From b35b19a0077605531c376ab17c6bdd167735bda9 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Mon, 5 Aug 2024 09:53:24 +0200 Subject: [PATCH] more error handling --- sdm630_mqtt.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sdm630_mqtt.py b/sdm630_mqtt.py index a3bd0ff..c8ff91c 100644 --- a/sdm630_mqtt.py +++ b/sdm630_mqtt.py @@ -104,12 +104,15 @@ class SDM630_MQTT: "voltage/average": 0x002A, }.items() ): - read = self.modbus.read_input_registers(address, 2) - longs = word_list_to_long(read) - if len(longs) == 1: - self._publish(readable, decode_ieee(longs[0])) - else: - self._publish(readable, sum([decode_ieee(x) for x in longs])) + try: + read = self.modbus.read_input_registers(address, 2) + longs = word_list_to_long(read) + if len(longs) == 1: + self._publish(readable, decode_ieee(longs[0])) + 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: self.modbus.close() self.modbus.open()