Sort effect lists in light groups (#50620)

This commit is contained in:
Franck Nijhof 2021-05-15 06:43:43 +02:00 committed by GitHub
parent e32dc306e1
commit 7221b1e09d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -371,6 +371,10 @@ class LightGroup(GroupEntity, light.LightEntity):
if all_effect_lists: if all_effect_lists:
# Merge all effects from all effect_lists with a union merge. # Merge all effects from all effect_lists with a union merge.
self._effect_list = list(set().union(*all_effect_lists)) self._effect_list = list(set().union(*all_effect_lists))
self._effect_list.sort()
if "None" in self._effect_list:
self._effect_list.remove("None")
self._effect_list.insert(0, "None")
self._effect = None self._effect = None
all_effects = list(_find_state_attributes(on_states, ATTR_EFFECT)) all_effects = list(_find_state_attributes(on_states, ATTR_EFFECT))

View File

@ -656,6 +656,10 @@ async def test_effect_list(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("light.light_group") state = hass.states.get("light.light_group")
assert set(state.attributes[ATTR_EFFECT_LIST]) == {"None", "Random", "Colorloop"} assert set(state.attributes[ATTR_EFFECT_LIST]) == {"None", "Random", "Colorloop"}
# These ensure the output is sorted as expected
assert state.attributes[ATTR_EFFECT_LIST][0] == "None"
assert state.attributes[ATTR_EFFECT_LIST][1] == "Colorloop"
assert state.attributes[ATTR_EFFECT_LIST][2] == "Random"
hass.states.async_set( hass.states.async_set(
"light.test2", "light.test2",