1 """Support for ESPHome locks."""
3 from __future__
import annotations
5 from functools
import partial
8 from aioesphomeapi
import EntityInfo, LockCommand, LockEntityState, LockInfo, LockState
16 convert_api_error_ha_error,
17 esphome_state_property,
18 platform_async_setup_entry,
23 """A lock implementation for ESPHome."""
27 """Set attrs from static info."""
32 if static_info.supports_open:
34 if static_info.requires_code:
40 @esphome_state_property
42 """Return true if the lock is locked."""
43 return self.
_state_state.state
is LockState.LOCKED
46 @esphome_state_property
48 """Return true if the lock is locking."""
49 return self.
_state_state.state
is LockState.LOCKING
52 @esphome_state_property
54 """Return true if the lock is unlocking."""
55 return self.
_state_state.state
is LockState.UNLOCKING
58 @esphome_state_property
60 """Return true if the lock is jammed (incomplete locking)."""
61 return self.
_state_state.state
is LockState.JAMMED
63 @convert_api_error_ha_error
66 self.
_client_client.lock_command(self.
_key_key, LockCommand.LOCK)
68 @convert_api_error_ha_error
70 """Unlock the lock."""
71 code = kwargs.get(ATTR_CODE)
72 self.
_client_client.lock_command(self.
_key_key, LockCommand.UNLOCK, code)
74 @convert_api_error_ha_error
76 """Open the door latch."""
77 self.
_client_client.lock_command(self.
_key_key, LockCommand.OPEN)
80 async_setup_entry = partial(
81 platform_async_setup_entry,
83 entity_type=EsphomeLock,
84 state_type=LockEntityState,
None async_open(self, **Any kwargs)
bool|None is_jammed(self)
bool|None is_unlocking(self)
None async_lock(self, **Any kwargs)
None _on_static_info_update(self, EntityInfo static_info)
bool|None is_locked(self)
None async_unlock(self, **Any kwargs)
bool|None is_locking(self)