Fix faulty color temp crashing google (#16758)
* Fix faulty color temp crashing google * Rename * Print warning for incorrect color temp
This commit is contained in:
parent
c475a876ce
commit
df67093441
2 changed files with 25 additions and 1 deletions
|
@ -1,4 +1,6 @@
|
||||||
"""Implement the Smart Home traits."""
|
"""Implement the Smart Home traits."""
|
||||||
|
import logging
|
||||||
|
|
||||||
from homeassistant.core import DOMAIN as HA_DOMAIN
|
from homeassistant.core import DOMAIN as HA_DOMAIN
|
||||||
from homeassistant.components import (
|
from homeassistant.components import (
|
||||||
climate,
|
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 .const import ERR_VALUE_OUT_OF_RANGE
|
||||||
from .helpers import SmartHomeError
|
from .helpers import SmartHomeError
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PREFIX_TRAITS = 'action.devices.traits.'
|
PREFIX_TRAITS = 'action.devices.traits.'
|
||||||
TRAIT_ONOFF = PREFIX_TRAITS + 'OnOff'
|
TRAIT_ONOFF = PREFIX_TRAITS + 'OnOff'
|
||||||
TRAIT_BRIGHTNESS = PREFIX_TRAITS + 'Brightness'
|
TRAIT_BRIGHTNESS = PREFIX_TRAITS + 'Brightness'
|
||||||
|
@ -317,7 +321,11 @@ class ColorTemperatureTrait(_Trait):
|
||||||
response = {}
|
response = {}
|
||||||
|
|
||||||
temp = self.state.attributes.get(light.ATTR_COLOR_TEMP)
|
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'] = {
|
response['color'] = {
|
||||||
'temperature':
|
'temperature':
|
||||||
color_util.color_temperature_mired_to_kelvin(temp)
|
color_util.color_temperature_mired_to_kelvin(temp)
|
||||||
|
|
|
@ -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):
|
async def test_scene_scene(hass):
|
||||||
"""Test Scene trait support for scene domain."""
|
"""Test Scene trait support for scene domain."""
|
||||||
assert trait.SceneTrait.supported(scene.DOMAIN, 0)
|
assert trait.SceneTrait.supported(scene.DOMAIN, 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue