Skip to content

Commit

Permalink
Add OnOff trait for climate entities in google_assistant (#109160)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh committed Jan 31, 2024
1 parent a7a41e5 commit 320bf53
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions homeassistant/components/google_assistant/trait.py
Expand Up @@ -484,6 +484,11 @@ def supported(domain, features, device_class, _):
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,
Expand Down
7 changes: 6 additions & 1 deletion tests/components/google_assistant/__init__.py
Expand Up @@ -305,6 +305,7 @@ def should_2fa(self, state):
"id": "climate.hvac",
"name": {"name": "Hvac"},
"traits": [
"action.devices.traits.OnOff",
"action.devices.traits.TemperatureSetting",
"action.devices.traits.FanSpeed",
],
Expand All @@ -326,14 +327,18 @@ def should_2fa(self, state):
{
"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,
},
{
"id": "climate.ecobee",
"name": {"name": "Ecobee"},
"traits": [
"action.devices.traits.OnOff",
"action.devices.traits.TemperatureSetting",
"action.devices.traits.FanSpeed",
],
Expand Down
6 changes: 6 additions & 0 deletions tests/components/google_assistant/test_google_assistant.py
Expand Up @@ -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",
Expand All @@ -247,6 +249,7 @@ async def test_query_climate_request(
}
assert devices["climate.hvac"] == {
"online": True,
"on": True,
"thermostatTemperatureSetpoint": 21,
"thermostatTemperatureAmbient": 22,
"thermostatMode": "cool",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions tests/components/google_assistant/test_trait.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 320bf53

Please sign in to comment.