mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
demo comp: preserve color when turning on light that's on
This commit is contained in:
parent
d506d0f424
commit
fee51d604d
@ -50,12 +50,19 @@ def setup(hass, config):
|
|||||||
if domain == "light":
|
if domain == "light":
|
||||||
rgb_color = service.data.get(ATTR_RGB_COLOR)
|
rgb_color = service.data.get(ATTR_RGB_COLOR)
|
||||||
|
|
||||||
if rgb_color is None:
|
if rgb_color:
|
||||||
color = random.choice(light_colors)
|
|
||||||
else:
|
|
||||||
color = color_RGB_to_xy(
|
color = color_RGB_to_xy(
|
||||||
rgb_color[0], rgb_color[1], rgb_color[2])
|
rgb_color[0], rgb_color[1], rgb_color[2])
|
||||||
|
|
||||||
|
else:
|
||||||
|
cur_state = hass.states.get(entity_id)
|
||||||
|
|
||||||
|
# Use current color if available
|
||||||
|
if cur_state and cur_state.attributes.get(ATTR_XY_COLOR):
|
||||||
|
color = cur_state.attributes.get(ATTR_XY_COLOR)
|
||||||
|
else:
|
||||||
|
color = random.choice(light_colors)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
ATTR_BRIGHTNESS: service.data.get(ATTR_BRIGHTNESS, 200),
|
ATTR_BRIGHTNESS: service.data.get(ATTR_BRIGHTNESS, 200),
|
||||||
ATTR_XY_COLOR: color
|
ATTR_XY_COLOR: color
|
||||||
|
Loading…
x
Reference in New Issue
Block a user