From 6fcece939ffd36c456b4cf0fb077ce588e6635c4 Mon Sep 17 00:00:00 2001 From: Tediore Date: Tue, 3 Aug 2021 14:59:36 -0500 Subject: [PATCH] Minor tweak --- battery2mqtt.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/battery2mqtt.py b/battery2mqtt.py index f074efa..f861d0e 100644 --- a/battery2mqtt.py +++ b/battery2mqtt.py @@ -53,6 +53,7 @@ while True: payload[name] = "condition not found" if BATTERY_HEALTH == '1': + unit = ' %' if SHOW_UNITS == '1' else '' try: for name in ['energy_full_design', 'energy_full']: with open(path + dir + '/' + name, 'r') as file: @@ -77,7 +78,10 @@ while True: except: pass - client.connect(MQTT_HOST) - client.publish("battery2mqtt/" + MQTT_TOPIC + '/' + dir, json.dumps(payload), qos=MQTT_QOS, retain=False) + try: + client.connect(MQTT_HOST) + client.publish("battery2mqtt/" + MQTT_TOPIC + '/' + dir, json.dumps(payload), qos=MQTT_QOS, retain=False) + except: + print('Message send failure.') sleep(INTERVAL)