Toggle device in case of timeout
This commit is contained in:
22
plugin.py
22
plugin.py
@@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
#pylint: disable=line-too-long,broad-exception-caught,possibly-used-before-assignment
|
#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>
|
<description>
|
||||||
<h2>Heatzy Pilote</h2><br/>
|
<h2>Heatzy Pilote</h2><br/>
|
||||||
Implementation of Heatzy Pilote as a Domoticz Plugin.<br/>
|
Implementation of Heatzy Pilote as a Domoticz Plugin.<br/>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
<option label="Yes" value="1"/>
|
<option label="Yes" value="1"/>
|
||||||
</options>
|
</options>
|
||||||
</param>
|
</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">
|
<param field="Mode6" label="Logging Level" width="200px">
|
||||||
<options>
|
<options>
|
||||||
<option label="Normal" value="0" default="true"/>
|
<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
|
def on_command(self, DeviceID, Unit, Command, Level, Color): #pylint: disable=unused-argument,invalid-name
|
||||||
"""Send a command"""
|
"""Send a command"""
|
||||||
if Unit == HeatzyUnit.CONTROL:
|
if Unit == HeatzyUnit.CONTROL:
|
||||||
self.on_off(DeviceID, Command)
|
self.send_command(DeviceID, Command)
|
||||||
elif Unit == HeatzyUnit.SELECTOR:
|
elif Unit == HeatzyUnit.SELECTOR:
|
||||||
self.set_mode(DeviceID, Level)
|
self.set_mode(DeviceID, Level)
|
||||||
|
|
||||||
@@ -315,6 +315,10 @@ class BasePlugin:
|
|||||||
obsolete_min = int((time.time() - response["updated_at"])//60)
|
obsolete_min = int((time.time() - response["updated_at"])//60)
|
||||||
Domoticz.Error(f"Last update from '{alias}' was {obsolete_min} min earlier.")
|
Domoticz.Error(f"Last update from '{alias}' was {obsolete_min} min earlier.")
|
||||||
Devices[deviceid].TimedOut = 1
|
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
|
continue
|
||||||
device["updated_at"] = response["updated_at"]
|
device["updated_at"] = response["updated_at"]
|
||||||
|
|
||||||
@@ -441,8 +445,8 @@ class BasePlugin:
|
|||||||
#Device is correctly running ==> we reset the retry counter
|
#Device is correctly running ==> we reset the retry counter
|
||||||
self.reset_retry()
|
self.reset_retry()
|
||||||
|
|
||||||
def on_off(self, deviceid, command):
|
def send_command(self, deviceid, command):
|
||||||
"""Toggle device on/off"""
|
"""Send command to device, only when it is not already in the requested state"""
|
||||||
if Devices[deviceid].Units[HeatzyUnit.CONTROL].sValue != command:
|
if Devices[deviceid].Units[HeatzyUnit.CONTROL].sValue != command:
|
||||||
if command == "On":
|
if command == "On":
|
||||||
self.set_mode(deviceid, HEATZY_MODE_VALUE['NORMAL'])
|
self.set_mode(deviceid, HEATZY_MODE_VALUE['NORMAL'])
|
||||||
@@ -453,6 +457,14 @@ class BasePlugin:
|
|||||||
#Because of issue with the equipment (Off do not work...)
|
#Because of issue with the equipment (Off do not work...)
|
||||||
self.set_mode(deviceid, HEATZY_MODE_VALUE['FROSTFREE'])
|
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):
|
def reset_retry(self):
|
||||||
"""Reset the retry counter"""
|
"""Reset the retry counter"""
|
||||||
if self.retry != self._MAX_RETRY_PER_DEVICE * len(self.did):
|
if self.retry != self._MAX_RETRY_PER_DEVICE * len(self.did):
|
||||||
|
|||||||
Reference in New Issue
Block a user