From 320bf53f75bd5cac94c53efdc2ecff04b05f8925 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Wed, 31 Jan 2024 03:27:36 +0100 Subject: [PATCH] Add OnOff trait for climate entities in google_assistant (#109160) --- homeassistant/components/google_assistant/trait.py | 5 +++++ tests/components/google_assistant/__init__.py | 7 ++++++- .../google_assistant/test_google_assistant.py | 6 ++++++ tests/components/google_assistant/test_trait.py | 12 +++++++++--- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/google_assistant/trait.py b/homeassistant/components/google_assistant/trait.py index 189d1354e26..bb03e796d91 100644 --- a/homeassistant/components/google_assistant/trait.py +++ b/homeassistant/components/google_assistant/trait.py @@ -484,6 +484,11 @@ class OnOffTrait(_Trait): if domain == water_heater.DOMAIN and features & WaterHeaterEntityFeature.ON_OFF: return True + if domain == climate.DOMAIN and features & ( + ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON + ): + return True + return domain in ( group.DOMAIN, input_boolean.DOMAIN, diff --git a/tests/components/google_assistant/__init__.py b/tests/components/google_assistant/__init__.py index 6fc1c9f580d..931f4d25522 100644 --- a/tests/components/google_assistant/__init__.py +++ b/tests/components/google_assistant/__init__.py @@ -305,6 +305,7 @@ DEMO_DEVICES = [ "id": "climate.hvac", "name": {"name": "Hvac"}, "traits": [ + "action.devices.traits.OnOff", "action.devices.traits.TemperatureSetting", "action.devices.traits.FanSpeed", ], @@ -326,7 +327,10 @@ DEMO_DEVICES = [ { "id": "climate.heatpump", "name": {"name": "HeatPump"}, - "traits": ["action.devices.traits.TemperatureSetting"], + "traits": [ + "action.devices.traits.OnOff", + "action.devices.traits.TemperatureSetting", + ], "type": "action.devices.types.THERMOSTAT", "willReportState": False, }, @@ -334,6 +338,7 @@ DEMO_DEVICES = [ "id": "climate.ecobee", "name": {"name": "Ecobee"}, "traits": [ + "action.devices.traits.OnOff", "action.devices.traits.TemperatureSetting", "action.devices.traits.FanSpeed", ], diff --git a/tests/components/google_assistant/test_google_assistant.py b/tests/components/google_assistant/test_google_assistant.py index 6d3a9b34cce..4fb6f50a5e6 100644 --- a/tests/components/google_assistant/test_google_assistant.py +++ b/tests/components/google_assistant/test_google_assistant.py @@ -233,12 +233,14 @@ async def test_query_climate_request( assert len(devices) == 3 assert devices["climate.heatpump"] == { "online": True, + "on": True, "thermostatTemperatureSetpoint": 20.0, "thermostatTemperatureAmbient": 25.0, "thermostatMode": "heat", } assert devices["climate.ecobee"] == { "online": True, + "on": True, "thermostatTemperatureSetpointHigh": 24, "thermostatTemperatureAmbient": 23, "thermostatMode": "heatcool", @@ -247,6 +249,7 @@ async def test_query_climate_request( } assert devices["climate.hvac"] == { "online": True, + "on": True, "thermostatTemperatureSetpoint": 21, "thermostatTemperatureAmbient": 22, "thermostatMode": "cool", @@ -294,12 +297,14 @@ async def test_query_climate_request_f( assert len(devices) == 3 assert devices["climate.heatpump"] == { "online": True, + "on": True, "thermostatTemperatureSetpoint": -6.7, "thermostatTemperatureAmbient": -3.9, "thermostatMode": "heat", } assert devices["climate.ecobee"] == { "online": True, + "on": True, "thermostatTemperatureSetpointHigh": -4.4, "thermostatTemperatureAmbient": -5, "thermostatMode": "heatcool", @@ -308,6 +313,7 @@ async def test_query_climate_request_f( } assert devices["climate.hvac"] == { "online": True, + "on": True, "thermostatTemperatureSetpoint": -6.1, "thermostatTemperatureAmbient": -5.6, "thermostatMode": "cool", diff --git a/tests/components/google_assistant/test_trait.py b/tests/components/google_assistant/test_trait.py index 3f1e28cb667..58cbc5dce0e 100644 --- a/tests/components/google_assistant/test_trait.py +++ b/tests/components/google_assistant/test_trait.py @@ -1080,7 +1080,9 @@ async def test_temperature_setting_climate_onoff(hass: HomeAssistant) -> None: "climate.bla", climate.HVACMode.AUTO, { - ATTR_SUPPORTED_FEATURES: ClimateEntityFeature.TARGET_TEMPERATURE_RANGE, + ATTR_SUPPORTED_FEATURES: ClimateEntityFeature.TARGET_TEMPERATURE_RANGE + | ClimateEntityFeature.TURN_ON + | ClimateEntityFeature.TURN_OFF, climate.ATTR_HVAC_MODES: [ climate.HVACMode.OFF, climate.HVACMode.COOL, @@ -1161,7 +1163,9 @@ async def test_temperature_setting_climate_range(hass: HomeAssistant) -> None: { climate.ATTR_CURRENT_TEMPERATURE: 70, climate.ATTR_CURRENT_HUMIDITY: 25, - ATTR_SUPPORTED_FEATURES: ClimateEntityFeature.TARGET_TEMPERATURE_RANGE, + ATTR_SUPPORTED_FEATURES: ClimateEntityFeature.TARGET_TEMPERATURE_RANGE + | ClimateEntityFeature.TURN_ON + | ClimateEntityFeature.TURN_OFF, climate.ATTR_HVAC_MODES: [ STATE_OFF, climate.HVACMode.COOL, @@ -1273,7 +1277,9 @@ async def test_temperature_setting_climate_setpoint(hass: HomeAssistant) -> None "climate.bla", climate.HVACMode.COOL, { - ATTR_SUPPORTED_FEATURES: ClimateEntityFeature.TARGET_TEMPERATURE, + ATTR_SUPPORTED_FEATURES: ClimateEntityFeature.TARGET_TEMPERATURE + | ClimateEntityFeature.TURN_ON + | ClimateEntityFeature.TURN_OFF, climate.ATTR_HVAC_MODES: [STATE_OFF, climate.HVACMode.COOL], climate.ATTR_MIN_TEMP: 10, climate.ATTR_MAX_TEMP: 30,