From 542ab2dd76dc0285aa71fa235c9f76ef86e281b0 Mon Sep 17 00:00:00 2001 From: Tudor Sandu Date: Sat, 30 Sep 2023 06:06:41 +0300 Subject: [PATCH] Fix ignored argument in service call for demo climate (#101137) Fix service call for demo climate --- homeassistant/components/demo/climate.py | 3 +++ tests/components/demo/test_climate.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/homeassistant/components/demo/climate.py b/homeassistant/components/demo/climate.py index 6639c125653..b0a53909a46 100644 --- a/homeassistant/components/demo/climate.py +++ b/homeassistant/components/demo/climate.py @@ -4,6 +4,7 @@ from __future__ import annotations from typing import Any from homeassistant.components.climate import ( + ATTR_HVAC_MODE, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, ClimateEntity, @@ -258,6 +259,8 @@ class DemoClimate(ClimateEntity): ): self._target_temperature_high = kwargs.get(ATTR_TARGET_TEMP_HIGH) self._target_temperature_low = kwargs.get(ATTR_TARGET_TEMP_LOW) + if kwargs.get(ATTR_HVAC_MODE) is not None: + self._hvac_mode = HVACMode(str(kwargs.get(ATTR_HVAC_MODE))) self.async_write_ha_state() async def async_set_humidity(self, humidity: int) -> None: diff --git a/tests/components/demo/test_climate.py b/tests/components/demo/test_climate.py index fa87c439a4d..69e385ce242 100644 --- a/tests/components/demo/test_climate.py +++ b/tests/components/demo/test_climate.py @@ -198,6 +198,28 @@ async def test_set_target_temp_range_bad_attr(hass: HomeAssistant) -> None: assert state.attributes.get(ATTR_TARGET_TEMP_HIGH) == 24.0 +async def test_set_temp_with_hvac_mode(hass: HomeAssistant) -> None: + """Test the setting of the hvac_mode in set_temperature.""" + state = hass.states.get(ENTITY_CLIMATE) + assert state.attributes.get(ATTR_TEMPERATURE) == 21 + assert state.state == HVACMode.COOL + + await hass.services.async_call( + DOMAIN, + SERVICE_SET_TEMPERATURE, + { + ATTR_ENTITY_ID: ENTITY_CLIMATE, + ATTR_TEMPERATURE: 23, + ATTR_HVAC_MODE: HVACMode.OFF, + }, + blocking=True, + ) + + state = hass.states.get(ENTITY_CLIMATE) + assert state.state == HVACMode.OFF + assert state.attributes.get(ATTR_TEMPERATURE) == 23 + + async def test_set_target_humidity_bad_attr(hass: HomeAssistant) -> None: """Test setting the target humidity without required attribute.""" state = hass.states.get(ENTITY_CLIMATE)