1 """Support for Verisure locks."""
3 from __future__
import annotations
8 from verisure
import Error
as VerisureError
17 async_get_current_platform,
23 CONF_LOCK_CODE_DIGITS,
24 DEFAULT_LOCK_CODE_DIGITS,
27 SERVICE_DISABLE_AUTOLOCK,
28 SERVICE_ENABLE_AUTOLOCK,
30 from .coordinator
import VerisureDataUpdateCoordinator
36 async_add_entities: AddEntitiesCallback,
38 """Set up Verisure alarm control panel from a config entry."""
39 coordinator: VerisureDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
42 platform.async_register_entity_service(
43 SERVICE_DISABLE_AUTOLOCK,
45 VerisureDoorlock.disable_autolock.__name__,
47 platform.async_register_entity_service(
48 SERVICE_ENABLE_AUTOLOCK,
50 VerisureDoorlock.enable_autolock.__name__,
55 for serial_number
in coordinator.data[
"locks"]
60 """Representation of a Verisure doorlock."""
62 _attr_has_entity_name =
True
66 self, coordinator: VerisureDataUpdateCoordinator, serial_number: str
68 """Initialize the Verisure lock."""
73 self.
_state_state: str |
None =
None
77 """Return device information about this entity."""
78 area = self.coordinator.data[
"locks"][self.
serial_numberserial_number][
"device"][
"area"]
81 manufacturer=
"Verisure",
82 model=
"Lockguard Smartlock",
84 via_device=(DOMAIN, self.coordinator.entry.data[CONF_GIID]),
85 configuration_url=
"https://mypages.verisure.com",
90 """Return True if entity is available."""
92 super().available
and self.
serial_numberserial_number
in self.coordinator.data[
"locks"]
97 """Last change triggered by."""
99 self.coordinator.data[
"locks"][self.
serial_numberserial_number]
106 """Last change method."""
107 return self.coordinator.data[
"locks"][self.
serial_numberserial_number][
"lockMethod"]
111 """Return the configured code format."""
112 digits = self.coordinator.entry.options.get(
113 CONF_LOCK_CODE_DIGITS, DEFAULT_LOCK_CODE_DIGITS
115 return f
"^\\d{{{digits}}}$"
119 """Return true if lock is locked."""
121 self.coordinator.data[
"locks"][self.
serial_numberserial_number][
"lockStatus"] ==
"LOCKED"
126 """Return the state attributes."""
130 """Send unlock command."""
131 code = kwargs.get(ATTR_CODE)
136 """Send lock command."""
137 code = kwargs.get(ATTR_CODE)
142 """Send set lock state command."""
144 self.coordinator.verisure.door_lock(self.
serial_numberserial_number, code)
145 if state == LockState.LOCKED
146 else self.coordinator.verisure.door_unlock(self.
serial_numberserial_number, code)
148 lock_request = await self.
hasshasshass.async_add_executor_job(
149 self.coordinator.verisure.request,
152 LOGGER.debug(
"Verisure doorlock %s", state)
153 transaction_id = lock_request.get(
"data", {}).
get(command[
"operationName"])
154 target_state =
"LOCKED" if state == LockState.LOCKED
else "UNLOCKED"
157 while lock_status !=
"OK":
161 await asyncio.sleep(0.5)
163 poll_data = await self.
hasshasshass.async_add_executor_job(
164 self.coordinator.verisure.request,
165 self.coordinator.verisure.poll_lock_state(
166 transaction_id, self.
serial_numberserial_number, target_state
170 poll_data.get(
"data", {})
171 .
get(
"installation", {})
172 .
get(
"doorLockStateChangePollResult", {})
175 if lock_status ==
"OK":
179 """Disable autolock on a doorlock."""
181 command = self.coordinator.verisure.set_autolock_enabled(
184 self.coordinator.verisure.request(command)
185 LOGGER.debug(
"Disabling autolock on %s", self.
serial_numberserial_number)
186 except VerisureError
as ex:
187 LOGGER.error(
"Could not disable autolock, %s", ex)
190 """Enable autolock on a doorlock."""
192 command = self.coordinator.verisure.set_autolock_enabled(
195 self.coordinator.verisure.request(command)
196 LOGGER.debug(
"Enabling autolock on %s", self.
serial_numberserial_number)
197 except VerisureError
as ex:
198 LOGGER.error(
"Could not enable autolock, %s", ex)
None async_lock(self, **Any kwargs)
None disable_autolock(self)
None __init__(self, VerisureDataUpdateCoordinator coordinator, str serial_number)
DeviceInfo device_info(self)
str|None changed_by(self)
None enable_autolock(self)
None async_set_lock_state(self, str code, LockState state)
None async_unlock(self, **Any kwargs)
dict[str, str] extra_state_attributes(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)