Enforce LightEntityFeature (#82460)

This commit is contained in:
epenet 2022-11-22 07:14:47 +01:00 committed by GitHub
parent d4bd9a0f7e
commit 7f1e1ed1d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 27 additions and 28 deletions

View File

@ -192,11 +192,11 @@ class Control4Light(Control4Entity, LightEntity):
return None return None
@property @property
def supported_features(self) -> LightEntityFeature | int: def supported_features(self) -> LightEntityFeature:
"""Flag supported features.""" """Flag supported features."""
if self._is_dimmer: if self._is_dimmer:
return LightEntityFeature.TRANSITION return LightEntityFeature.TRANSITION
return 0 return LightEntityFeature(0)
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on.""" """Turn the entity on."""

View File

@ -112,11 +112,11 @@ class DecoraWifiLight(LightEntity):
return {self.color_mode} return {self.color_mode}
@property @property
def supported_features(self) -> LightEntityFeature | int: def supported_features(self) -> LightEntityFeature:
"""Return supported features.""" """Return supported features."""
if self._switch.canSetLevel: if self._switch.canSetLevel:
return LightEntityFeature.TRANSITION return LightEntityFeature.TRANSITION
return 0 return LightEntityFeature(0)
@property @property
def name(self): def name(self):

View File

@ -287,7 +287,7 @@ class LightGroup(GroupEntity, LightEntity):
set[str], set().union(*all_supported_color_modes) set[str], set().union(*all_supported_color_modes)
) )
self._attr_supported_features = 0 self._attr_supported_features = LightEntityFeature(0)
for support in find_state_attributes(states, ATTR_SUPPORTED_FEATURES): for support in find_state_attributes(states, ATTR_SUPPORTED_FEATURES):
# Merge supported features by emulating support for every feature # Merge supported features by emulating support for every feature
# we find. # we find.

View File

@ -108,7 +108,7 @@ def create_light(item_class, coordinator, bridge, is_group, rooms, api, item_id)
if is_group: if is_group:
supported_color_modes = set() supported_color_modes = set()
supported_features = 0 supported_features = LightEntityFeature(0)
for light_id in api_item.lights: for light_id in api_item.lights:
if light_id not in bridge.api.lights: if light_id not in bridge.api.lights:
continue continue

View File

@ -100,9 +100,9 @@ class HassAqualinkLight(AqualinkEntity, LightEntity):
return {self.color_mode} return {self.color_mode}
@property @property
def supported_features(self) -> LightEntityFeature | int: def supported_features(self) -> LightEntityFeature:
"""Return the list of features supported by the light.""" """Return the list of features supported by the light."""
if self.dev.supports_effect: if self.dev.supports_effect:
return LightEntityFeature.EFFECT return LightEntityFeature.EFFECT
return 0 return LightEntityFeature(0)

View File

@ -793,7 +793,7 @@ class LightEntity(ToggleEntity):
_attr_rgbw_color: tuple[int, 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_rgbww_color: tuple[int, int, int, int, int] | None = None
_attr_supported_color_modes: set[ColorMode] | set[str] | None = None _attr_supported_color_modes: set[ColorMode] | set[str] | None = None
_attr_supported_features: LightEntityFeature | int = 0 _attr_supported_features: LightEntityFeature = LightEntityFeature(0)
_attr_xy_color: tuple[float, float] | None = None _attr_xy_color: tuple[float, float] | None = None
@property @property
@ -1060,6 +1060,6 @@ class LightEntity(ToggleEntity):
return self._attr_supported_color_modes return self._attr_supported_color_modes
@property @property
def supported_features(self) -> LightEntityFeature | int: def supported_features(self) -> LightEntityFeature:
"""Flag supported features.""" """Flag supported features."""
return self._attr_supported_features return self._attr_supported_features

View File

@ -415,11 +415,9 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
supported_color_modes supported_color_modes
) )
supported_features: int = 0 self._attr_supported_features = LightEntityFeature(0)
supported_features |= ( if topic[CONF_EFFECT_COMMAND_TOPIC] is not None:
topic[CONF_EFFECT_COMMAND_TOPIC] is not None and LightEntityFeature.EFFECT self._attr_supported_features |= LightEntityFeature.EFFECT
)
self._attr_supported_features = supported_features
def _is_optimistic(self, attribute: str) -> bool: def _is_optimistic(self, attribute: str) -> bool:
"""Return True if the attribute is optimistically updated.""" """Return True if the attribute is optimistically updated."""

View File

@ -221,9 +221,9 @@ class Luminary(LightEntity):
return color_modes return color_modes
def _get_supported_features(self) -> LightEntityFeature | int: def _get_supported_features(self) -> LightEntityFeature:
"""Get list of supported features.""" """Get list of supported features."""
features = 0 features = LightEntityFeature(0)
if "lum" in self._luminary.supported_features(): if "lum" in self._luminary.supported_features():
features = features | LightEntityFeature.TRANSITION features = features | LightEntityFeature.TRANSITION
@ -435,7 +435,7 @@ class OsramLightifyGroup(Luminary):
# users. # users.
return f"{self._luminary.lights()}" return f"{self._luminary.lights()}"
def _get_supported_features(self) -> LightEntityFeature | int: def _get_supported_features(self) -> LightEntityFeature:
"""Get list of supported features.""" """Get list of supported features."""
features = super()._get_supported_features() features = super()._get_supported_features()
if self._luminary.scenes(): if self._luminary.scenes():

View File

@ -101,9 +101,9 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
return color_modes return color_modes
def _determine_features(self) -> LightEntityFeature | int: def _determine_features(self) -> LightEntityFeature:
"""Get features supported by the device.""" """Get features supported by the device."""
features = 0 features = LightEntityFeature(0)
# Transition # Transition
if Capability.switch_level in self._device.capabilities: if Capability.switch_level in self._device.capabilities:
features |= LightEntityFeature.TRANSITION features |= LightEntityFeature.TRANSITION

View File

@ -120,7 +120,7 @@ class TasmotaLight(
def _setup_from_entity(self) -> None: def _setup_from_entity(self) -> None:
"""(Re)Setup the entity.""" """(Re)Setup the entity."""
self._supported_color_modes = set() self._supported_color_modes = set()
supported_features = 0 supported_features = LightEntityFeature(0)
light_type = self._tasmota_entity.light_type light_type = self._tasmota_entity.light_type
if light_type in [LIGHT_TYPE_RGB, LIGHT_TYPE_RGBW, LIGHT_TYPE_RGBCW]: if light_type in [LIGHT_TYPE_RGB, LIGHT_TYPE_RGBW, LIGHT_TYPE_RGBCW]:

View File

@ -254,9 +254,9 @@ class LightTemplate(TemplateEntity, LightEntity):
return self._supported_color_modes return self._supported_color_modes
@property @property
def supported_features(self) -> LightEntityFeature | int: def supported_features(self) -> LightEntityFeature:
"""Flag supported features.""" """Flag supported features."""
supported_features = 0 supported_features = LightEntityFeature(0)
if self._effect_script is not None: if self._effect_script is not None:
supported_features |= LightEntityFeature.EFFECT supported_features |= LightEntityFeature.EFFECT
if self._supports_transition is True: if self._supports_transition is True:

View File

@ -312,7 +312,7 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
device: SmartLightStrip device: SmartLightStrip
@property @property
def supported_features(self) -> LightEntityFeature | int: def supported_features(self) -> LightEntityFeature:
"""Flag supported features.""" """Flag supported features."""
return super().supported_features | LightEntityFeature.EFFECT return super().supported_features | LightEntityFeature.EFFECT

View File

@ -1002,9 +1002,9 @@ class YeelightNightLightMode(YeelightGenericLight):
return PowerMode.MOONLIGHT return PowerMode.MOONLIGHT
@property @property
def supported_features(self) -> int: def supported_features(self) -> LightEntityFeature:
"""Flag no supported features.""" """Flag no supported features."""
return 0 return LightEntityFeature(0)
class YeelightNightLightModeWithAmbientSupport(YeelightNightLightMode): class YeelightNightLightModeWithAmbientSupport(YeelightNightLightMode):

View File

@ -18,6 +18,7 @@ from zigpy.zcl.foundation import Status
from homeassistant.components import light from homeassistant.components import light
from homeassistant.components.light import ( from homeassistant.components.light import (
ColorMode, ColorMode,
LightEntityFeature,
brightness_supported, brightness_supported,
filter_supported_color_modes, filter_supported_color_modes,
) )
@ -1078,7 +1079,7 @@ class LightGroup(BaseLight, ZhaGroupEntity):
set[str], set().union(*all_supported_color_modes) set[str], set().union(*all_supported_color_modes)
) )
self._attr_supported_features = 0 self._attr_supported_features = LightEntityFeature(0)
for support in helpers.find_state_attributes(states, ATTR_SUPPORTED_FEATURES): for support in helpers.find_state_attributes(states, ATTR_SUPPORTED_FEATURES):
# Merge supported features by emulating support for every feature # Merge supported features by emulating support for every feature
# we find. # we find.

View File

@ -1520,7 +1520,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
), ),
TypeHintMatch( TypeHintMatch(
function_name="supported_features", function_name="supported_features",
return_type=["LightEntityFeature", "int"], return_type="LightEntityFeature",
), ),
TypeHintMatch( TypeHintMatch(
function_name="turn_on", function_name="turn_on",