diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index dfe2e6909b4..4f3240d7b31 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -747,7 +747,7 @@ class LightEntity(ToggleEntity): _attr_rgb_color: tuple[int, int, int] | None = None _attr_rgbw_color: tuple[int, int, int, int] | None = None _attr_rgbww_color: tuple[int, int, int, int, int] | None = None - _attr_supported_color_modes: set[ColorMode | str] | None = None + _attr_supported_color_modes: set[ColorMode] | set[str] | None = None _attr_supported_features: int = 0 _attr_xy_color: tuple[float, float] | None = None @@ -978,32 +978,32 @@ class LightEntity(ToggleEntity): return {key: val for key, val in data.items() if val is not None} @property - def _light_internal_supported_color_modes(self) -> set: + def _light_internal_supported_color_modes(self) -> set[ColorMode] | set[str]: """Calculate supported color modes with backwards compatibility.""" - supported_color_modes = self.supported_color_modes + if self.supported_color_modes is not None: + return self.supported_color_modes - if supported_color_modes is None: - # Backwards compatibility for supported_color_modes added in 2021.4 - # Add warning in 2021.6, remove in 2021.10 - supported_features = self.supported_features - supported_color_modes = set() + # Backwards compatibility for supported_color_modes added in 2021.4 + # Add warning in 2021.6, remove in 2021.10 + supported_features = self.supported_features + supported_color_modes: set[ColorMode] = set() - if supported_features & SUPPORT_COLOR_TEMP: - supported_color_modes.add(ColorMode.COLOR_TEMP) - if supported_features & SUPPORT_COLOR: - supported_color_modes.add(ColorMode.HS) - if supported_features & SUPPORT_WHITE_VALUE: - supported_color_modes.add(ColorMode.RGBW) - if supported_features & SUPPORT_BRIGHTNESS and not supported_color_modes: - supported_color_modes = {ColorMode.BRIGHTNESS} + if supported_features & SUPPORT_COLOR_TEMP: + supported_color_modes.add(ColorMode.COLOR_TEMP) + if supported_features & SUPPORT_COLOR: + supported_color_modes.add(ColorMode.HS) + if supported_features & SUPPORT_WHITE_VALUE: + supported_color_modes.add(ColorMode.RGBW) + if supported_features & SUPPORT_BRIGHTNESS and not supported_color_modes: + supported_color_modes = {ColorMode.BRIGHTNESS} - if not supported_color_modes: - supported_color_modes = {ColorMode.ONOFF} + if not supported_color_modes: + supported_color_modes = {ColorMode.ONOFF} return supported_color_modes @property - def supported_color_modes(self) -> set[ColorMode | str] | None: + def supported_color_modes(self) -> set[ColorMode] | set[str] | None: """Flag supported color modes.""" return self._attr_supported_color_modes diff --git a/homeassistant/components/overkiz/light.py b/homeassistant/components/overkiz/light.py index 77b8f9bad92..0ad6cb0d9c5 100644 --- a/homeassistant/components/overkiz/light.py +++ b/homeassistant/components/overkiz/light.py @@ -45,7 +45,7 @@ class OverkizLight(OverkizEntity, LightEntity): """Initialize a device.""" super().__init__(device_url, coordinator) - self._attr_supported_color_modes = set() + self._attr_supported_color_modes: set[ColorMode] = set() if self.executor.has_command(OverkizCommand.SET_RGB): self._attr_supported_color_modes.add(ColorMode.RGB) diff --git a/homeassistant/components/tradfri/light.py b/homeassistant/components/tradfri/light.py index 161c7d8f25d..32160c6a130 100644 --- a/homeassistant/components/tradfri/light.py +++ b/homeassistant/components/tradfri/light.py @@ -71,7 +71,7 @@ class TradfriLight(TradfriBaseEntity, LightEntity): self._hs_color = None # Calculate supported color modes - self._attr_supported_color_modes = set() + self._attr_supported_color_modes: set[ColorMode] = set() if self._device.light_control.can_set_color: self._attr_supported_color_modes.add(ColorMode.HS) if self._device.light_control.can_set_temp: diff --git a/homeassistant/components/tuya/light.py b/homeassistant/components/tuya/light.py index 6b8329701aa..7ba8acdc0fe 100644 --- a/homeassistant/components/tuya/light.py +++ b/homeassistant/components/tuya/light.py @@ -409,7 +409,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity): super().__init__(device, device_manager) self.entity_description = description self._attr_unique_id = f"{super().unique_id}{description.key}" - self._attr_supported_color_modes = set() + self._attr_supported_color_modes: set[ColorMode] = set() # Determine DPCodes self._color_mode_dpcode = self.find_dpcode(