From f5a235beee10d92f842f64ed44ad37c5271ee266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Wed, 24 May 2023 21:18:59 +0200 Subject: [PATCH] Fix Airzone min/max climate temperatures (#93161) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * airzone: climate: fix max/min temps The library now provides AZD_ABS_TEMP_MAX/AZD_ABS_TEMP_MIN which are useful for devices with different max/min temperatures depending on the current working mode (HEAT vs COOL). These new values will have the highest/lowest max/min of both modes. Until now, the max/min of the current working mode (HEAT/COOL) would be set when starting Home Assistant, limiting the temperature range if the device mode was changed after that. Signed-off-by: Álvaro Fernández Rojas * airzone: climate: update max/min temps Some devices have different max/min climate temps depending on the active mode (HEAT vs COOL), so we should update these values. Signed-off-by: Álvaro Fernández Rojas * Revert "airzone: climate: update max/min temps" This reverts commit 988194d48614e2326a45b31ffcb8730b8172ac28. * Revert "Revert "airzone: climate: update max/min temps"" This reverts commit e4ead24f71cf2a16faec9253046419a59136daa1. * tests: airzone: add max/min climate changes test Signed-off-by: Álvaro Fernández Rojas * tests: airzone: fix dict copy Signed-off-by: Álvaro Fernández Rojas --------- Signed-off-by: Álvaro Fernández Rojas --- homeassistant/components/airzone/climate.py | 4 +-- tests/components/airzone/test_climate.py | 35 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/airzone/climate.py b/homeassistant/components/airzone/climate.py index fda007cdc82..3c47c333b92 100644 --- a/homeassistant/components/airzone/climate.py +++ b/homeassistant/components/airzone/climate.py @@ -131,8 +131,6 @@ class AirzoneClimate(AirzoneZoneEntity, ClimateEntity): self._attr_unique_id = f"{self._attr_unique_id}_{system_zone_id}" self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE self._attr_target_temperature_step = API_TEMPERATURE_STEP - self._attr_max_temp = self.get_airzone_value(AZD_TEMP_MAX) - self._attr_min_temp = self.get_airzone_value(AZD_TEMP_MIN) self._attr_temperature_unit = TEMP_UNIT_LIB_TO_HASS[ self.get_airzone_value(AZD_TEMP_UNIT) ] @@ -240,6 +238,8 @@ class AirzoneClimate(AirzoneZoneEntity, ClimateEntity): ] else: self._attr_hvac_mode = HVACMode.OFF + self._attr_max_temp = self.get_airzone_value(AZD_TEMP_MAX) + self._attr_min_temp = self.get_airzone_value(AZD_TEMP_MIN) self._attr_target_temperature = self.get_airzone_value(AZD_TEMP_SET) if self.supported_features & ClimateEntityFeature.FAN_MODE: self._attr_fan_mode = self._speeds.get(self.get_airzone_value(AZD_SPEED)) diff --git a/tests/components/airzone/test_climate.py b/tests/components/airzone/test_climate.py index 0baac5c9d71..f51dd318240 100644 --- a/tests/components/airzone/test_climate.py +++ b/tests/components/airzone/test_climate.py @@ -6,17 +6,21 @@ from aioairzone.const import ( API_COOL_SET_POINT, API_DATA, API_HEAT_SET_POINT, + API_MAX_TEMP, + API_MIN_TEMP, API_MODE, API_ON, API_SET_POINT, API_SPEED, API_SYSTEM_ID, + API_SYSTEMS, API_ZONE_ID, ) from aioairzone.exceptions import AirzoneError import pytest from homeassistant.components.airzone.const import API_TEMPERATURE_STEP +from homeassistant.components.airzone.coordinator import SCAN_INTERVAL from homeassistant.components.climate import ( ATTR_CURRENT_HUMIDITY, ATTR_CURRENT_TEMPERATURE, @@ -49,8 +53,16 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError +from homeassistant.util.dt import utcnow -from .util import async_init_integration +from .util import ( + HVAC_MOCK, + HVAC_SYSTEMS_MOCK, + HVAC_WEBSERVER_MOCK, + async_init_integration, +) + +from tests.common import async_fire_time_changed async def test_airzone_create_climates(hass: HomeAssistant) -> None: @@ -211,6 +223,27 @@ async def test_airzone_create_climates(hass: HomeAssistant) -> None: assert state.attributes.get(ATTR_TARGET_TEMP_STEP) == API_TEMPERATURE_STEP assert state.attributes.get(ATTR_TEMPERATURE) == 22.8 + HVAC_MOCK_CHANGED = {**HVAC_MOCK} + HVAC_MOCK_CHANGED[API_SYSTEMS][0][API_DATA][0][API_MAX_TEMP] = 25 + HVAC_MOCK_CHANGED[API_SYSTEMS][0][API_DATA][0][API_MIN_TEMP] = 10 + + with patch( + "homeassistant.components.airzone.AirzoneLocalApi.get_hvac", + return_value=HVAC_MOCK_CHANGED, + ), patch( + "homeassistant.components.airzone.AirzoneLocalApi.get_hvac_systems", + return_value=HVAC_SYSTEMS_MOCK, + ), patch( + "homeassistant.components.airzone.AirzoneLocalApi.get_webserver", + return_value=HVAC_WEBSERVER_MOCK, + ): + async_fire_time_changed(hass, utcnow() + SCAN_INTERVAL) + await hass.async_block_till_done() + + state = hass.states.get("climate.salon") + assert state.attributes.get(ATTR_MAX_TEMP) == 25 + assert state.attributes.get(ATTR_MIN_TEMP) == 10 + async def test_airzone_climate_turn_on_off(hass: HomeAssistant) -> None: """Test turning on."""