Select onoff and brightness color modes last for light groups (#51054)
This commit is contained in:
parent
c0234df136
commit
d2804433d3
2 changed files with 82 additions and 1 deletions
|
@ -27,6 +27,8 @@ from homeassistant.components.light import (
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
ATTR_WHITE_VALUE,
|
ATTR_WHITE_VALUE,
|
||||||
ATTR_XY_COLOR,
|
ATTR_XY_COLOR,
|
||||||
|
COLOR_MODE_BRIGHTNESS,
|
||||||
|
COLOR_MODE_ONOFF,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
SUPPORT_EFFECT,
|
SUPPORT_EFFECT,
|
||||||
SUPPORT_FLASH,
|
SUPPORT_FLASH,
|
||||||
|
@ -386,8 +388,12 @@ class LightGroup(GroupEntity, light.LightEntity):
|
||||||
self._color_mode = None
|
self._color_mode = None
|
||||||
all_color_modes = list(_find_state_attributes(on_states, ATTR_COLOR_MODE))
|
all_color_modes = list(_find_state_attributes(on_states, ATTR_COLOR_MODE))
|
||||||
if all_color_modes:
|
if all_color_modes:
|
||||||
# Report the most common color mode.
|
# Report the most common color mode, select brightness and onoff last
|
||||||
color_mode_count = Counter(itertools.chain(all_color_modes))
|
color_mode_count = Counter(itertools.chain(all_color_modes))
|
||||||
|
if COLOR_MODE_ONOFF in color_mode_count:
|
||||||
|
color_mode_count[COLOR_MODE_ONOFF] = -1
|
||||||
|
if COLOR_MODE_BRIGHTNESS in color_mode_count:
|
||||||
|
color_mode_count[COLOR_MODE_BRIGHTNESS] = 0
|
||||||
self._color_mode = color_mode_count.most_common(1)[0][0]
|
self._color_mode = color_mode_count.most_common(1)[0][0]
|
||||||
|
|
||||||
self._supported_color_modes = None
|
self._supported_color_modes = None
|
||||||
|
|
|
@ -26,6 +26,7 @@ from homeassistant.components.light import (
|
||||||
COLOR_MODE_BRIGHTNESS,
|
COLOR_MODE_BRIGHTNESS,
|
||||||
COLOR_MODE_COLOR_TEMP,
|
COLOR_MODE_COLOR_TEMP,
|
||||||
COLOR_MODE_HS,
|
COLOR_MODE_HS,
|
||||||
|
COLOR_MODE_ONOFF,
|
||||||
COLOR_MODE_RGBW,
|
COLOR_MODE_RGBW,
|
||||||
COLOR_MODE_RGBWW,
|
COLOR_MODE_RGBWW,
|
||||||
DOMAIN as LIGHT_DOMAIN,
|
DOMAIN as LIGHT_DOMAIN,
|
||||||
|
@ -856,6 +857,80 @@ async def test_color_mode(hass, enable_custom_integrations):
|
||||||
assert state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_HS
|
assert state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_HS
|
||||||
|
|
||||||
|
|
||||||
|
async def test_color_mode2(hass, enable_custom_integrations):
|
||||||
|
"""Test onoff color_mode and brightness are given lowest priority."""
|
||||||
|
platform = getattr(hass.components, "test.light")
|
||||||
|
platform.init(empty=True)
|
||||||
|
|
||||||
|
platform.ENTITIES.append(platform.MockLight("test1", STATE_ON))
|
||||||
|
platform.ENTITIES.append(platform.MockLight("test2", STATE_ON))
|
||||||
|
platform.ENTITIES.append(platform.MockLight("test3", STATE_ON))
|
||||||
|
platform.ENTITIES.append(platform.MockLight("test4", STATE_ON))
|
||||||
|
platform.ENTITIES.append(platform.MockLight("test5", STATE_ON))
|
||||||
|
platform.ENTITIES.append(platform.MockLight("test6", STATE_ON))
|
||||||
|
|
||||||
|
entity = platform.ENTITIES[0]
|
||||||
|
entity.supported_color_modes = {COLOR_MODE_COLOR_TEMP}
|
||||||
|
entity.color_mode = COLOR_MODE_COLOR_TEMP
|
||||||
|
|
||||||
|
entity = platform.ENTITIES[1]
|
||||||
|
entity.supported_color_modes = {COLOR_MODE_BRIGHTNESS}
|
||||||
|
entity.color_mode = COLOR_MODE_BRIGHTNESS
|
||||||
|
|
||||||
|
entity = platform.ENTITIES[2]
|
||||||
|
entity.supported_color_modes = {COLOR_MODE_BRIGHTNESS}
|
||||||
|
entity.color_mode = COLOR_MODE_BRIGHTNESS
|
||||||
|
|
||||||
|
entity = platform.ENTITIES[3]
|
||||||
|
entity.supported_color_modes = {COLOR_MODE_ONOFF}
|
||||||
|
entity.color_mode = COLOR_MODE_ONOFF
|
||||||
|
|
||||||
|
entity = platform.ENTITIES[4]
|
||||||
|
entity.supported_color_modes = {COLOR_MODE_ONOFF}
|
||||||
|
entity.color_mode = COLOR_MODE_ONOFF
|
||||||
|
|
||||||
|
entity = platform.ENTITIES[5]
|
||||||
|
entity.supported_color_modes = {COLOR_MODE_ONOFF}
|
||||||
|
entity.color_mode = COLOR_MODE_ONOFF
|
||||||
|
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
LIGHT_DOMAIN,
|
||||||
|
{
|
||||||
|
LIGHT_DOMAIN: [
|
||||||
|
{"platform": "test"},
|
||||||
|
{
|
||||||
|
"platform": DOMAIN,
|
||||||
|
"entities": [
|
||||||
|
"light.test1",
|
||||||
|
"light.test2",
|
||||||
|
"light.test3",
|
||||||
|
"light.test4",
|
||||||
|
"light.test5",
|
||||||
|
"light.test6",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await hass.async_start()
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("light.light_group")
|
||||||
|
assert state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_COLOR_TEMP
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
"light",
|
||||||
|
"turn_off",
|
||||||
|
{"entity_id": ["light.test1"]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
state = hass.states.get("light.light_group")
|
||||||
|
assert state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS
|
||||||
|
|
||||||
|
|
||||||
async def test_supported_features(hass):
|
async def test_supported_features(hass):
|
||||||
"""Test supported features reporting."""
|
"""Test supported features reporting."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
|
Loading…
Add table
Reference in a new issue