Skip to content

Commit

Permalink
make Air Qual Target enumerated multi switch
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJaapKo committed May 7, 2020
1 parent d4c36a5 commit c87e6b6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
8 changes: 6 additions & 2 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
17 changes: 10 additions & 7 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author: Jan-Jaap Kostelijk
#
"""
<plugin key="DysonPureLink" name="Dyson Pure Link" author="Jan-Jaap Kostelijk" version="2.1.1" wikilink="https://github.com/JanJaapKo/DysonPureLink.wiki.git" externallink="https://github.com/JanJaapKo/DysonPureLink">
<plugin key="DysonPureLink" name="Dyson Pure Link" author="Jan-Jaap Kostelijk" version="2.1.2" wikilink="https://github.com/JanJaapKo/DysonPureLink.wiki.git" externallink="https://github.com/JanJaapKo/DysonPureLink">
<description>
<h2>Dyson Pure Link plugin</h2><br/>
Connects to Dyson Pure Link devices<br/>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand All @@ -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))
Expand Down
27 changes: 26 additions & 1 deletion value_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c87e6b6

Please sign in to comment.