From 0cb8ff9bc6804354e601e60f99cd03b34242d939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Wed, 30 Mar 2022 13:32:15 +0200 Subject: [PATCH] Fix HVAC modes for Airzone slave zones (#68851) --- homeassistant/components/airzone/climate.py | 10 +- .../components/airzone/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/airzone/test_climate.py | 95 ++++++++++++++----- 5 files changed, 79 insertions(+), 32 deletions(-) diff --git a/homeassistant/components/airzone/climate.py b/homeassistant/components/airzone/climate.py index aac53ec35db..f9a32e8e5ff 100644 --- a/homeassistant/components/airzone/climate.py +++ b/homeassistant/components/airzone/climate.py @@ -144,10 +144,14 @@ class AirzoneClimate(AirzoneEntity, ClimateEntity): if hvac_mode == HVAC_MODE_OFF: params[API_ON] = 0 else: - if self.get_zone_value(AZD_MASTER): - mode = HVAC_MODE_HASS_TO_LIB[hvac_mode] - if mode != self.get_zone_value(AZD_MODE): + mode = HVAC_MODE_HASS_TO_LIB[hvac_mode] + if mode != self.get_zone_value(AZD_MODE): + if self.get_zone_value(AZD_MASTER): params[API_MODE] = mode + else: + raise HomeAssistantError( + f"Mode can't be changed on slave zone {self.name}" + ) params[API_ON] = 1 _LOGGER.debug("Set hvac_mode=%s params=%s", hvac_mode, params) await self._async_update_hvac_params(params) diff --git a/homeassistant/components/airzone/manifest.json b/homeassistant/components/airzone/manifest.json index 019c3347027..3f8fbc5647b 100644 --- a/homeassistant/components/airzone/manifest.json +++ b/homeassistant/components/airzone/manifest.json @@ -3,7 +3,7 @@ "name": "Airzone", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/airzone", - "requirements": ["aioairzone==0.2.1"], + "requirements": ["aioairzone==0.2.3"], "codeowners": ["@Noltari"], "iot_class": "local_polling", "loggers": ["aioairzone"] diff --git a/requirements_all.txt b/requirements_all.txt index aa02bffceb6..77f700c9128 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -110,7 +110,7 @@ aio_geojson_nsw_rfs_incidents==0.4 aio_georss_gdacs==0.5 # homeassistant.components.airzone -aioairzone==0.2.1 +aioairzone==0.2.3 # homeassistant.components.ambient_station aioambient==2021.11.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f91dc53d5a5..0a8d2325f66 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -91,7 +91,7 @@ aio_geojson_nsw_rfs_incidents==0.4 aio_georss_gdacs==0.5 # homeassistant.components.airzone -aioairzone==0.2.1 +aioairzone==0.2.3 # homeassistant.components.ambient_station aioambient==2021.11.0 diff --git a/tests/components/airzone/test_climate.py b/tests/components/airzone/test_climate.py index bc88321720c..b06bb1f046f 100644 --- a/tests/components/airzone/test_climate.py +++ b/tests/components/airzone/test_climate.py @@ -12,6 +12,7 @@ from aioairzone.const import ( API_ZONE_ID, ) from aioairzone.exceptions import AirzoneError +import pytest from homeassistant.components.airzone.const import API_TEMPERATURE_STEP from homeassistant.components.climate.const import ( @@ -52,8 +53,11 @@ async def test_airzone_create_climates(hass): assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 21.2 assert state.attributes.get(ATTR_HVAC_ACTION) == CURRENT_HVAC_OFF assert state.attributes.get(ATTR_HVAC_MODES) == [ - HVAC_MODE_HEAT, HVAC_MODE_OFF, + HVAC_MODE_FAN_ONLY, + HVAC_MODE_COOL, + HVAC_MODE_HEAT, + HVAC_MODE_DRY, ] assert state.attributes.get(ATTR_MAX_TEMP) == 30 assert state.attributes.get(ATTR_MIN_TEMP) == 15 @@ -66,8 +70,11 @@ async def test_airzone_create_climates(hass): assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 20.8 assert state.attributes.get(ATTR_HVAC_ACTION) == CURRENT_HVAC_IDLE assert state.attributes.get(ATTR_HVAC_MODES) == [ - HVAC_MODE_HEAT, HVAC_MODE_OFF, + HVAC_MODE_FAN_ONLY, + HVAC_MODE_COOL, + HVAC_MODE_HEAT, + HVAC_MODE_DRY, ] assert state.attributes.get(ATTR_MAX_TEMP) == 30 assert state.attributes.get(ATTR_MIN_TEMP) == 15 @@ -80,8 +87,11 @@ async def test_airzone_create_climates(hass): assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 20.5 assert state.attributes.get(ATTR_HVAC_ACTION) == CURRENT_HVAC_OFF assert state.attributes.get(ATTR_HVAC_MODES) == [ - HVAC_MODE_HEAT, HVAC_MODE_OFF, + HVAC_MODE_FAN_ONLY, + HVAC_MODE_COOL, + HVAC_MODE_HEAT, + HVAC_MODE_DRY, ] assert state.attributes.get(ATTR_MAX_TEMP) == 30 assert state.attributes.get(ATTR_MIN_TEMP) == 15 @@ -94,8 +104,11 @@ async def test_airzone_create_climates(hass): assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 21.1 assert state.attributes.get(ATTR_HVAC_ACTION) == CURRENT_HVAC_HEAT assert state.attributes.get(ATTR_HVAC_MODES) == [ - HVAC_MODE_HEAT, HVAC_MODE_OFF, + HVAC_MODE_FAN_ONLY, + HVAC_MODE_COOL, + HVAC_MODE_HEAT, + HVAC_MODE_DRY, ] assert state.attributes.get(ATTR_MAX_TEMP) == 30 assert state.attributes.get(ATTR_MIN_TEMP) == 15 @@ -121,7 +134,7 @@ async def test_airzone_create_climates(hass): async def test_airzone_climate_set_hvac_mode(hass): - """Test setting the target temperature.""" + """Test setting the HVAC mode.""" await async_init_integration(hass) @@ -149,8 +162,8 @@ async def test_airzone_climate_set_hvac_mode(hass): blocking=True, ) - state = hass.states.get("climate.salon") - assert state.state == HVAC_MODE_COOL + state = hass.states.get("climate.salon") + assert state.state == HVAC_MODE_COOL HVAC_MOCK_2 = { API_DATA: [ @@ -175,8 +188,41 @@ async def test_airzone_climate_set_hvac_mode(hass): blocking=True, ) - state = hass.states.get("climate.salon") - assert state.state == HVAC_MODE_OFF + state = hass.states.get("climate.salon") + assert state.state == HVAC_MODE_OFF + + +async def test_airzone_climate_set_hvac_slave_error(hass): + """Test setting the HVAC mode for a slave zone.""" + + HVAC_MOCK = { + API_DATA: [ + { + API_SYSTEM_ID: 1, + API_ZONE_ID: 5, + API_ON: 1, + } + ] + } + + await async_init_integration(hass) + + with patch( + "homeassistant.components.airzone.AirzoneLocalApi.http_request", + return_value=HVAC_MOCK, + ), pytest.raises(HomeAssistantError): + await hass.services.async_call( + CLIMATE_DOMAIN, + SERVICE_SET_HVAC_MODE, + { + ATTR_ENTITY_ID: "climate.dorm_2", + ATTR_HVAC_MODE: HVAC_MODE_COOL, + }, + blocking=True, + ) + + state = hass.states.get("climate.dorm_2") + assert state.state == HVAC_MODE_OFF async def test_airzone_climate_set_temp(hass): @@ -208,8 +254,8 @@ async def test_airzone_climate_set_temp(hass): blocking=True, ) - state = hass.states.get("climate.dorm_2") - assert state.attributes.get(ATTR_TEMPERATURE) == 20.5 + state = hass.states.get("climate.dorm_2") + assert state.attributes.get(ATTR_TEMPERATURE) == 20.5 async def test_airzone_climate_set_temp_error(hass): @@ -220,19 +266,16 @@ async def test_airzone_climate_set_temp_error(hass): with patch( "homeassistant.components.airzone.AirzoneLocalApi.put_hvac", side_effect=AirzoneError, - ): - try: - await hass.services.async_call( - CLIMATE_DOMAIN, - SERVICE_SET_TEMPERATURE, - { - ATTR_ENTITY_ID: "climate.dorm_2", - ATTR_TEMPERATURE: 20.5, - }, - blocking=True, - ) - except HomeAssistantError: - pass + ), pytest.raises(HomeAssistantError): + await hass.services.async_call( + CLIMATE_DOMAIN, + SERVICE_SET_TEMPERATURE, + { + ATTR_ENTITY_ID: "climate.dorm_2", + ATTR_TEMPERATURE: 20.5, + }, + blocking=True, + ) - state = hass.states.get("climate.dorm_2") - assert state.attributes.get(ATTR_TEMPERATURE) == 19.5 + state = hass.states.get("climate.dorm_2") + assert state.attributes.get(ATTR_TEMPERATURE) == 19.5