Skip to content

Commit

Permalink
Properly handle t_power vs t_work_mode merge in HA.
Browse files Browse the repository at this point in the history
  • Loading branch information
deiger committed Jan 8, 2021
1 parent bb0fa93 commit ef0ca94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
45 changes: 30 additions & 15 deletions aircon/aircon.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ def queue_command(self, name: str, value) -> None:
raise Error('Cannot update read-only property "{}".'.format(name))
data_type = self._properties.get_type(name)

# HomeAssistant doesn't have a designated turn on button in climate.mqtt.
# Furthermore, turn_on doesn't send the right command...
# Mitigate that by making setting t_work_mode also set t_power.
if name == 't_work_mode' and value != 'OFF':
self.queue_command('t_power', 'ON')

# Device mode is set using t_control_value
if issubclass(data_type, enum.Enum):
data_value = data_type[value]
Expand All @@ -137,13 +131,6 @@ def queue_command(self, name: str, value) -> None:
property_updater = lambda: self.update_property(name, typed_value)
self.commands_queue.put_nowait((command, property_updater))

# Handle turning on FastColdHeat
if name == 't_temp_heatcold' and typed_value is FastColdHeat.ON:
self.queue_command('t_fan_speed', 'AUTO')
self.queue_command('t_fan_mute', 'OFF')
self.queue_command('t_sleep', 'STOP')
self.queue_command('t_temp_eight', 'OFF')

self._queue_listener()

def _build_command(self, name: str, data_value: int):
Expand Down Expand Up @@ -203,6 +190,36 @@ def available(self, value: bool):
self._available = value
self._notify_listeners("available", value)

# @override to add special support for t_power.
def update_property(self, name: str, value) -> None:
super().update_property(name, value)
# HomeAssistant doesn't listen to changes in t_power, so notify also on a t_work_mode change.
if name == 't_power':
work_mode = AcWorkMode.OFF if value == Power.OFF else self.get_work_mode()
self._notify_listeners('t_work_mode', work_mode)

# @override to add special support for t_power.
def queue_command(self, name: str, value) -> None:
# HomeAssistant doesn't have a designated turn on button in climate.mqtt.
# Furthermore, turn_on doesn't send the right command...
if name == 't_work_mode':
if value == 'OFF':
# Pass the command to t_power instead of t_work_mode.
name = 't_power'
else:
# Also turn on the AC (if it hasn't already).
super().queue_command('t_power', 'ON')

# Run base.
super().queue_command(name, value)

# Handle turning on FastColdHeat
if name == 't_temp_heatcold' and value is 'ON':
super().queue_command('t_fan_speed', 'AUTO')
super().queue_command('t_fan_mute', 'OFF')
super().queue_command('t_sleep', 'STOP')
super().queue_command('t_temp_eight', 'OFF')

def get_env_temp(self) -> int:
return self.get_property('f_temp_in')

Expand Down Expand Up @@ -246,8 +263,6 @@ def set_work_mode(self, setting: AcWorkMode) -> None:
control = control_value.set_work_mode(control, setting)
self.queue_command('t_control_value', control)
else:
if self.get_property("t_power"):
self.queue_command("t_power", Power.ON)
self.queue_command('t_work_mode', setting)

def get_work_mode(self) -> AcWorkMode:
Expand Down
3 changes: 0 additions & 3 deletions aircon/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def mqtt_on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessa
if prop_name == 't_work_mode':
if payload == 'fan_only':
payload = 'FAN'
elif payload == 'off':
prop_name = 't_power'
payload = 'OFF'

for device in self._devices:
if device.mac_address != mac_address:
Expand Down

0 comments on commit ef0ca94

Please sign in to comment.