From 096ef5da4765dd15a11851ab6c545fe1adb322ef Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 17 Jan 2023 16:13:49 +0100 Subject: [PATCH] Use Home Assistant swing modes in tado climate (#84278) --- homeassistant/components/tado/climate.py | 11 ++++++++--- homeassistant/components/tado/const.py | 11 +++++++++++ tests/components/tado/test_climate.py | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/tado/climate.py b/homeassistant/components/tado/climate.py index b913993a4e1..a72451b0023 100644 --- a/homeassistant/components/tado/climate.py +++ b/homeassistant/components/tado/climate.py @@ -42,6 +42,7 @@ from .const import ( HA_TERMINATION_TYPE, HA_TO_TADO_FAN_MODE_MAP, HA_TO_TADO_HVAC_MODE_MAP, + HA_TO_TADO_SWING_MODE_MAP, ORDERED_KNOWN_TADO_MODES, SIGNAL_TADO_UPDATE_RECEIVED, SUPPORT_PRESET, @@ -52,6 +53,7 @@ from .const import ( TADO_TO_HA_FAN_MODE_MAP, TADO_TO_HA_HVAC_MODE_MAP, TADO_TO_HA_OFFSET_MAP, + TADO_TO_HA_SWING_MODE_MAP, TEMP_OFFSET, TYPE_AIR_CONDITIONING, TYPE_HEATING, @@ -456,13 +458,16 @@ class TadoClimate(TadoZoneEntity, ClimateEntity): @property def swing_mode(self): """Active swing mode for the device.""" - return self._current_tado_swing_mode + return TADO_TO_HA_SWING_MODE_MAP[self._current_tado_swing_mode] @property def swing_modes(self): """Swing modes for the device.""" if self.supported_features & ClimateEntityFeature.SWING_MODE: - return [TADO_SWING_ON, TADO_SWING_OFF] + return [ + TADO_TO_HA_SWING_MODE_MAP[TADO_SWING_ON], + TADO_TO_HA_SWING_MODE_MAP[TADO_SWING_OFF], + ] return None @property @@ -479,7 +484,7 @@ class TadoClimate(TadoZoneEntity, ClimateEntity): def set_swing_mode(self, swing_mode: str) -> None: """Set swing modes for the device.""" - self._control_hvac(swing_mode=swing_mode) + self._control_hvac(swing_mode=HA_TO_TADO_SWING_MODE_MAP[swing_mode]) @callback def _async_update_zone_data(self): diff --git a/homeassistant/components/tado/const.py b/homeassistant/components/tado/const.py index c547179f4e9..94d074c4066 100644 --- a/homeassistant/components/tado/const.py +++ b/homeassistant/components/tado/const.py @@ -18,6 +18,8 @@ from homeassistant.components.climate import ( FAN_OFF, PRESET_AWAY, PRESET_HOME, + SWING_OFF, + SWING_ON, HVACAction, HVACMode, ) @@ -157,6 +159,15 @@ SUPPORT_PRESET = [PRESET_AWAY, PRESET_HOME] TADO_SWING_OFF = "OFF" TADO_SWING_ON = "ON" +HA_TO_TADO_SWING_MODE_MAP = { + SWING_OFF: TADO_SWING_OFF, + SWING_ON: TADO_SWING_ON, +} + +TADO_TO_HA_SWING_MODE_MAP = { + value: key for key, value in HA_TO_TADO_SWING_MODE_MAP.items() +} + DOMAIN = "tado" SIGNAL_TADO_UPDATE_RECEIVED = "tado_update_received_{}_{}_{}" diff --git a/tests/components/tado/test_climate.py b/tests/components/tado/test_climate.py index 05471d9060e..ca1ed285df9 100644 --- a/tests/components/tado/test_climate.py +++ b/tests/components/tado/test_climate.py @@ -79,7 +79,7 @@ async def test_smartac_with_swing(hass): "min_temp": 16.0, "preset_mode": "home", "preset_modes": ["away", "home"], - "swing_modes": ["ON", "OFF"], + "swing_modes": ["on", "off"], "supported_features": 57, "target_temp_step": 1.0, "temperature": 20.0,