From 4602c0a1c32339235508d82f4dd90a536a03ae3f Mon Sep 17 00:00:00 2001 From: hydazz <53986978+hydazz@users.noreply.github.com> Date: Mon, 3 Mar 2025 07:59:44 +1100 Subject: [PATCH] Add Night mode and `HVACAction` to Advantage Air (#137475) * add night mode toggle * populate AC's action * set hvac action on zones * update tests * show zones as off if AC is off --------- Co-authored-by: Franck Nijhof --- .../components/advantage_air/climate.py | 37 +++++++++++++++++++ .../components/advantage_air/const.py | 1 + .../components/advantage_air/switch.py | 29 +++++++++++++++ .../advantage_air/snapshots/test_climate.ambr | 1 + 4 files changed, 68 insertions(+) diff --git a/homeassistant/components/advantage_air/climate.py b/homeassistant/components/advantage_air/climate.py index c023d4cf8f3..1d593c5c3c8 100644 --- a/homeassistant/components/advantage_air/climate.py +++ b/homeassistant/components/advantage_air/climate.py @@ -2,6 +2,7 @@ from __future__ import annotations +from decimal import Decimal import logging from typing import Any @@ -14,6 +15,7 @@ from homeassistant.components.climate import ( FAN_MEDIUM, ClimateEntity, ClimateEntityFeature, + HVACAction, HVACMode, ) from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, UnitOfTemperature @@ -49,6 +51,14 @@ ADVANTAGE_AIR_MYTEMP_ENABLED = "climateControlModeEnabled" ADVANTAGE_AIR_HEAT_TARGET = "myAutoHeatTargetTemp" ADVANTAGE_AIR_COOL_TARGET = "myAutoCoolTargetTemp" ADVANTAGE_AIR_MYFAN = "autoAA" +ADVANTAGE_AIR_MYAUTO_MODE_SET = "myAutoModeCurrentSetMode" + +HVAC_ACTIONS = { + "cool": HVACAction.COOLING, + "heat": HVACAction.HEATING, + "vent": HVACAction.FAN, + "dry": HVACAction.DRYING, +} HVAC_MODES = [ HVACMode.OFF, @@ -175,6 +185,17 @@ class AdvantageAirAC(AdvantageAirAcEntity, ClimateEntity): return ADVANTAGE_AIR_HVAC_MODES.get(self._ac["mode"]) return HVACMode.OFF + @property + def hvac_action(self) -> HVACAction | None: + """Return the current running HVAC action.""" + if self._ac["state"] == ADVANTAGE_AIR_STATE_OFF: + return HVACAction.OFF + if self._ac["mode"] == "myauto": + return HVAC_ACTIONS.get( + self._ac.get(ADVANTAGE_AIR_MYAUTO_MODE_SET, HVACAction.OFF) + ) + return HVAC_ACTIONS.get(self._ac["mode"]) + @property def fan_mode(self) -> str | None: """Return the current fan modes.""" @@ -273,6 +294,22 @@ class AdvantageAirZone(AdvantageAirZoneEntity, ClimateEntity): return HVACMode.HEAT_COOL return HVACMode.OFF + @property + def hvac_action(self) -> HVACAction | None: + """Return the HVAC action, inheriting from master AC if zone is open but idle if air is <= 5%.""" + if self._ac["state"] == ADVANTAGE_AIR_STATE_OFF: + return HVACAction.OFF + master_action = HVAC_ACTIONS.get(self._ac["mode"], HVACAction.OFF) + if self._ac["mode"] == "myauto": + master_action = HVAC_ACTIONS.get( + str(self._ac.get(ADVANTAGE_AIR_MYAUTO_MODE_SET)), HVACAction.OFF + ) + if self._zone["state"] == ADVANTAGE_AIR_STATE_OPEN: + if self._zone["value"] <= Decimal(5): + return HVACAction.IDLE + return master_action + return HVACAction.OFF + @property def current_temperature(self) -> float | None: """Return the current temperature.""" diff --git a/homeassistant/components/advantage_air/const.py b/homeassistant/components/advantage_air/const.py index 6ae0a0e06d5..103ca57f6ef 100644 --- a/homeassistant/components/advantage_air/const.py +++ b/homeassistant/components/advantage_air/const.py @@ -7,3 +7,4 @@ ADVANTAGE_AIR_STATE_CLOSE = "close" ADVANTAGE_AIR_STATE_ON = "on" ADVANTAGE_AIR_STATE_OFF = "off" ADVANTAGE_AIR_AUTOFAN_ENABLED = "aaAutoFanModeEnabled" +ADVANTAGE_AIR_NIGHT_MODE_ENABLED = "quietNightModeEnabled" diff --git a/homeassistant/components/advantage_air/switch.py b/homeassistant/components/advantage_air/switch.py index 5c4528b44c6..8560c9a9138 100644 --- a/homeassistant/components/advantage_air/switch.py +++ b/homeassistant/components/advantage_air/switch.py @@ -9,6 +9,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from . import AdvantageAirDataConfigEntry from .const import ( ADVANTAGE_AIR_AUTOFAN_ENABLED, + ADVANTAGE_AIR_NIGHT_MODE_ENABLED, ADVANTAGE_AIR_STATE_OFF, ADVANTAGE_AIR_STATE_ON, ) @@ -32,6 +33,8 @@ async def async_setup_entry( entities.append(AdvantageAirFreshAir(instance, ac_key)) if ADVANTAGE_AIR_AUTOFAN_ENABLED in ac_device["info"]: entities.append(AdvantageAirMyFan(instance, ac_key)) + if ADVANTAGE_AIR_NIGHT_MODE_ENABLED in ac_device["info"]: + entities.append(AdvantageAirNightMode(instance, ac_key)) if things := instance.coordinator.data.get("myThings"): entities.extend( AdvantageAirRelay(instance, thing) @@ -93,6 +96,32 @@ class AdvantageAirMyFan(AdvantageAirAcEntity, SwitchEntity): await self.async_update_ac({ADVANTAGE_AIR_AUTOFAN_ENABLED: False}) +class AdvantageAirNightMode(AdvantageAirAcEntity, SwitchEntity): + """Representation of Advantage 'MySleep$aver' Mode control.""" + + _attr_icon = "mdi:weather-night" + _attr_name = "MySleep$aver" + _attr_device_class = SwitchDeviceClass.SWITCH + + def __init__(self, instance: AdvantageAirData, ac_key: str) -> None: + """Initialize an Advantage Air Night Mode control.""" + super().__init__(instance, ac_key) + self._attr_unique_id += "-nightmode" + + @property + def is_on(self) -> bool: + """Return the Night Mode status.""" + return self._ac[ADVANTAGE_AIR_NIGHT_MODE_ENABLED] + + async def async_turn_on(self, **kwargs: Any) -> None: + """Turn Night Mode on.""" + await self.async_update_ac({ADVANTAGE_AIR_NIGHT_MODE_ENABLED: True}) + + async def async_turn_off(self, **kwargs: Any) -> None: + """Turn Night Mode off.""" + await self.async_update_ac({ADVANTAGE_AIR_NIGHT_MODE_ENABLED: False}) + + class AdvantageAirRelay(AdvantageAirThingEntity, SwitchEntity): """Representation of Advantage Air Thing.""" diff --git a/tests/components/advantage_air/snapshots/test_climate.ambr b/tests/components/advantage_air/snapshots/test_climate.ambr index bd1fb431ae1..b2559b5bdfd 100644 --- a/tests/components/advantage_air/snapshots/test_climate.ambr +++ b/tests/components/advantage_air/snapshots/test_climate.ambr @@ -30,6 +30,7 @@ 'auto', ]), 'friendly_name': 'myauto', + 'hvac_action': , 'hvac_modes': list([ , ,