Adjust ColorMode type hint in light (#70806)
* Adjust ColorMode type hint in light * Adjust componentspull/70880/head^2
parent
906c12d8aa
commit
c0d8f94487
homeassistant/components
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue