Enforce LockEntityFeature (#82461)

pull/82567/head
epenet 2022-11-22 07:15:11 +01:00 committed by GitHub
parent 7f1e1ed1d8
commit a225fc456f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 8 deletions

View File

@ -38,9 +38,11 @@ class EsphomeLock(EsphomeEntity[LockInfo, LockEntityState], LockEntity):
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:

View File

@ -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 @@ class LockEntity(Entity):
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

View File

@ -136,9 +136,9 @@ class MqttLock(MqttEntity, LockEntity):
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."""

View File

@ -1583,7 +1583,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
),
TypeHintMatch(
function_name="supported_features",
return_type=["LockEntityFeature", "int"],
return_type="LockEntityFeature",
),
TypeHintMatch(
function_name="lock",