diff --git a/homeassistant/components/google_assistant/trait.py b/homeassistant/components/google_assistant/trait.py index 5ae72b7a41ae7..cf9f360d4693b 100644 --- a/homeassistant/components/google_assistant/trait.py +++ b/homeassistant/components/google_assistant/trait.py @@ -1201,6 +1201,17 @@ class TemperatureSettingTrait(_Trait): preset_to_google = {climate.PRESET_ECO: "eco"} google_to_preset = {value: key for key, value in preset_to_google.items()} + action_to_google = { + climate.HVACAction.OFF: "off", + climate.HVACAction.HEATING: "heat", + climate.HVACAction.DEFROSTING: "heat", + climate.HVACAction.PREHEATING: "heat", + climate.HVACAction.COOLING: "cool", + climate.HVACAction.DRYING: "dry", + climate.HVACAction.FAN: "fan-only", + climate.HVACAction.IDLE: "none", + } + @staticmethod def supported(domain, features, device_class, _): """Test if state is supported.""" @@ -1282,6 +1293,11 @@ def query_attributes(self) -> dict[str, Any]: else: response["thermostatMode"] = self.hvac_to_google.get(operation, "none") + if ( + action := self.action_to_google.get(attrs.get(climate.ATTR_HVAC_ACTION)) + ) is not None: + response["activeThermostatMode"] = action + current_temp = attrs.get(climate.ATTR_CURRENT_TEMPERATURE) if current_temp is not None: response["thermostatTemperatureAmbient"] = round( diff --git a/tests/components/google_assistant/test_google_assistant.py b/tests/components/google_assistant/test_google_assistant.py index 3a7efe2b9b60c..001f637ba3065 100644 --- a/tests/components/google_assistant/test_google_assistant.py +++ b/tests/components/google_assistant/test_google_assistant.py @@ -231,6 +231,7 @@ async def test_query_climate_request( devices = body["payload"]["devices"] assert len(devices) == 3 assert devices["climate.heatpump"] == { + "activeThermostatMode": "heat", "online": True, "on": True, "thermostatTemperatureSetpoint": 20.0, @@ -247,6 +248,7 @@ async def test_query_climate_request( "currentFanSpeedSetting": "auto_low", } assert devices["climate.hvac"] == { + "activeThermostatMode": "cool", "online": True, "on": True, "thermostatTemperatureSetpoint": 21, @@ -295,6 +297,7 @@ async def test_query_climate_request_f( devices = body["payload"]["devices"] assert len(devices) == 3 assert devices["climate.heatpump"] == { + "activeThermostatMode": "heat", "online": True, "on": True, "thermostatTemperatureSetpoint": -6.7, @@ -311,6 +314,7 @@ async def test_query_climate_request_f( "currentFanSpeedSetting": "auto_low", } assert devices["climate.hvac"] == { + "activeThermostatMode": "cool", "online": True, "on": True, "thermostatTemperatureSetpoint": -6.1, diff --git a/tests/components/google_assistant/test_trait.py b/tests/components/google_assistant/test_trait.py index ee2ab12788946..c9f5646e9f064 100644 --- a/tests/components/google_assistant/test_trait.py +++ b/tests/components/google_assistant/test_trait.py @@ -1625,6 +1625,44 @@ async def test_temperature_setting_climate_setpoint_auto(hass: HomeAssistant) -> assert calls[0].data == {ATTR_ENTITY_ID: "climate.bla", ATTR_TEMPERATURE: 19} +async def test_temperature_setting_action_change(hass: HomeAssistant) -> None: + """Test that activeThermostatMode contains the current HVAC action.""" + trt_idle = trait.TemperatureSettingTrait( + hass, + State( + "climate.bla", + climate.HVACMode.COOL, + { + climate.ATTR_HVAC_MODES: [climate.HVACMode.OFF, climate.HVACMode.COOL], + climate.ATTR_HVAC_ACTION: climate.HVACAction.IDLE, + climate.ATTR_CURRENT_TEMPERATURE: 18, + climate.ATTR_MIN_TEMP: 10, + climate.ATTR_MAX_TEMP: 30, + ATTR_TEMPERATURE: 18, + }, + ), + BASIC_CONFIG, + ) + assert trt_idle.query_attributes().get("activeThermostatMode") == "none" + trt_cool = trait.TemperatureSettingTrait( + hass, + State( + "climate.bla", + climate.HVACMode.COOL, + { + climate.ATTR_HVAC_MODES: [climate.HVACMode.OFF, climate.HVACMode.COOL], + climate.ATTR_HVAC_ACTION: climate.HVACAction.COOLING, + climate.ATTR_CURRENT_TEMPERATURE: 23, + climate.ATTR_MIN_TEMP: 10, + climate.ATTR_MAX_TEMP: 30, + ATTR_TEMPERATURE: 18, + }, + ), + BASIC_CONFIG, + ) + assert trt_cool.query_attributes().get("activeThermostatMode") == "cool" + + async def test_temperature_control(hass: HomeAssistant) -> None: """Test TemperatureControl trait support for sensor domain.""" trt = trait.TemperatureControlTrait(