From 3c59047d10bab37222db29259a5815d2d82ca79b Mon Sep 17 00:00:00 2001 From: bindismal <24500053+bindismal@users.noreply.github.com> Date: Sat, 16 Jun 2018 21:34:33 +1000 Subject: [PATCH 1/2] Added support for zone control for ducted HVAC that support zone control Added support for reading / setting fan speed --- example.py | 8 ++++++-- wideq.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/example.py b/example.py index cc26b93..2e3df40 100644 --- a/example.py +++ b/example.py @@ -87,7 +87,8 @@ def ac_mon(client, device_id): '{1}; ' '{0.mode.name}; ' 'cur {0.temp_cur_f}°F; ' - 'cfg {0.temp_cfg_f}°F' + 'cfg {0.temp_cfg_f}°F; ' + 'fan speed {0.fan_speed.name}' .format( state, 'on' if state.is_on else 'off' @@ -121,7 +122,10 @@ def ac_config(client, device_id): print(ac.get_energy_target()) print(ac.get_volume()) print(ac.get_light()) - + zones = ac.get_zones() + print(zones) + ac.set_fan_speed(wideq.ACFanSpeed('@AC_MAIN_WIND_STRENGTH_LOW_W')) + ac.set_zones(zones) EXAMPLE_COMMANDS = { 'ls': ls, diff --git a/wideq.py b/wideq.py index 2d29c92..98cf868 100644 --- a/wideq.py +++ b/wideq.py @@ -746,6 +746,18 @@ class ACMode(enum.Enum): AROMA = "@AC_MAIN_OPERATION_MODE_AROMA_W" ENERGY_SAVING = "@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W" +class ACFanSpeed(enum.Enum): + """The fan speed for an AC/HVAC device.""" + + SLOW_W = '@AC_MAIN_WIND_STRENGTH_SLOW_W' + SLOW_LOW_W = '@AC_MAIN_WIND_STRENGTH_SLOW_LOW_W' + LOW_W = '@AC_MAIN_WIND_STRENGTH_LOW_W' + LOW_MID_W = '@AC_MAIN_WIND_STRENGTH_LOW_MID_W' + MID_W = '@AC_MAIN_WIND_STRENGTH_MID_W' + MID_HIGH_W = '@AC_MAIN_WIND_STRENGTH_MID_HIGH_W' + HIGH_W = '@AC_MAIN_WIND_STRENGTH_HIGH_W' + POWER_W = '@AC_MAIN_WIND_STRENGTH_POWER_W' + AUTO_W = '@AC_MAIN_WIND_STRENGTH_AUTO_W' class ACOp(enum.Enum): """Whether a device is on or off.""" @@ -806,6 +818,31 @@ class ACDevice(Device): self.set_celsius(self.f2c[f]) + def set_zones(self, zones): + """Set the device's zones to on/off. + zones arg is a list of the format below + zone_no is a number indexed from 1 typed as string + enabled is a bool typed as string + isOpen is a bool typed as string + [{'No':zone_no, 'Cfg':enabled, 'State':isOpen},] + """ + #ensure at least 1 zone is enabled. Can't turn all zones off + on_count = sum(int(zone['State']) for zone in zones) + if(on_count > 0): + zone_cmd = '/'.join(zone['No']+'_'+zone['State'] for zone in zones if zone['Cfg'] == '1') + self._set_control('DuctZone', zone_cmd) + + def get_zones(self): + """Gets the status of the zones, including whether a zone is configured. + Result is a list of dicts with the same format as set_zones() + """ + return self._get_config('DuctZone') + + def set_fan_speed(self, speed): + """Sets the fan speed according to the WindStreng operation""" + speed_value = self.model.enum_value('WindStrength', speed.value) + self._set_control('WindStrength', speed_value) + def set_mode(self, mode): """Set the device's operating mode to an `OpMode` value. """ @@ -921,6 +958,10 @@ class ACStatus(object): def mode(self): return ACMode(self.lookup_enum('OpMode')) + @property + def fan_speed(self): + return ACFanSpeed(self.lookup_enum('WindStrength')) + @property def is_on(self): op = ACOp(self.lookup_enum('Operation')) From add21143d2b0b14f0ae75470f3115b9cd2d36f02 Mon Sep 17 00:00:00 2001 From: bindismal <24500053+bindismal@users.noreply.github.com> Date: Sun, 17 Jun 2018 23:50:33 +1000 Subject: [PATCH 2/2] Accepted proposed changes --- example.py | 5 +---- wideq.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/example.py b/example.py index 2e3df40..78ad5bb 100644 --- a/example.py +++ b/example.py @@ -122,10 +122,7 @@ def ac_config(client, device_id): print(ac.get_energy_target()) print(ac.get_volume()) print(ac.get_light()) - zones = ac.get_zones() - print(zones) - ac.set_fan_speed(wideq.ACFanSpeed('@AC_MAIN_WIND_STRENGTH_LOW_W')) - ac.set_zones(zones) + print(ac.get_zones()) EXAMPLE_COMMANDS = { 'ls': ls, diff --git a/wideq.py b/wideq.py index 98cf868..9711e48 100644 --- a/wideq.py +++ b/wideq.py @@ -749,15 +749,15 @@ class ACMode(enum.Enum): class ACFanSpeed(enum.Enum): """The fan speed for an AC/HVAC device.""" - SLOW_W = '@AC_MAIN_WIND_STRENGTH_SLOW_W' - SLOW_LOW_W = '@AC_MAIN_WIND_STRENGTH_SLOW_LOW_W' - LOW_W = '@AC_MAIN_WIND_STRENGTH_LOW_W' - LOW_MID_W = '@AC_MAIN_WIND_STRENGTH_LOW_MID_W' - MID_W = '@AC_MAIN_WIND_STRENGTH_MID_W' - MID_HIGH_W = '@AC_MAIN_WIND_STRENGTH_MID_HIGH_W' - HIGH_W = '@AC_MAIN_WIND_STRENGTH_HIGH_W' - POWER_W = '@AC_MAIN_WIND_STRENGTH_POWER_W' - AUTO_W = '@AC_MAIN_WIND_STRENGTH_AUTO_W' + SLOW = '@AC_MAIN_WIND_STRENGTH_SLOW_W' + SLOW_LOW = '@AC_MAIN_WIND_STRENGTH_SLOW_LOW_W' + LOW = '@AC_MAIN_WIND_STRENGTH_LOW_W' + LOW_MID = '@AC_MAIN_WIND_STRENGTH_LOW_MID_W' + MID = '@AC_MAIN_WIND_STRENGTH_MID_W' + MID_HIGH = '@AC_MAIN_WIND_STRENGTH_MID_HIGH_W' + HIGH = '@AC_MAIN_WIND_STRENGTH_HIGH_W' + POWER = '@AC_MAIN_WIND_STRENGTH_POWER_W' + AUTO = '@AC_MAIN_WIND_STRENGTH_AUTO_W' class ACOp(enum.Enum): """Whether a device is on or off.""" @@ -822,14 +822,17 @@ class ACDevice(Device): """Set the device's zones to on/off. zones arg is a list of the format below zone_no is a number indexed from 1 typed as string - enabled is a bool typed as string - isOpen is a bool typed as string + enabled is a 1/0 typed as string + isOpen is a 1/0 typed as string [{'No':zone_no, 'Cfg':enabled, 'State':isOpen},] """ #ensure at least 1 zone is enabled. Can't turn all zones off on_count = sum(int(zone['State']) for zone in zones) - if(on_count > 0): - zone_cmd = '/'.join(zone['No']+'_'+zone['State'] for zone in zones if zone['Cfg'] == '1') + if on_count > 0: + zone_cmd = '/'.join( + '{}_{}'.format(zone['No'], zone['State']) + for zone in zones if zone['Cfg'] == '1' + ) self._set_control('DuctZone', zone_cmd) def get_zones(self): @@ -839,7 +842,9 @@ class ACDevice(Device): return self._get_config('DuctZone') def set_fan_speed(self, speed): - """Sets the fan speed according to the WindStreng operation""" + """Sets the fan speed according to the WindStrength operation + Speed arg is a value of the ACFanSpeed enum + """ speed_value = self.model.enum_value('WindStrength', speed.value) self._set_control('WindStrength', speed_value)