Add support to climate devices in Google Assistant Fan Trait (#38337)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Marcio Granzotto RodriguesandPaulus Schoutsen authored and GitHub committed 2020-08-01 04:05:00 +02:00
1 parent 2e340d2c2f
commit 416ee7f143
4 files changed
+137 -34

No files matched your search

@@ -229,7 +229,10 @@ DEMO_DEVICES = [
{
"id": "climate.hvac",
"name": {"name": "Hvac"},
"traits": ["action.devices.traits.TemperatureSetting"],
"traits": [
"action.devices.traits.TemperatureSetting",
"action.devices.traits.FanSpeed",
],
"type": "action.devices.types.THERMOSTAT",
"willReportState": False,
"attributes": {
@@ -247,7 +250,10 @@ DEMO_DEVICES = [
{
"id": "climate.ecobee",
"name": {"name": "Ecobee"},
"traits": ["action.devices.traits.TemperatureSetting"],
"traits": [
"action.devices.traits.TemperatureSetting",
"action.devices.traits.FanSpeed",
],
"type": "action.devices.types.THERMOSTAT",
"willReportState": False,
},
@@ -231,6 +231,7 @@ async def test_query_climate_request(hass_fixture, assistant_client, auth_header
"thermostatTemperatureAmbient": 23,
"thermostatMode": "heatcool",
"thermostatTemperatureSetpointLow": 21,
"currentFanSpeedSetting": "Auto Low",
}
assert devices["climate.hvac"] == {
"online": True,
@@ -238,6 +239,7 @@ async def test_query_climate_request(hass_fixture, assistant_client, auth_header
"thermostatTemperatureAmbient": 22,
"thermostatMode": "cool",
"thermostatHumidityAmbient": 54,
"currentFanSpeedSetting": "On High",
}
@@ -288,6 +290,7 @@ async def test_query_climate_request_f(hass_fixture, assistant_client, auth_head
"thermostatTemperatureAmbient": -5,
"thermostatMode": "heatcool",
"thermostatTemperatureSetpointLow": -6.1,
"currentFanSpeedSetting": "Auto Low",
}
assert devices["climate.hvac"] == {
"online": True,
@@ -295,6 +298,7 @@ async def test_query_climate_request_f(hass_fixture, assistant_client, auth_head
"thermostatTemperatureAmbient": -5.6,
"thermostatMode": "cool",
"thermostatHumidityAmbient": 54,
"currentFanSpeedSetting": "On High",
}
hass_fixture.config.units.temperature_unit = const.TEMP_CELSIUS
@@ -1313,6 +1313,65 @@ async def test_fan_speed(hass):
assert calls[0].data == {"entity_id": "fan.living_room_fan", "speed": "medium"}
async def test_climate_fan_speed(hass):
"""Test FanSpeed trait speed control support for climate domain."""
assert helpers.get_google_type(climate.DOMAIN, None) is not None
assert trait.FanSpeedTrait.supported(climate.DOMAIN, climate.SUPPORT_FAN_MODE, None)
trt = trait.FanSpeedTrait(
hass,
State(
"climate.living_room_ac",
"on",
attributes={
"fan_modes": ["auto", "low", "medium", "high"],
"fan_mode": "low",
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"availableFanSpeeds": {
"ordered": True,
"speeds": [
{
"speed_name": "auto",
"speed_values": [{"speed_synonym": ["auto"], "lang": "en"}],
},
{
"speed_name": "low",
"speed_values": [{"speed_synonym": ["low"], "lang": "en"}],
},
{
"speed_name": "medium",
"speed_values": [{"speed_synonym": ["medium"], "lang": "en"}],
},
{
"speed_name": "high",
"speed_values": [{"speed_synonym": ["high"], "lang": "en"}],
},
],
},
"reversible": False,
}
assert trt.query_attributes() == {
"currentFanSpeedSetting": "low",
}
assert trt.can_execute(trait.COMMAND_FANSPEED, params={"fanSpeed": "medium"})
calls = async_mock_service(hass, climate.DOMAIN, climate.SERVICE_SET_FAN_MODE)
await trt.execute(trait.COMMAND_FANSPEED, BASIC_DATA, {"fanSpeed": "medium"}, {})
assert len(calls) == 1
assert calls[0].data == {
"entity_id": "climate.living_room_ac",
"fan_mode": "medium",
}
async def test_inputselector(hass):
"""Test input selector trait."""
assert helpers.get_google_type(media_player.DOMAIN, None) is not None