From c87e6b634c09646442b0b2c90fe3e38865684b8d Mon Sep 17 00:00:00 2001 From: janjaapko Date: Thu, 7 May 2020 15:03:25 +0200 Subject: [PATCH] make Air Qual Target enumerated multi switch --- commands.py | 8 ++++++-- plugin.py | 17 ++++++++++------- value_types.py | 27 ++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/commands.py b/commands.py index da2cb0e..41e5ce5 100644 --- a/commands.py +++ b/commands.py @@ -87,6 +87,10 @@ def set_fan_mode_auto(self, mode): return(self.device_command, command); def set_quality_target(self, mode): - """Changes auto mode: 0001..0004""" - command = self._create_command({'qtar': mode}) + """Changes quality target: 0001..0004""" + if mode == 10 : level = 4 + if mode == 20 : level = 3 + if mode == 30 : level = 1 + arg="000"+str(level) + command = self._create_command({'qtar': arg}) return(self.device_command, command); diff --git a/plugin.py b/plugin.py index ee4f6bb..668dc92 100644 --- a/plugin.py +++ b/plugin.py @@ -3,7 +3,7 @@ # Author: Jan-Jaap Kostelijk # """ - +

Dyson Pure Link plugin


Connects to Dyson Pure Link devices
@@ -161,7 +161,11 @@ def onStart(self): if self.particlesUnit not in Devices: Domoticz.Device(Name='Dust', Unit=self.particlesUnit, TypeName="Air Quality").Create() if self.qualityTargetUnit not in Devices: - Domoticz.Device(Name='Air quality setpoint', Unit=self.qualityTargetUnit, TypeName="Custom").Create() + Options = {"LevelActions" : "||", + "LevelNames" : "|Normal|Sensitive (Medium)|Very Sensitive (High)", + "LevelOffHidden" : "true", + "SelectorStyle" : "1"} + Domoticz.Device(Name='Air quality setpoint', Unit=self.qualityTargetUnit, TypeName="Selector Switch", Image=7, Options=Options).Create() if self.particles2_5Unit not in Devices: Domoticz.Device(Name='Dust (PM 2,5)', Unit=self.particles2_5Unit, TypeName="Air Quality").Create() @@ -229,8 +233,7 @@ def onCommand(self, Unit, Command, Level, Hue): payload = '' if Unit == self.qualityTargetUnit and Level<=100: - arg="0000"+str(Level//10) - topic, payload = self.myDevice.set_quality_target(arg[-4:]) #use last 4 characters as quality target + topic, payload = self.myDevice.set_quality_target(Level) if Unit == self.fanSpeedUnit and Level<=100: arg="0000"+str(Level//10) topic, payload = self.myDevice.set_fan_speed(arg[-4:]) #use last 4 characters as speed level or AUTO @@ -279,8 +282,8 @@ def onHeartbeat(self): else: Domoticz.Debug("Polling unit in " + str(self.runCounter) + " heartbeats.") - def onDeviceRemoved(self): - Domoticz.Log("DysonPureLink plugin: onDeviceRemoved called") + def onDeviceRemoved(self, unit): + Domoticz.Log("DysonPureLink plugin: onDeviceRemoved called for unit '" + str(unit) + "'") def updateDevices(self): """Update the defined devices from incoming mesage info""" @@ -299,7 +302,7 @@ def updateDevices(self): UpdateDevice(self.fanModeUnit, self.state_data.fan_mode.state, str((self.state_data.fan_mode.state+1)*10)) UpdateDevice(self.fanStateUnit, self.state_data.fan_state.state, str((self.state_data.fan_state.state+1)*10)) UpdateDevice(self.filterLifeUnit, self.state_data.filter_life, str(self.state_data.filter_life)) - UpdateDevice(self.qualityTargetUnit, self.state_data.quality_target, str(self.state_data.quality_target)) + UpdateDevice(self.qualityTargetUnit, self.state_data.quality_target.state, str((self.state_data.quality_target.state+1)*10)) UpdateDevice(self.standbyMonitoringUnit, self.state_data.standby_monitoring.state, str((self.state_data.standby_monitoring.state+1)*10)) if self.state_data.fan_mode_auto is not None: UpdateDevice(self.fanModeAutoUnit, self.state_data.fan_mode_auto.state, str((self.state_data.fan_mode_auto.state+1)*10)) diff --git a/value_types.py b/value_types.py index 17ee74a..fe5e8ab 100644 --- a/value_types.py +++ b/value_types.py @@ -39,6 +39,31 @@ def state(self): if self._state == self.OFF: return 0 if self._state == self.ON: return 1 if self._state == self.AUTO: return 2 + +class QualityTarget(): + """Enum for air quality target""" + HIGH = 'HIGH' + MEDIUM = 'MEDIUM' + NORMAL = 'NORMAL' + UNKNOWN = 'UNKNOWN' + _state = None + + def __init__(self, state): + """go from string to state object""" + if state.upper() == '0001': self._state = self.HIGH + if state.upper() == '0002': self._state = self.UNKNOWN + if state.upper() == '0003': self._state = self.MEDIUM + if state.upper() == '0004': self._state = self.NORMAL + + def __repr__(self): + return self._state + + @property + def state(self): + if self._state == self.NORMAL: return 0 + if self._state == self.MEDIUM: return 1 + if self._state == self.HIGH: return 2 + if self._state == self.UNKNOWN: return 3 class StandbyMonitoring(object): """Enum for monitor air quality when on standby""" @@ -146,7 +171,7 @@ def __init__(self, message): if 'filf' in data: self.filter_life = int(self._get_field_value(data['filf'])) #0000 - 4300 if 'qtar' in data: - self.quality_target = int(self._get_field_value(data['qtar'])) #0001 , 0003... + self.quality_target = QualityTarget(self._get_field_value(data['qtar'])) #0001 (high), 0003 (medium) , 0004 (normal) self.standby_monitoring = FanMode(self._get_field_value(data['rhtm'])) # ON, OFF self.error_code = self._get_field_value(data['ercd']) #I think this is an errorcode: NONE when filter needs replacement self.warning_code = self._get_field_value(data['wacd']) #I think this is Warning: FLTR when filter needs replacement