diff --git a/homeassistant/components/google_assistant/trait.py b/homeassistant/components/google_assistant/trait.py index d32dd91a3c1..e0d12e00e30 100644 --- a/homeassistant/components/google_assistant/trait.py +++ b/homeassistant/components/google_assistant/trait.py @@ -197,6 +197,8 @@ class OnOffTrait(_Trait): @staticmethod def supported(domain, features): """Test if state is supported.""" + if domain == climate.DOMAIN: + return features & climate.SUPPORT_ON_OFF != 0 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 1568919a9b4..c8748ade00e 100644 --- a/tests/components/google_assistant/__init__.py +++ b/tests/components/google_assistant/__init__.py @@ -225,7 +225,10 @@ DEMO_DEVICES = [{ 'name': { 'name': 'HeatPump' }, - 'traits': ['action.devices.traits.TemperatureSetting'], + 'traits': [ + 'action.devices.traits.OnOff', + 'action.devices.traits.TemperatureSetting' + ], 'type': 'action.devices.types.THERMOSTAT', 'willReportState': False }, { diff --git a/tests/components/google_assistant/test_google_assistant.py b/tests/components/google_assistant/test_google_assistant.py index 047fad3574c..89e9090da98 100644 --- a/tests/components/google_assistant/test_google_assistant.py +++ b/tests/components/google_assistant/test_google_assistant.py @@ -204,6 +204,7 @@ def test_query_climate_request(hass_fixture, assistant_client, auth_header): devices = body['payload']['devices'] assert len(devices) == 3 assert devices['climate.heatpump'] == { + 'on': True, 'online': True, 'thermostatTemperatureSetpoint': 20.0, 'thermostatTemperatureAmbient': 25.0, @@ -260,6 +261,7 @@ def test_query_climate_request_f(hass_fixture, assistant_client, auth_header): devices = body['payload']['devices'] assert len(devices) == 3 assert devices['climate.heatpump'] == { + 'on': True, 'online': True, 'thermostatTemperatureSetpoint': -6.7, 'thermostatTemperatureAmbient': -3.9, diff --git a/tests/components/google_assistant/test_trait.py b/tests/components/google_assistant/test_trait.py index 42af1230eed..ef6ed7a4b8f 100644 --- a/tests/components/google_assistant/test_trait.py +++ b/tests/components/google_assistant/test_trait.py @@ -388,6 +388,47 @@ async def test_onoff_media_player(hass): } +async def test_onoff_climate(hass): + """Test OnOff trait support for climate domain.""" + assert trait.OnOffTrait.supported(climate.DOMAIN, climate.SUPPORT_ON_OFF) + + trt_on = trait.OnOffTrait(hass, State('climate.bla', STATE_ON), + BASIC_CONFIG) + + assert trt_on.sync_attributes() == {} + + assert trt_on.query_attributes() == { + 'on': True + } + + trt_off = trait.OnOffTrait(hass, State('climate.bla', STATE_OFF), + BASIC_CONFIG) + + assert trt_off.query_attributes() == { + 'on': False + } + + on_calls = async_mock_service(hass, climate.DOMAIN, SERVICE_TURN_ON) + await trt_on.execute(trait.COMMAND_ONOFF, { + 'on': True + }) + assert len(on_calls) == 1 + assert on_calls[0].data == { + ATTR_ENTITY_ID: 'climate.bla', + } + + off_calls = async_mock_service(hass, climate.DOMAIN, + SERVICE_TURN_OFF) + + await trt_on.execute(trait.COMMAND_ONOFF, { + 'on': False + }) + assert len(off_calls) == 1 + assert off_calls[0].data == { + ATTR_ENTITY_ID: 'climate.bla', + } + + async def test_dock_vacuum(hass): """Test dock trait support for vacuum domain.""" assert trait.DockTrait.supported(vacuum.DOMAIN, 0)