Toggle device in case of timeout

This commit is contained in:
2025-11-23 21:49:56 +01:00
parent ad3cfbe74d
commit f752b45ee1

View File

@@ -4,7 +4,7 @@
#
#pylint: disable=line-too-long,broad-exception-caught,possibly-used-before-assignment
"""
<plugin key="HeatzyEx" name="Heatzy Pilote Ex" author="fjumelle" version="2.2.2" wikilink="" externallink="">
<plugin key="HeatzyEx" name="Heatzy Pilote Ex" author="fjumelle" version="2.3.0" wikilink="" externallink="">
<description>
<h2>Heatzy Pilote</h2><br/>
Implementation of Heatzy Pilote as a Domoticz Plugin.<br/>
@@ -18,7 +18,7 @@
<option label="Yes" value="1"/>
</options>
</param>
<param field="Mode5" label="Polling interval (s)" width="40px" required="true" default="60"/>
<param field="Mode5" label="Polling interval (s)" width="40px" required="true" default="120"/>
<param field="Mode6" label="Logging Level" width="200px">
<options>
<option label="Normal" value="0" default="true"/>
@@ -152,7 +152,7 @@ class BasePlugin:
def on_command(self, DeviceID, Unit, Command, Level, Color): #pylint: disable=unused-argument,invalid-name
"""Send a command"""
if Unit == HeatzyUnit.CONTROL:
self.on_off(DeviceID, Command)
self.send_command(DeviceID, Command)
elif Unit == HeatzyUnit.SELECTOR:
self.set_mode(DeviceID, Level)
@@ -315,6 +315,10 @@ class BasePlugin:
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
#Toggle device to be sure it is not stucked
Domoticz.Error(f"Then I toggle the device '{alias}'.")
self.toggle(deviceid)
continue
device["updated_at"] = response["updated_at"]
@@ -441,8 +445,8 @@ class BasePlugin:
#Device is correctly running ==> we reset the retry counter
self.reset_retry()
def on_off(self, deviceid, command):
"""Toggle device on/off"""
def send_command(self, deviceid, command):
"""Send command to device, only when it is not already in the requested state"""
if Devices[deviceid].Units[HeatzyUnit.CONTROL].sValue != command:
if command == "On":
self.set_mode(deviceid, HEATZY_MODE_VALUE['NORMAL'])
@@ -453,6 +457,14 @@ class BasePlugin:
#Because of issue with the equipment (Off do not work...)
self.set_mode(deviceid, HEATZY_MODE_VALUE['FROSTFREE'])
def toggle(self, deviceid):
"""Toggle device"""
new_command1 = "Off" if Devices[deviceid].Units[HeatzyUnit.CONTROL].sValue == "On" else "On"
new_command2 = "On" if Devices[deviceid].Units[HeatzyUnit.CONTROL].sValue == "On" else "Off"
self.send_command(deviceid, new_command1)
time.sleep(5) #slepp 5 seconds
self.send_command(deviceid, new_command2)
def reset_retry(self):
"""Reset the retry counter"""
if self.retry != self._MAX_RETRY_PER_DEVICE * len(self.did):