Add OnOff trait for climate entities in google_assistant (#109160)

This commit is contained in:
Jan Bouwhuis 2024-01-31 03:27:36 +01:00 committed by GitHub
parent a7a41e54f6
commit 320bf53f75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 4 deletions

View file

@ -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,

View file

@ -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",
],

View file

@ -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",

View file

@ -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,