Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions homeassistant/components/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -978,32 +978,32 @@ def state_attributes(self):
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

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/overkiz/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
"""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)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tradfri/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(
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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tuya/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def __init__(
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(
Expand Down