added try catch clause

This commit is contained in:
Angoosh Leviocki 2025-01-18 00:43:47 +01:00
parent 4d401ecadd
commit 1d98bbe227
Signed by: angoosh
GPG Key ID: 2DAE446D291BD8D3

View File

@ -40,10 +40,13 @@ def subscribe(client: mqtt_client):
def on_message(client, userdata, msg): def on_message(client, userdata, msg):
topic = msg.topic topic = msg.topic
if "tele" in topic: if "tele" in topic:
if "STATE" in topic: try:
data = json.loads(msg.payload.decode()) if "STATE" in topic:
device = topic.split('/')[1] data = json.loads(msg.payload.decode())
powerState[device] = data['POWER'] device = topic.split('/')[1]
powerState[device] = data['POWER']
except:
pass
if "stat" in topic: if "stat" in topic:
device = topic.split('/')[1] device = topic.split('/')[1]
powerState[device] = msg.payload.decode() powerState[device] = msg.payload.decode()
@ -84,4 +87,4 @@ if __name__ == "__main__":
while True: while True:
checkPC() checkPC()
sleep(1) sleep(1)