1 """Tedee lock entities."""
5 from aiotedee
import TedeeClientException, TedeeLock, TedeeLockState
12 from .const
import DOMAIN
13 from .coordinator
import TedeeApiCoordinator, TedeeConfigEntry
14 from .entity
import TedeeEntity
21 entry: TedeeConfigEntry,
22 async_add_entities: AddEntitiesCallback,
24 """Set up the Tedee lock entity."""
25 coordinator = entry.runtime_data
27 entities: list[TedeeLockEntity] = []
28 for lock
in coordinator.data.values():
29 if lock.is_enabled_pullspring:
34 def _async_add_new_lock(lock_id: int) ->
None:
35 lock = coordinator.data[lock_id]
36 if lock.is_enabled_pullspring:
41 coordinator.new_lock_callbacks.append(_async_add_new_lock)
47 """A tedee lock that doesn't have pullspring enabled."""
54 coordinator: TedeeApiCoordinator,
56 """Initialize the lock."""
57 super().
__init__(lock, coordinator,
"lock")
61 """Return true if lock is locked."""
62 if self.
_lock_lock.state
in (
63 TedeeLockState.HALF_OPEN,
64 TedeeLockState.UNKNOWN,
67 return self.
_lock_lock.state == TedeeLockState.LOCKED
71 """Return true if lock is unlocking."""
72 return self.
_lock_lock.state == TedeeLockState.UNLOCKING
76 """Return true if lock is open."""
77 return self.
_lock_lock.state == TedeeLockState.PULLED
81 """Return true if lock is opening."""
82 return self.
_lock_lock.state == TedeeLockState.PULLING
86 """Return true if lock is locking."""
87 return self.
_lock_lock.state == TedeeLockState.LOCKING
91 """Return true if lock is jammed."""
92 return self.
_lock_lock.is_state_jammed
96 """Return True if entity is available."""
99 and self.
_lock_lock.is_connected
100 and self.
_lock_lock.state != TedeeLockState.UNCALIBRATED
104 """Unlock the door."""
106 self.
_lock_lock.state = TedeeLockState.UNLOCKING
109 await self.coordinator.tedee_client.unlock(self.
_lock_lock.lock_id)
111 except (TedeeClientException, Exception)
as ex:
113 translation_domain=DOMAIN,
114 translation_key=
"unlock_failed",
115 translation_placeholders={
"lock_id":
str(self.
_lock_lock.lock_id)},
121 self.
_lock_lock.state = TedeeLockState.LOCKING
124 await self.coordinator.tedee_client.lock(self.
_lock_lock.lock_id)
126 except (TedeeClientException, Exception)
as ex:
128 translation_domain=DOMAIN,
129 translation_key=
"lock_failed",
130 translation_placeholders={
"lock_id":
str(self.
_lock_lock.lock_id)},
135 """A tedee lock but has pullspring enabled, so it additional features."""
139 """Flag supported features."""
140 return LockEntityFeature.OPEN
143 """Open the door with pullspring."""
145 self.
_lock_lock.state = TedeeLockState.UNLOCKING
148 await self.coordinator.tedee_client.open(self.
_lock_lock.lock_id)
150 except (TedeeClientException, Exception)
as ex:
152 translation_domain=DOMAIN,
153 translation_key=
"open_failed",
154 translation_placeholders={
"lock_id":
str(self.
_lock_lock.lock_id)},
None __init__(self, TedeeLock lock, TedeeApiCoordinator coordinator)
bool|None is_locked(self)
None async_unlock(self, **Any kwargs)
None async_lock(self, **Any kwargs)
LockEntityFeature supported_features(self)
None async_open(self, **Any kwargs)
None async_write_ha_state(self)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, TedeeConfigEntry entry, AddEntitiesCallback async_add_entities)