forked from sthope/battery2mqtt
Revert only send message when state change occurs
This commit is contained in:
parent
576a17922f
commit
e614ba5d76
@ -25,7 +25,6 @@ path = "/sys/class/power_supply/"
|
|||||||
dirs = os.listdir(path)
|
dirs = os.listdir(path)
|
||||||
|
|
||||||
payload = {}
|
payload = {}
|
||||||
last_payload = {}
|
|
||||||
health_calc = {}
|
health_calc = {}
|
||||||
time_remaining = {}
|
time_remaining = {}
|
||||||
|
|
||||||
@ -79,14 +78,11 @@ while True:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if payload != last_payload:
|
try:
|
||||||
try:
|
client.connect(MQTT_HOST)
|
||||||
client.connect(MQTT_HOST)
|
client.publish("battery2mqtt/" + MQTT_TOPIC + '/' + dir, json.dumps(payload), qos=MQTT_QOS, retain=False)
|
||||||
client.publish("battery2mqtt/" + MQTT_TOPIC + '/' + dir, json.dumps(payload), qos=MQTT_QOS, retain=False)
|
last_payload = payload
|
||||||
last_payload = payload
|
except:
|
||||||
except:
|
print('Message send failed.')
|
||||||
print('Message send failed.')
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
sleep(INTERVAL)
|
sleep(INTERVAL)
|
Loading…
x
Reference in New Issue
Block a user