Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions homeassistant/components/light/hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,26 +242,16 @@ def _color_mode(self):
@property
def hs_color(self):
"""Return the hs color value."""
# pylint: disable=redefined-outer-name
mode = self._color_mode

if mode not in ('hs', 'xy'):
return

source = self.light.action if self.is_group else self.light.state

hue = source.get('hue')
sat = source.get('sat')
if mode == 'xy' and 'xy' in source:
return color.color_xy_to_hs(*source['xy'])

# Sometimes the state will not include valid hue/sat values.
# Reported as issue 13434
if hue is not None and sat is not None:
return hue / 65535 * 360, sat / 255 * 100

if 'xy' not in source:
return None
if mode == 'hs' and 'hue' in source and 'sat' in source:
return source['hue'] / 65535 * 360, source['sat'] / 255 * 100

return color.color_xy_to_hs(*source['xy'])
return None

@property
def color_temp(self):
Expand Down
17 changes: 2 additions & 15 deletions tests/components/light/test_hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ async def test_lights(hass, mock_bridge):
assert lamp_1 is not None
assert lamp_1.state == 'on'
assert lamp_1.attributes['brightness'] == 144
assert lamp_1.attributes['hs_color'] == (71.896, 83.137)
assert lamp_1.attributes['hs_color'] == (36.067, 69.804)

lamp_2 = hass.states.get('light.hue_lamp_2')
assert lamp_2 is not None
Expand All @@ -253,7 +253,7 @@ async def test_lights_color_mode(hass, mock_bridge):
assert lamp_1 is not None
assert lamp_1.state == 'on'
assert lamp_1.attributes['brightness'] == 144
assert lamp_1.attributes['hs_color'] == (71.896, 83.137)
assert lamp_1.attributes['hs_color'] == (36.067, 69.804)
assert 'color_temp' not in lamp_1.attributes

new_light1_on = LIGHT_1_ON.copy()
Expand Down Expand Up @@ -668,19 +668,6 @@ def test_hs_color():
'colormode': 'xy',
'hue': 1234,
'sat': 123,
}),
request_bridge_update=None,
bridge=Mock(),
is_group=False,
)

assert light.hs_color == (1234 / 65535 * 360, 123 / 255 * 100)

light = hue_light.HueLight(
light=Mock(state={
'colormode': 'xy',
'hue': None,
'sat': 123,
'xy': [0.4, 0.5]
}),
request_bridge_update=None,
Expand Down