From 0b136075dee1910313b6ba33ed9cbdb345cb886b Mon Sep 17 00:00:00 2001 From: Simon Milvert Date: Wed, 8 Mar 2023 14:13:00 +0100 Subject: [PATCH] Added try/catch to test if the thread is not killed by exception --- src/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.py b/src/main.py index 98ead8c..89a5cce 100644 --- a/src/main.py +++ b/src/main.py @@ -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}")