From 6180f7bd645b197880893de446056beac07fe30a Mon Sep 17 00:00:00 2001 From: Oxan van Leeuwen Date: Tue, 24 Mar 2020 00:57:26 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20Google=20Assistant=20temperature=20contro?= =?UTF-8?q?l=20for=20entity=20without=20mo=E2=80=A6=20(#33107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/google_assistant/trait.py | 8 ++++++ .../components/google_assistant/test_trait.py | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/homeassistant/components/google_assistant/trait.py b/homeassistant/components/google_assistant/trait.py index 9da319226fa..1c47be45651 100644 --- a/homeassistant/components/google_assistant/trait.py +++ b/homeassistant/components/google_assistant/trait.py @@ -647,6 +647,14 @@ class TemperatureSettingTrait(_Trait): elif domain == climate.DOMAIN: modes = self.climate_google_modes + + # Some integrations don't support modes (e.g. opentherm), but Google doesn't + # support changing the temperature if we don't have any modes. If there's + # only one Google doesn't support changing it, so the default mode here is + # only cosmetic. + if len(modes) == 0: + modes.append("heat") + if "off" in modes and any( mode in modes for mode in ("heatcool", "heat", "cool") ): diff --git a/tests/components/google_assistant/test_trait.py b/tests/components/google_assistant/test_trait.py index 232da039ea7..ec1848bf1ed 100644 --- a/tests/components/google_assistant/test_trait.py +++ b/tests/components/google_assistant/test_trait.py @@ -557,6 +557,32 @@ async def test_temperature_setting_climate_onoff(hass): assert len(calls) == 1 +async def test_temperature_setting_climate_no_modes(hass): + """Test TemperatureSetting trait support for climate domain not supporting any modes.""" + assert helpers.get_google_type(climate.DOMAIN, None) is not None + assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None) + + hass.config.units.temperature_unit = TEMP_CELSIUS + + trt = trait.TemperatureSettingTrait( + hass, + State( + "climate.bla", + climate.HVAC_MODE_AUTO, + { + climate.ATTR_HVAC_MODES: [], + climate.ATTR_MIN_TEMP: None, + climate.ATTR_MAX_TEMP: None, + }, + ), + BASIC_CONFIG, + ) + assert trt.sync_attributes() == { + "availableThermostatModes": "heat", + "thermostatTemperatureUnit": "C", + } + + async def test_temperature_setting_climate_range(hass): """Test TemperatureSetting trait support for climate domain - range.""" assert helpers.get_google_type(climate.DOMAIN, None) is not None