Added try/catch to test if the thread is not killed by exception
This commit is contained in:
parent
c78818bc5c
commit
0b136075de
13
src/main.py
13
src/main.py
|
|
@ -4,7 +4,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import paho.mqtt.client
|
import paho.mqtt.client
|
||||||
from huawei_solar import AsyncHuaweiSolar
|
from huawei_solar import AsyncHuaweiSolar, ReadException
|
||||||
from huawei_solar import register_values as rv
|
from huawei_solar import register_values as rv
|
||||||
|
|
||||||
from src.data import InverterData, ReadRegister
|
from src.data import InverterData, ReadRegister
|
||||||
|
|
@ -37,9 +37,14 @@ async def main():
|
||||||
inverter_client = await get_inverter_client()
|
inverter_client = await get_inverter_client()
|
||||||
count = 0
|
count = 0
|
||||||
while True:
|
while True:
|
||||||
status = await inverter_client.get(
|
try:
|
||||||
ReadRegister.inverter_reg_status, slave_id
|
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}")
|
LOGGER.info(f"-- INVERTER -- Status: {status}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue