diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 562789abd26..795975b5c3e 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -1336,5 +1336,5 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): """Return if light color mode issues should be reported.""" if not self.platform: return True - # philips_js, tuya and zha have known issues, we don't need users to open issues - return self.platform.platform_name not in {"philips_js", "tuya", "zha"} + # 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"} diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 84399f3da32..aa117c7ef9b 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -1185,7 +1185,7 @@ class LightGroup(BaseLight, ZhaGroupEntity): self._zha_config_enhanced_light_transition = False 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 @property @@ -1285,6 +1285,19 @@ class LightGroup(BaseLight, ZhaGroupEntity): effects_count = Counter(itertools.chain(all_effects)) 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( 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 color_mode_count = Counter(itertools.chain(all_color_modes)) 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: - color_mode_count[ColorMode.BRIGHTNESS] = 0 - self._attr_color_mode = color_mode_count.most_common(1)[0][0] + if ColorMode.BRIGHTNESS in supported_color_modes: + 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 ( color_mode_count[ColorMode.HS] != len(self._group.members) or self._zha_config_always_prefer_xy_color_mode ): # switch to XY if all members do not support HS 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) for support in helpers.find_state_attributes(states, ATTR_SUPPORTED_FEATURES): # Merge supported features by emulating support for every feature diff --git a/tests/components/light/test_init.py b/tests/components/light/test_init.py index 4becbd87c1b..ca25611f890 100644 --- a/tests/components/light/test_init.py +++ b/tests/components/light/test_init.py @@ -2791,7 +2791,7 @@ def test_report_invalid_color_mode( ( light.ColorMode.ONOFF, {light.ColorMode.ONOFF, light.ColorMode.BRIGHTNESS}, - "zha", # We don't log issues for zha + "tuya", # We don't log issues for tuya False, ), ],