From a225fc456fb11901ccc628fbb45a3a2c87efe085 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 22 Nov 2022 07:15:11 +0100 Subject: [PATCH] Enforce LockEntityFeature (#82461) --- homeassistant/components/esphome/lock.py | 6 ++++-- homeassistant/components/lock/__init__.py | 4 ++-- homeassistant/components/mqtt/lock.py | 6 +++--- pylint/plugins/hass_enforce_type_hints.py | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/esphome/lock.py b/homeassistant/components/esphome/lock.py index 12666971d71ae0..947ea4729bb24d 100644 --- a/homeassistant/components/esphome/lock.py +++ b/homeassistant/components/esphome/lock.py @@ -38,9 +38,11 @@ def assumed_state(self) -> bool: return self._static_info.assumed_state @property - def supported_features(self) -> LockEntityFeature | int: + def supported_features(self) -> LockEntityFeature: """Flag supported features.""" - return LockEntityFeature.OPEN if self._static_info.supports_open else 0 + if self._static_info.supports_open: + return LockEntityFeature.OPEN + return LockEntityFeature(0) @property def code_format(self) -> str | None: diff --git a/homeassistant/components/lock/__init__.py b/homeassistant/components/lock/__init__.py index 412e314da0fcba..5008fa0ca2b779 100644 --- a/homeassistant/components/lock/__init__.py +++ b/homeassistant/components/lock/__init__.py @@ -112,7 +112,7 @@ class LockEntity(Entity): _attr_is_unlocking: bool | None = None _attr_is_jammed: bool | None = None _attr_state: None = None - _attr_supported_features: LockEntityFeature | int = 0 + _attr_supported_features: LockEntityFeature = LockEntityFeature(0) @property def changed_by(self) -> str | None: @@ -193,6 +193,6 @@ def state(self) -> str | None: return STATE_LOCKED if locked else STATE_UNLOCKED @property - def supported_features(self) -> LockEntityFeature | int: + def supported_features(self) -> LockEntityFeature: """Return the list of supported features.""" return self._attr_supported_features diff --git a/homeassistant/components/mqtt/lock.py b/homeassistant/components/mqtt/lock.py index ec1a3f2a8976fe..525d85b5a6cfca 100644 --- a/homeassistant/components/mqtt/lock.py +++ b/homeassistant/components/mqtt/lock.py @@ -136,9 +136,9 @@ def _setup_from_config(self, config: ConfigType) -> None: entity=self, ).async_render_with_possible_json_value - self._attr_supported_features = ( - LockEntityFeature.OPEN if CONF_PAYLOAD_OPEN in config else 0 - ) + self._attr_supported_features = LockEntityFeature(0) + if CONF_PAYLOAD_OPEN in config: + self._attr_supported_features |= LockEntityFeature.OPEN def _prepare_subscribe_topics(self) -> None: """(Re)Subscribe to topics.""" diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index a7c8782197fa8d..e2e889e71b32d7 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -1583,7 +1583,7 @@ class ClassTypeHintMatch: ), TypeHintMatch( function_name="supported_features", - return_type=["LockEntityFeature", "int"], + return_type="LockEntityFeature", ), TypeHintMatch( function_name="lock",