Switch to TimedOut only when update_at < command_at
This commit is contained in:
11
plugin.py
11
plugin.py
@@ -174,7 +174,6 @@ class BasePlugin:
|
||||
|
||||
self.pooling_current_step = 1
|
||||
else:
|
||||
# Devices["9420ae048da545c88fc6274d204dd25f"].Refresh()
|
||||
self.pooling_current_step = self.pooling_current_step + 1
|
||||
|
||||
def get_token(self, user, password):
|
||||
@@ -263,7 +262,7 @@ class BasePlugin:
|
||||
product_key = device['product_key']
|
||||
alias = device['dev_alias']
|
||||
did = device['did']
|
||||
self.did[product_key] = {"did":did, "alias":alias, "updated_at":0}
|
||||
self.did[product_key] = {"did":did, "alias":alias, "updated_at":0, "command_at":0}
|
||||
Domoticz.Status(f"Devide Id from Heatzy API: {alias} - {did}")
|
||||
unit = unit + 1
|
||||
|
||||
@@ -310,11 +309,12 @@ class BasePlugin:
|
||||
|
||||
#Last Update
|
||||
if 'updated_at' in response:
|
||||
obsolete_min = int((time.time() - response["updated_at"])//60)
|
||||
if response["updated_at"] == device["updated_at"]:
|
||||
#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.")
|
||||
if device["command_at"] - 60 > device["updated_at"] and Devices[deviceid].TimedOut == 0:
|
||||
#No update while a command has been sent
|
||||
obsolete_min = int((time.time() - response["updated_at"])//60)
|
||||
Domoticz.Error(f"Last update from '{alias}' was {obsolete_min} min earlier.")
|
||||
Devices[deviceid].TimedOut = 1
|
||||
continue
|
||||
device["updated_at"] = response["updated_at"]
|
||||
@@ -394,6 +394,7 @@ class BasePlugin:
|
||||
#Should not occur... but it occurs sometimes
|
||||
self.did = self.get_heatzy_devices()
|
||||
did = self.did[deviceid]["did"]
|
||||
self.did[deviceid]["command_at"] = time.time()
|
||||
url = f"https://euapi.gizwits.com/app/control/{did}"
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=data, timeout=self._HTTP_TIMEOUT).json()
|
||||
|
||||
Reference in New Issue
Block a user