From 7f1e1ed1d84700fc1517f6e2c10260a9698f4eb6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 22 Nov 2022 07:14:47 +0100 Subject: [PATCH] Enforce LightEntityFeature (#82460) --- homeassistant/components/control4/light.py | 4 ++-- homeassistant/components/decora_wifi/light.py | 4 ++-- homeassistant/components/group/light.py | 2 +- homeassistant/components/hue/v1/light.py | 2 +- homeassistant/components/iaqualink/light.py | 4 ++-- homeassistant/components/light/__init__.py | 4 ++-- homeassistant/components/mqtt/light/schema_basic.py | 8 +++----- homeassistant/components/osramlightify/light.py | 6 +++--- homeassistant/components/smartthings/light.py | 4 ++-- homeassistant/components/tasmota/light.py | 2 +- homeassistant/components/template/light.py | 4 ++-- homeassistant/components/tplink/light.py | 2 +- homeassistant/components/yeelight/light.py | 4 ++-- homeassistant/components/zha/light.py | 3 ++- pylint/plugins/hass_enforce_type_hints.py | 2 +- 15 files changed, 27 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/control4/light.py b/homeassistant/components/control4/light.py index 51da8113710..1f738803c2e 100644 --- a/homeassistant/components/control4/light.py +++ b/homeassistant/components/control4/light.py @@ -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.""" diff --git a/homeassistant/components/decora_wifi/light.py b/homeassistant/components/decora_wifi/light.py index 820b5c8f53a..c103636563c 100644 --- a/homeassistant/components/decora_wifi/light.py +++ b/homeassistant/components/decora_wifi/light.py @@ -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): diff --git a/homeassistant/components/group/light.py b/homeassistant/components/group/light.py index 71afa5d104b..6315e79d61a 100644 --- a/homeassistant/components/group/light.py +++ b/homeassistant/components/group/light.py @@ -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. diff --git a/homeassistant/components/hue/v1/light.py b/homeassistant/components/hue/v1/light.py index 74fe25dafcf..e840835764b 100644 --- a/homeassistant/components/hue/v1/light.py +++ b/homeassistant/components/hue/v1/light.py @@ -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 diff --git a/homeassistant/components/iaqualink/light.py b/homeassistant/components/iaqualink/light.py index 853660c10bf..00c9445a3b5 100644 --- a/homeassistant/components/iaqualink/light.py +++ b/homeassistant/components/iaqualink/light.py @@ -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) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 80110dbd006..acc6252d3b3 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -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 diff --git a/homeassistant/components/mqtt/light/schema_basic.py b/homeassistant/components/mqtt/light/schema_basic.py index ea0c3b545da..dfa8af0097d 100644 --- a/homeassistant/components/mqtt/light/schema_basic.py +++ b/homeassistant/components/mqtt/light/schema_basic.py @@ -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.""" diff --git a/homeassistant/components/osramlightify/light.py b/homeassistant/components/osramlightify/light.py index d3c529c738e..fa4aca357c1 100644 --- a/homeassistant/components/osramlightify/light.py +++ b/homeassistant/components/osramlightify/light.py @@ -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(): diff --git a/homeassistant/components/smartthings/light.py b/homeassistant/components/smartthings/light.py index 514296d156a..37237323d1c 100644 --- a/homeassistant/components/smartthings/light.py +++ b/homeassistant/components/smartthings/light.py @@ -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 diff --git a/homeassistant/components/tasmota/light.py b/homeassistant/components/tasmota/light.py index 2ff51752ea5..b7b695c260f 100644 --- a/homeassistant/components/tasmota/light.py +++ b/homeassistant/components/tasmota/light.py @@ -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]: diff --git a/homeassistant/components/template/light.py b/homeassistant/components/template/light.py index 8e0027b323f..27dcbf0e014 100644 --- a/homeassistant/components/template/light.py +++ b/homeassistant/components/template/light.py @@ -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: diff --git a/homeassistant/components/tplink/light.py b/homeassistant/components/tplink/light.py index d0c056d7c17..c8944b7add2 100644 --- a/homeassistant/components/tplink/light.py +++ b/homeassistant/components/tplink/light.py @@ -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 diff --git a/homeassistant/components/yeelight/light.py b/homeassistant/components/yeelight/light.py index af1c3de74e7..da79a1eb2d6 100644 --- a/homeassistant/components/yeelight/light.py +++ b/homeassistant/components/yeelight/light.py @@ -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): diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 2953ab3b99a..b4c760b27ec 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -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. diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 4c15de25c4d..a7c8782197f 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -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",