Adjust ColorMode type hint in light ()

* Adjust ColorMode type hint in light

* Adjust components
pull/70880/head^2
epenet 2022-04-27 16:02:23 +02:00 committed by GitHub
parent 906c12d8aa
commit c0d8f94487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 22 deletions
homeassistant/components

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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(