From 109546aa99beaa52413f747b3eefd66f7fa4eace Mon Sep 17 00:00:00 2001 From: Alexander Bell-Towne Date: Fri, 23 Oct 2026 05:14:09 -0700 Subject: [PATCH] Pin off to the front of grouped light effect lists (#187227) Co-authored-by: Cursor --- homeassistant/components/group/light.py | 10 +++++-- tests/components/group/test_light.py | 38 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/group/light.py b/homeassistant/components/group/light.py index 39307f93975d..6f2e36ab78fa 100644 --- a/homeassistant/components/group/light.py +++ b/homeassistant/components/group/light.py @@ -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( diff --git a/tests/components/group/test_light.py b/tests/components/group/test_light.py index 29b638eb4cfa..d0375d0fc1cb 100644 --- a/tests/components/group/test_light.py +++ b/tests/components/group/test_light.py @@ -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(