mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Pin off to the front of grouped light effect lists (#187227)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
814c6c692d
commit
109546aa99
@@ -9,6 +9,7 @@ import probatio
|
||||
|
||||
from homeassistant.components.light import (
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
EFFECT_OFF,
|
||||
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA,
|
||||
ColorMode,
|
||||
LightEntity,
|
||||
@@ -259,9 +260,12 @@ class LightGroup(GroupEntity, LightEntity):
|
||||
# Merge all effects from all effect_lists with a union merge.
|
||||
self._attr_effect_list = list(set().union(*all_effect_lists))
|
||||
self._attr_effect_list.sort()
|
||||
if "None" in self._attr_effect_list:
|
||||
self._attr_effect_list.remove("None")
|
||||
self._attr_effect_list.insert(0, "None")
|
||||
# Each insert lands at the front. Pin "None" first, then "off",
|
||||
# so "off" is first and "None" is second when both are present.
|
||||
for effect_name in ("None", EFFECT_OFF):
|
||||
if effect_name in self._attr_effect_list:
|
||||
self._attr_effect_list.remove(effect_name)
|
||||
self._attr_effect_list.insert(0, effect_name)
|
||||
|
||||
self._attr_effect = None
|
||||
all_effects = list(
|
||||
|
||||
@@ -29,6 +29,7 @@ from homeassistant.components.light import (
|
||||
ATTR_TRANSITION,
|
||||
ATTR_WHITE,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
EFFECT_OFF,
|
||||
SERVICE_TOGGLE,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
@@ -971,6 +972,43 @@ async def test_effect_list(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_effect_list_pins_off_ahead_of_none(hass: HomeAssistant) -> None:
|
||||
"""Test that merged effect lists keep off ahead of None."""
|
||||
await async_setup_component(
|
||||
hass,
|
||||
LIGHT_DOMAIN,
|
||||
{
|
||||
LIGHT_DOMAIN: {
|
||||
"platform": DOMAIN,
|
||||
"entities": ["light.test1", "light.test2"],
|
||||
"all": "false",
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
"light.test1",
|
||||
STATE_ON,
|
||||
{ATTR_EFFECT_LIST: ["Rainbow", EFFECT_OFF], ATTR_SUPPORTED_FEATURES: 4},
|
||||
)
|
||||
hass.states.async_set(
|
||||
"light.test2",
|
||||
STATE_ON,
|
||||
{ATTR_EFFECT_LIST: ["None", "Colorloop"], ATTR_SUPPORTED_FEATURES: 4},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes[ATTR_EFFECT_LIST] == [
|
||||
EFFECT_OFF,
|
||||
"None",
|
||||
"Colorloop",
|
||||
"Rainbow",
|
||||
]
|
||||
|
||||
|
||||
async def test_effect(hass: HomeAssistant) -> None:
|
||||
"""Test effect reporting."""
|
||||
await async_setup_component(
|
||||
|
||||
Reference in New Issue
Block a user