more error handling

This commit is contained in:
Franzi 2024-08-05 09:53:24 +02:00
parent 734f4cf4e9
commit b35b19a007
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -104,12 +104,15 @@ class SDM630_MQTT:
"voltage/average": 0x002A, "voltage/average": 0x002A,
}.items() }.items()
): ):
read = self.modbus.read_input_registers(address, 2) try:
longs = word_list_to_long(read) read = self.modbus.read_input_registers(address, 2)
if len(longs) == 1: longs = word_list_to_long(read)
self._publish(readable, decode_ieee(longs[0])) if len(longs) == 1:
else: self._publish(readable, decode_ieee(longs[0]))
self._publish(readable, sum([decode_ieee(x) for x in longs])) else:
self._publish(readable, sum([decode_ieee(x) for x in longs]))
except Exception:
LOG.exception(f'error while reading {readable} from meter')
if idx % 20: if idx % 20:
self.modbus.close() self.modbus.close()
self.modbus.open() self.modbus.open()