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
@property
def supported_features(self) -> LightEntityFeature | int:
def supported_features(self) -> LightEntityFeature:
"""Flag supported features."""
if self._is_dimmer:
return LightEntityFeature.TRANSITION
return 0
return LightEntityFeature(0)
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""

View File

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

View File

@ -287,7 +287,7 @@ class LightGroup(GroupEntity, LightEntity):
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):
# Merge supported features by emulating support for every feature
# we find.

View File

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

View File

@ -100,9 +100,9 @@ class HassAqualinkLight(AqualinkEntity, LightEntity):
return {self.color_mode}
@property
def supported_features(self) -> LightEntityFeature | int:
def supported_features(self) -> LightEntityFeature:
"""Return the list of features supported by the light."""
if self.dev.supports_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_rgbww_color: tuple[int, int, int, int, int] | 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
@property
@ -1060,6 +1060,6 @@ class LightEntity(ToggleEntity):
return self._attr_supported_color_modes
@property
def supported_features(self) -> LightEntityFeature | int:
def supported_features(self) -> LightEntityFeature:
"""Flag supported features."""
return self._attr_supported_features

View File

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

View File

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

View File

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

View File

@ -120,7 +120,7 @@ class TasmotaLight(
def _setup_from_entity(self) -> None:
"""(Re)Setup the entity."""
self._supported_color_modes = set()
supported_features = 0
supported_features = LightEntityFeature(0)
light_type = self._tasmota_entity.light_type
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
@property
def supported_features(self) -> LightEntityFeature | int:
def supported_features(self) -> LightEntityFeature:
"""Flag supported features."""
supported_features = 0
supported_features = LightEntityFeature(0)
if self._effect_script is not None:
supported_features |= LightEntityFeature.EFFECT
if self._supports_transition is True:

View File

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

View File

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

View File

@ -18,6 +18,7 @@ from zigpy.zcl.foundation import Status
from homeassistant.components import light
from homeassistant.components.light import (
ColorMode,
LightEntityFeature,
brightness_supported,
filter_supported_color_modes,
)
@ -1078,7 +1079,7 @@ class LightGroup(BaseLight, ZhaGroupEntity):
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):
# Merge supported features by emulating support for every feature
# we find.

View File

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