From 6e4fd69326887d5a3ec0b606fbacbde3d2fa0e20 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 12 Feb 2024 19:44:46 +0100 Subject: [PATCH] Fix color mode in wiz light (#110328) --- homeassistant/components/wiz/light.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/wiz/light.py b/homeassistant/components/wiz/light.py index 216c5d9335e..3a6ba2a9f5b 100644 --- a/homeassistant/components/wiz/light.py +++ b/homeassistant/components/wiz/light.py @@ -16,6 +16,7 @@ from homeassistant.components.light import ( ColorMode, LightEntity, LightEntityFeature, + filter_supported_color_modes, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -72,21 +73,24 @@ class WizBulbEntity(WizToggleEntity, LightEntity): """Representation of WiZ Light bulb.""" _attr_name = None + _fixed_color_mode: ColorMode | None = None def __init__(self, wiz_data: WizData, name: str) -> None: """Initialize an WiZLight.""" super().__init__(wiz_data, name) bulb_type: BulbType = self._device.bulbtype features: Features = bulb_type.features - self._attr_supported_color_modes: set[ColorMode | str] = set() + color_modes = {ColorMode.ONOFF} if features.color: - self._attr_supported_color_modes.add( - RGB_WHITE_CHANNELS_COLOR_MODE[bulb_type.white_channels] - ) + color_modes.add(RGB_WHITE_CHANNELS_COLOR_MODE[bulb_type.white_channels]) if features.color_tmp: - self._attr_supported_color_modes.add(ColorMode.COLOR_TEMP) - if not self._attr_supported_color_modes and features.brightness: - self._attr_supported_color_modes.add(ColorMode.BRIGHTNESS) + color_modes.add(ColorMode.COLOR_TEMP) + if features.brightness: + color_modes.add(ColorMode.BRIGHTNESS) + self._attr_supported_color_modes = filter_supported_color_modes(color_modes) + if len(self._attr_supported_color_modes) == 1: + # If the light supports only a single color mode, set it now + self._attr_color_mode = next(iter(self._attr_supported_color_modes)) self._attr_effect_list = wiz_data.scenes if bulb_type.bulb_type != BulbClass.DW: kelvin = bulb_type.kelvin_range @@ -117,8 +121,6 @@ class WizBulbEntity(WizToggleEntity, LightEntity): elif ColorMode.RGBW in color_modes and (rgbw := state.get_rgbw()) is not None: self._attr_rgbw_color = rgbw self._attr_color_mode = ColorMode.RGBW - else: - self._attr_color_mode = ColorMode.BRIGHTNESS self._attr_effect = state.get_scene() super()._async_update_attrs()