Better management of obsolete device
This commit is contained in:
13
plugin.py
13
plugin.py
@@ -257,7 +257,7 @@ class BasePlugin:
|
|||||||
product_key = device['product_key']
|
product_key = device['product_key']
|
||||||
alias = device['dev_alias']
|
alias = device['dev_alias']
|
||||||
did = device['did']
|
did = device['did']
|
||||||
self.did[product_key] = {"did":did, "alias":alias}
|
self.did[product_key] = {"did":did, "alias":alias, "updated_at":0}
|
||||||
Domoticz.Status(f"Devide Id from Heatzy API: {alias} - {did}")
|
Domoticz.Status(f"Devide Id from Heatzy API: {alias} - {did}")
|
||||||
unit = unit + 1
|
unit = unit + 1
|
||||||
|
|
||||||
@@ -298,19 +298,22 @@ class BasePlugin:
|
|||||||
#Domoticz.Error("Headers: " + str(headers))
|
#Domoticz.Error("Headers: " + str(headers))
|
||||||
if 'response' in locals() and response != "":
|
if 'response' in locals() and response != "":
|
||||||
Domoticz.Error("Response: " + str(response))
|
Domoticz.Error("Response: " + str(response))
|
||||||
return ""
|
return
|
||||||
|
|
||||||
Domoticz.Debug("Get Mode Response:" + str(response))
|
Domoticz.Debug("Get Mode Response:" + str(response))
|
||||||
|
|
||||||
#Last Update
|
#Last Update
|
||||||
if 'updated_at' in response:
|
if 'updated_at' in response:
|
||||||
obsolete_min = int((time.time() - response["updated_at"])//60)
|
obsolete_min = int((time.time() - response["updated_at"])//60)
|
||||||
if obsolete_min >= 180:
|
if response["updated_at"] == device["updated_at"]:
|
||||||
if Devices[deviceid].TimedOut == 0:
|
#No update since last heartbeat
|
||||||
|
if obsolete_min >= 180 and Devices[deviceid].TimedOut == 0:
|
||||||
Domoticz.Status(f"Last update from '{alias}' was {obsolete_min} min earlier.")
|
Domoticz.Status(f"Last update from '{alias}' was {obsolete_min} min earlier.")
|
||||||
Devices[deviceid].TimedOut = 1
|
Devices[deviceid].TimedOut = 1
|
||||||
return
|
return
|
||||||
elif Devices[deviceid].TimedOut == 1:
|
device["updated_at"] = response["updated_at"]
|
||||||
|
|
||||||
|
if Devices[deviceid].TimedOut == 1:
|
||||||
Domoticz.Status(f"'{alias}' is now back.")
|
Domoticz.Status(f"'{alias}' is now back.")
|
||||||
Devices[deviceid].TimedOut = 0
|
Devices[deviceid].TimedOut = 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user