From bbdea6f5a6334572a343e6c2c5837460e418b8bb Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Thu, 10 Mar 2022 13:33:54 +1100 Subject: [PATCH] fix mqtt none type error --- SunGather/exports/mqtt.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SunGather/exports/mqtt.py b/SunGather/exports/mqtt.py index ba3685f..0ca0747 100644 --- a/SunGather/exports/mqtt.py +++ b/SunGather/exports/mqtt.py @@ -68,8 +68,11 @@ class export_mqtt(object): return name.lower().replace(' ','_') def publish(self, inverter): - if not self.mqtt_client.is_connected(): - logging.warning(f'MQTT: Server Disconnected; {self.mqtt_queue.__len__()} messages queued, will automatically attempt to reconnect') + try: + if not self.mqtt_client.is_connected(): + logging.warning(f'MQTT: Server Disconnected; {self.mqtt_queue.__len__()} messages queued, will automatically attempt to reconnect') + except Exception as err: + logging.warning(f'MQTT: Server Error; Server not configured') # qos=0 is set, so no acknowledgment is sent, rending this check useless #elif self.mqtt_queue.__len__() > 10: # logging.warning(f'MQTT: {self.mqtt_queue.__len__()} messages queued, this may be due to a MQTT server issue')