diff --git a/homeassistant/components/google_assistant/trait.py b/homeassistant/components/google_assistant/trait.py index 26e80e6f03b52b4f1591b6a4598e5f7b7879a237..1ee9d4e2364f669d6c1d9f4ae5bd602264c509c2 100644 --- a/homeassistant/components/google_assistant/trait.py +++ b/homeassistant/components/google_assistant/trait.py @@ -1,4 +1,6 @@ """Implement the Smart Home traits.""" +import logging + from homeassistant.core import DOMAIN as HA_DOMAIN from homeassistant.components import ( climate, @@ -25,6 +27,8 @@ from homeassistant.util import color as color_util, temperature as temp_util from .const import ERR_VALUE_OUT_OF_RANGE from .helpers import SmartHomeError +_LOGGER = logging.getLogger(__name__) + PREFIX_TRAITS = 'action.devices.traits.' TRAIT_ONOFF = PREFIX_TRAITS + 'OnOff' TRAIT_BRIGHTNESS = PREFIX_TRAITS + 'Brightness' @@ -317,7 +321,11 @@ class ColorTemperatureTrait(_Trait): response = {} temp = self.state.attributes.get(light.ATTR_COLOR_TEMP) - if temp is not None: + # Some faulty integrations might put 0 in here, raising exception. + if temp == 0: + _LOGGER.warning('Entity %s has incorrect color temperature %s', + self.state.entity_id, temp) + elif temp is not None: response['color'] = { 'temperature': color_util.color_temperature_mired_to_kelvin(temp) diff --git a/tests/components/google_assistant/test_trait.py b/tests/components/google_assistant/test_trait.py index c18ed4b7bf34aa4f6b8831b8aef8ea759f358825..52dac7ddb61eea03b90f5bf8bdc5dcb6515923d1 100644 --- a/tests/components/google_assistant/test_trait.py +++ b/tests/components/google_assistant/test_trait.py @@ -457,6 +457,22 @@ async def test_color_temperature_light(hass): } +async def test_color_temperature_light_bad_temp(hass): + """Test ColorTemperature trait support for light domain.""" + assert not trait.ColorTemperatureTrait.supported(light.DOMAIN, 0) + assert trait.ColorTemperatureTrait.supported(light.DOMAIN, + light.SUPPORT_COLOR_TEMP) + + trt = trait.ColorTemperatureTrait(hass, State('light.bla', STATE_ON, { + light.ATTR_MIN_MIREDS: 200, + light.ATTR_COLOR_TEMP: 0, + light.ATTR_MAX_MIREDS: 500, + })) + + assert trt.query_attributes() == { + } + + async def test_scene_scene(hass): """Test Scene trait support for scene domain.""" assert trait.SceneTrait.supported(scene.DOMAIN, 0)