Added try/catch to test if the thread is not killed by exception

This commit is contained in:
Simon 2023-03-08 14:13:00 +01:00
parent c78818bc5c
commit 0b136075de
1 changed files with 9 additions and 4 deletions

View File

@ -4,7 +4,7 @@ import logging
import os
import paho.mqtt.client
from huawei_solar import AsyncHuaweiSolar
from huawei_solar import AsyncHuaweiSolar, ReadException
from huawei_solar import register_values as rv
from src.data import InverterData, ReadRegister
@ -37,9 +37,14 @@ async def main():
inverter_client = await get_inverter_client()
count = 0
while True:
status = await inverter_client.get(
ReadRegister.inverter_reg_status, slave_id
)
try:
status = await inverter_client.get(
ReadRegister.inverter_reg_status, slave_id
)
except ReadException as error:
LOGGER.error(f"Can't read register, {ReadRegister.inverter_reg_status}. "
f"Error code: {error}. Sleep for 10 min")
await asyncio.sleep(10*60)
LOGGER.info(f"-- INVERTER -- Status: {status}")