Skip to content

Commit

Permalink
Prettify fan modes for ACs with min/max and without high/low
Browse files Browse the repository at this point in the history
Home Assistant has standard high/low fan modes that are localized and
displayed in the UI in a pretty way. Tasmota IRHVAC has min, low,
middle, high and max, along with a few other modes. Min and max are
displayed in Home Assistant as is and not localized. While nothing can
be done on the integration side for air conditioners that use 5 levels
of the fan, some air conditioners have 3 levels, but use min/medium/max
instead of low/medium/high. For such ACs, convert min->low and max->high
to display pretty localized values in the UI.
  • Loading branch information
gentoo-root committed Aug 11, 2024
1 parent b772248 commit 9e3ad34
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions custom_components/tasmota_irhvac/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ def __init__(
else:
new_fan_list.append(val)
self._attr_fan_modes = new_fan_list if len(new_fan_list) else None
self._quirk_fan_prettify = all(mode not in (self._attr_fan_modes or []) for mode in [FAN_LOW, FAN_HIGH])
if self._quirk_fan_prettify and self._attr_fan_modes:
self._attr_fan_modes = [self.fan_prettify(mode) for mode in self._attr_fan_modes]
self._attr_fan_mode = (
self._attr_fan_modes[0]
if isinstance(self._attr_fan_modes, list) and len(self._attr_fan_modes)
Expand All @@ -586,6 +589,24 @@ def __init__(
if self._attr_swing_mode is not None:
self._support_flags = self._support_flags | ClimateEntityFeature.SWING_MODE

def fan_prettify(self, mode):
if not self._quirk_fan_prettify:
return mode
if mode == HVAC_FAN_MIN:
return FAN_LOW
if mode == HVAC_FAN_MAX:
return FAN_HIGH
return mode

def fan_unprettify(self, mode):
if not self._quirk_fan_prettify:
return mode
if mode == FAN_LOW:
return HVAC_FAN_MIN
if mode == FAN_HIGH:
return HVAC_FAN_MAX
return mode

async def async_added_to_hass(self):
# Replacing `async_track_state_change` with `async_track_state_change_event`
# See, https://developers.home-assistant.io/blog/2024/04/13/deprecate_async_track_state_change/
Expand Down Expand Up @@ -799,9 +820,9 @@ async def state_message_received(message: mqtt.ReceiveMessage) -> None:
elif fan_mode == HVAC_FAN_AUTO:
self._attr_fan_mode = HVAC_FAN_MAX
else:
self._attr_fan_mode = fan_mode
self._attr_fan_mode = self.fan_prettify(fan_mode)
else:
self._attr_fan_mode = fan_mode
self._attr_fan_mode = self.fan_prettify(fan_mode)
_LOGGER.debug(self._attr_fan_mode)

if self._attr_hvac_mode is not HVACMode.OFF:
Expand Down Expand Up @@ -1180,7 +1201,7 @@ async def set_mode(self, hvac_mode):

async def send_ir(self):
"""Send the payload to tasmota mqtt topic."""
fan_speed = self._attr_fan_mode
fan_speed = self.fan_unprettify(self._attr_fan_mode)
# tweak for some ELECTRA_AC devices
if self._quirk_fan_max_high:
if fan_speed == FAN_HIGH:
Expand Down

0 comments on commit 9e3ad34

Please sign in to comment.