mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Improve ZHA group color modes (#111669)
* Set the color mode based on supported color modes * Replace `zha` with `tuya` in unit test
This commit is contained in:
parent
eeb87247e9
commit
016f2c7581
@ -1336,5 +1336,5 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
"""Return if light color mode issues should be reported."""
|
"""Return if light color mode issues should be reported."""
|
||||||
if not self.platform:
|
if not self.platform:
|
||||||
return True
|
return True
|
||||||
# philips_js, tuya and zha have known issues, we don't need users to open issues
|
# philips_js and tuya have known issues, we don't need users to open issues
|
||||||
return self.platform.platform_name not in {"philips_js", "tuya", "zha"}
|
return self.platform.platform_name not in {"philips_js", "tuya"}
|
||||||
|
@ -1185,7 +1185,7 @@ class LightGroup(BaseLight, ZhaGroupEntity):
|
|||||||
self._zha_config_enhanced_light_transition = False
|
self._zha_config_enhanced_light_transition = False
|
||||||
|
|
||||||
self._attr_color_mode = ColorMode.UNKNOWN
|
self._attr_color_mode = ColorMode.UNKNOWN
|
||||||
self._attr_supported_color_modes = set()
|
self._attr_supported_color_modes = {ColorMode.ONOFF}
|
||||||
|
|
||||||
# remove this when all ZHA platforms and base entities are updated
|
# remove this when all ZHA platforms and base entities are updated
|
||||||
@property
|
@property
|
||||||
@ -1285,6 +1285,19 @@ class LightGroup(BaseLight, ZhaGroupEntity):
|
|||||||
effects_count = Counter(itertools.chain(all_effects))
|
effects_count = Counter(itertools.chain(all_effects))
|
||||||
self._attr_effect = effects_count.most_common(1)[0][0]
|
self._attr_effect = effects_count.most_common(1)[0][0]
|
||||||
|
|
||||||
|
supported_color_modes = {ColorMode.ONOFF}
|
||||||
|
all_supported_color_modes: list[set[ColorMode]] = list(
|
||||||
|
helpers.find_state_attributes(states, light.ATTR_SUPPORTED_COLOR_MODES)
|
||||||
|
)
|
||||||
|
if all_supported_color_modes:
|
||||||
|
# Merge all color modes.
|
||||||
|
supported_color_modes = filter_supported_color_modes(
|
||||||
|
set().union(*all_supported_color_modes)
|
||||||
|
)
|
||||||
|
|
||||||
|
self._attr_supported_color_modes = supported_color_modes
|
||||||
|
|
||||||
|
self._attr_color_mode = ColorMode.UNKNOWN
|
||||||
all_color_modes = list(
|
all_color_modes = list(
|
||||||
helpers.find_state_attributes(on_states, light.ATTR_COLOR_MODE)
|
helpers.find_state_attributes(on_states, light.ATTR_COLOR_MODE)
|
||||||
)
|
)
|
||||||
@ -1292,25 +1305,26 @@ class LightGroup(BaseLight, ZhaGroupEntity):
|
|||||||
# Report the most common color mode, select brightness and onoff last
|
# 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 ColorMode.ONOFF in color_mode_count:
|
if ColorMode.ONOFF in color_mode_count:
|
||||||
color_mode_count[ColorMode.ONOFF] = -1
|
if ColorMode.ONOFF in supported_color_modes:
|
||||||
|
color_mode_count[ColorMode.ONOFF] = -1
|
||||||
|
else:
|
||||||
|
color_mode_count.pop(ColorMode.ONOFF)
|
||||||
if ColorMode.BRIGHTNESS in color_mode_count:
|
if ColorMode.BRIGHTNESS in color_mode_count:
|
||||||
color_mode_count[ColorMode.BRIGHTNESS] = 0
|
if ColorMode.BRIGHTNESS in supported_color_modes:
|
||||||
self._attr_color_mode = color_mode_count.most_common(1)[0][0]
|
color_mode_count[ColorMode.BRIGHTNESS] = 0
|
||||||
|
else:
|
||||||
|
color_mode_count.pop(ColorMode.BRIGHTNESS)
|
||||||
|
if color_mode_count:
|
||||||
|
self._attr_color_mode = color_mode_count.most_common(1)[0][0]
|
||||||
|
else:
|
||||||
|
self._attr_color_mode = next(iter(supported_color_modes))
|
||||||
|
|
||||||
if self._attr_color_mode == ColorMode.HS and (
|
if self._attr_color_mode == ColorMode.HS and (
|
||||||
color_mode_count[ColorMode.HS] != len(self._group.members)
|
color_mode_count[ColorMode.HS] != len(self._group.members)
|
||||||
or self._zha_config_always_prefer_xy_color_mode
|
or self._zha_config_always_prefer_xy_color_mode
|
||||||
): # switch to XY if all members do not support HS
|
): # switch to XY if all members do not support HS
|
||||||
self._attr_color_mode = ColorMode.XY
|
self._attr_color_mode = ColorMode.XY
|
||||||
|
|
||||||
all_supported_color_modes: list[set[ColorMode]] = list(
|
|
||||||
helpers.find_state_attributes(states, light.ATTR_SUPPORTED_COLOR_MODES)
|
|
||||||
)
|
|
||||||
if all_supported_color_modes:
|
|
||||||
# Merge all color modes.
|
|
||||||
self._attr_supported_color_modes = filter_supported_color_modes(
|
|
||||||
set().union(*all_supported_color_modes)
|
|
||||||
)
|
|
||||||
|
|
||||||
self._attr_supported_features = LightEntityFeature(0)
|
self._attr_supported_features = LightEntityFeature(0)
|
||||||
for support in helpers.find_state_attributes(states, ATTR_SUPPORTED_FEATURES):
|
for support in helpers.find_state_attributes(states, ATTR_SUPPORTED_FEATURES):
|
||||||
# Merge supported features by emulating support for every feature
|
# Merge supported features by emulating support for every feature
|
||||||
|
@ -2791,7 +2791,7 @@ def test_report_invalid_color_mode(
|
|||||||
(
|
(
|
||||||
light.ColorMode.ONOFF,
|
light.ColorMode.ONOFF,
|
||||||
{light.ColorMode.ONOFF, light.ColorMode.BRIGHTNESS},
|
{light.ColorMode.ONOFF, light.ColorMode.BRIGHTNESS},
|
||||||
"zha", # We don't log issues for zha
|
"tuya", # We don't log issues for tuya
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user