From 17573196c883a84f9831ab591eba4cdd2e4a827a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 17 Nov 2022 08:39:44 +0100 Subject: [PATCH] Adjust type hints for CoverEntityFeature (#82238) --- homeassistant/components/acmeda/cover.py | 2 +- homeassistant/components/cover/__init__.py | 3 ++- homeassistant/components/esphome/cover.py | 2 +- homeassistant/components/homekit_controller/cover.py | 2 +- homeassistant/components/motion_blinds/cover.py | 2 +- homeassistant/components/mqtt/cover.py | 2 +- homeassistant/components/shelly/cover.py | 4 ++-- homeassistant/components/template/cover.py | 2 +- homeassistant/components/velux/cover.py | 2 +- pylint/plugins/hass_enforce_type_hints.py | 4 ++++ 10 files changed, 15 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/acmeda/cover.py b/homeassistant/components/acmeda/cover.py index 3c3a5ba825a..fba538a7a70 100644 --- a/homeassistant/components/acmeda/cover.py +++ b/homeassistant/components/acmeda/cover.py @@ -70,7 +70,7 @@ class AcmedaCover(AcmedaBase, CoverEntity): return position @property - def supported_features(self) -> int: + def supported_features(self) -> CoverEntityFeature | int: """Flag supported features.""" supported_features = 0 if self.current_cover_position is not None: diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index 8b4aa79659d..37cdc6422ad 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -232,6 +232,7 @@ class CoverEntity(Entity): _attr_is_closing: bool | None = None _attr_is_opening: bool | None = None _attr_state: None = None + _attr_supported_features: CoverEntityFeature | int | None _cover_is_last_toggle_direction_open = True @@ -291,7 +292,7 @@ class CoverEntity(Entity): return data @property - def supported_features(self) -> int: + def supported_features(self) -> CoverEntityFeature | int: """Flag supported features.""" if self._attr_supported_features is not None: return self._attr_supported_features diff --git a/homeassistant/components/esphome/cover.py b/homeassistant/components/esphome/cover.py index 10662977307..1b3e42d5a17 100644 --- a/homeassistant/components/esphome/cover.py +++ b/homeassistant/components/esphome/cover.py @@ -38,7 +38,7 @@ class EsphomeCover(EsphomeEntity[CoverInfo, CoverState], CoverEntity): """A cover implementation for ESPHome.""" @property - def supported_features(self) -> int: + def supported_features(self) -> CoverEntityFeature: """Flag supported features.""" flags = ( CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP diff --git a/homeassistant/components/homekit_controller/cover.py b/homeassistant/components/homekit_controller/cover.py index d4feeccc77a..fbe6f08bc75 100644 --- a/homeassistant/components/homekit_controller/cover.py +++ b/homeassistant/components/homekit_controller/cover.py @@ -143,7 +143,7 @@ class HomeKitWindowCover(HomeKitEntity, CoverEntity): ] @property - def supported_features(self) -> int: + def supported_features(self) -> CoverEntityFeature: """Flag supported features.""" features = ( CoverEntityFeature.OPEN diff --git a/homeassistant/components/motion_blinds/cover.py b/homeassistant/components/motion_blinds/cover.py index a73166912f4..e0d02750d6d 100644 --- a/homeassistant/components/motion_blinds/cover.py +++ b/homeassistant/components/motion_blinds/cover.py @@ -380,7 +380,7 @@ class MotionTiltOnlyDevice(MotionTiltDevice): _restore_tilt = False @property - def supported_features(self) -> int: + def supported_features(self) -> CoverEntityFeature: """Flag supported features.""" supported_features = ( CoverEntityFeature.OPEN_TILT diff --git a/homeassistant/components/mqtt/cover.py b/homeassistant/components/mqtt/cover.py index ef8b0090015..6016f4cf96e 100644 --- a/homeassistant/components/mqtt/cover.py +++ b/homeassistant/components/mqtt/cover.py @@ -535,7 +535,7 @@ class MqttCover(MqttEntity, CoverEntity): return self._config.get(CONF_DEVICE_CLASS) @property - def supported_features(self) -> int: + def supported_features(self) -> CoverEntityFeature | int: """Flag supported features.""" supported_features = 0 if self._config.get(CONF_COMMAND_TOPIC) is not None: diff --git a/homeassistant/components/shelly/cover.py b/homeassistant/components/shelly/cover.py index 66b95a7a7fd..f2020597277 100644 --- a/homeassistant/components/shelly/cover.py +++ b/homeassistant/components/shelly/cover.py @@ -75,7 +75,7 @@ class BlockShellyCover(ShellyBlockEntity, CoverEntity): """Initialize block cover.""" super().__init__(coordinator, block) self.control_result: dict[str, Any] | None = None - self._attr_supported_features: int = ( + self._attr_supported_features = ( CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP ) if self.coordinator.device.settings["rollers"][0]["positioning"]: @@ -151,7 +151,7 @@ class RpcShellyCover(ShellyRpcEntity, CoverEntity): """Initialize rpc cover.""" super().__init__(coordinator, f"cover:{id_}") self._id = id_ - self._attr_supported_features: int = ( + self._attr_supported_features = ( CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP ) if self.status["pos_control"]: diff --git a/homeassistant/components/template/cover.py b/homeassistant/components/template/cover.py index aad0270e434..4c234e21875 100644 --- a/homeassistant/components/template/cover.py +++ b/homeassistant/components/template/cover.py @@ -309,7 +309,7 @@ class CoverTemplate(TemplateEntity, CoverEntity): return self._device_class @property - def supported_features(self) -> int: + def supported_features(self) -> CoverEntityFeature: """Flag supported features.""" supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE diff --git a/homeassistant/components/velux/cover.py b/homeassistant/components/velux/cover.py index f721a628ef8..c924fe5c10b 100644 --- a/homeassistant/components/velux/cover.py +++ b/homeassistant/components/velux/cover.py @@ -40,7 +40,7 @@ class VeluxCover(VeluxEntity, CoverEntity): """Representation of a Velux cover.""" @property - def supported_features(self) -> int: + def supported_features(self) -> CoverEntityFeature: """Flag supported features.""" supported_features = ( CoverEntityFeature.OPEN diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 873a783c1ca..2bb80cac2d7 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -1108,6 +1108,10 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { function_name="is_closed", return_type=["bool", None], ), + TypeHintMatch( + function_name="supported_features", + return_type=["CoverEntityFeature", "int"], + ), TypeHintMatch( function_name="open_cover", kwargs_type="Any",