Adjust type hints for LockEntityFeature (#82256)

This commit is contained in:
epenet 2022-11-17 12:47:48 +01:00 committed by GitHub
parent 4986f65dca
commit 8570d3aabe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View file

@ -60,7 +60,6 @@ class DemoLock(LockEntity):
) -> None:
"""Initialize the lock."""
self._attr_name = name
self._attr_supported_features = 0
if openable:
self._attr_supported_features = LockEntityFeature.OPEN
self._state = state

View file

@ -38,7 +38,7 @@ class EsphomeLock(EsphomeEntity[LockInfo, LockEntityState], LockEntity):
return self._static_info.assumed_state
@property
def supported_features(self) -> int:
def supported_features(self) -> LockEntityFeature | int:
"""Flag supported features."""
return LockEntityFeature.OPEN if self._static_info.supports_open else 0

View file

@ -112,6 +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
@property
def changed_by(self) -> str | None:
@ -190,3 +191,8 @@ class LockEntity(Entity):
if (locked := self.is_locked) is None:
return None
return STATE_LOCKED if locked else STATE_UNLOCKED
@property
def supported_features(self) -> LockEntityFeature | int:
"""Return the list of supported features."""
return self._attr_supported_features

View file

@ -1581,6 +1581,10 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
function_name="is_jammed",
return_type=["bool", None],
),
TypeHintMatch(
function_name="supported_features",
return_type=["LockEntityFeature", "int"],
),
TypeHintMatch(
function_name="lock",
kwargs_type="Any",