Skip to content

Commit

Permalink
Enforce LockEntityFeature (home-assistant#82461)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Nov 22, 2022
1 parent 7f1e1ed commit a225fc4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions homeassistant/components/esphome/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/lock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions homeassistant/components/mqtt/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion pylint/plugins/hass_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ class ClassTypeHintMatch:
),
TypeHintMatch(
function_name="supported_features",
return_type=["LockEntityFeature", "int"],
return_type="LockEntityFeature",
),
TypeHintMatch(
function_name="lock",
Expand Down

0 comments on commit a225fc4

Please sign in to comment.