Fix yolink lock v2 state update (#138710)

This commit is contained in:
Matrix 2025-02-25 22:51:21 +08:00 committed by GitHub
parent 3059d06960
commit e99bf21a36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,6 +51,7 @@ class YoLinkLockEntity(YoLinkEntity, LockEntity):
def update_entity_state(self, state: dict[str, Any]) -> None: def update_entity_state(self, state: dict[str, Any]) -> None:
"""Update HA Entity State.""" """Update HA Entity State."""
state_value = state.get("state") state_value = state.get("state")
if state_value is not None:
if self.coordinator.device.device_type == ATTR_DEVICE_LOCK_V2: if self.coordinator.device.device_type == ATTR_DEVICE_LOCK_V2:
self._attr_is_locked = ( self._attr_is_locked = (
state_value["lock"] == "locked" if state_value is not None else None state_value["lock"] == "locked" if state_value is not None else None
@ -69,7 +70,7 @@ class YoLinkLockEntity(YoLinkEntity, LockEntity):
) )
else: else:
await self.call_device(ClientRequest("setState", {"state": state})) await self.call_device(ClientRequest("setState", {"state": state}))
self._attr_is_locked = state == "lock" self._attr_is_locked = state in ["locked", "lock"]
self.async_write_ha_state() self.async_write_ha_state()
async def async_lock(self, **kwargs: Any) -> None: async def async_lock(self, **kwargs: Any) -> None: