Revert only send message when state change occurs

This commit is contained in:
Tediore 2021-08-05 13:56:22 -05:00
parent 576a17922f
commit e614ba5d76

View File

@ -25,7 +25,6 @@ path = "/sys/class/power_supply/"
dirs = os.listdir(path)
payload = {}
last_payload = {}
health_calc = {}
time_remaining = {}
@ -79,14 +78,11 @@ while True:
except:
pass
if payload != last_payload:
try:
client.connect(MQTT_HOST)
client.publish("battery2mqtt/" + MQTT_TOPIC + '/' + dir, json.dumps(payload), qos=MQTT_QOS, retain=False)
last_payload = payload
except:
print('Message send failed.')
else:
pass
try:
client.connect(MQTT_HOST)
client.publish("battery2mqtt/" + MQTT_TOPIC + '/' + dir, json.dumps(payload), qos=MQTT_QOS, retain=False)
last_payload = payload
except:
print('Message send failed.')
sleep(INTERVAL)
sleep(INTERVAL)