1 """YoLink Lock V1/V2."""
3 from __future__
import annotations
7 from yolink.client_request
import ClientRequest
8 from yolink.const
import ATTR_DEVICE_LOCK, ATTR_DEVICE_LOCK_V2
15 from .const
import DOMAIN
16 from .coordinator
import YoLinkCoordinator
17 from .entity
import YoLinkEntity
22 config_entry: ConfigEntry,
23 async_add_entities: AddEntitiesCallback,
25 """Set up YoLink lock from a config entry."""
26 device_coordinators = hass.data[DOMAIN][config_entry.entry_id].device_coordinators
29 for device_coordinator
in device_coordinators.values()
30 if device_coordinator.device.device_type
31 in [ATTR_DEVICE_LOCK, ATTR_DEVICE_LOCK_V2]
37 """YoLink Lock Entity."""
43 config_entry: ConfigEntry,
44 coordinator: YoLinkCoordinator,
46 """Init YoLink Lock."""
47 super().
__init__(config_entry, coordinator)
48 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.device.device_id}_lock_state"
52 """Update HA Entity State."""
53 state_value = state.get(
"state")
54 if self.coordinator.device.device_type == ATTR_DEVICE_LOCK_V2:
56 state_value[
"lock"] ==
"locked" if state_value
is not None else None
60 state_value ==
"locked" if state_value
is not None else None
65 """Call setState api to change lock state."""
66 if self.coordinator.device.device_type == ATTR_DEVICE_LOCK_V2:
68 ClientRequest(
"setState", {
"state": {
"lock": state}})
71 await self.
call_devicecall_device(ClientRequest(
"setState", {
"state": state}))
79 if self.coordinator.device.device_type == ATTR_DEVICE_LOCK_V2
88 if self.coordinator.device.device_type == ATTR_DEVICE_LOCK_V2
None call_device(self, ClientRequest request)
None async_lock(self, **Any kwargs)
None update_entity_state(self, dict[str, Any] state)
None call_lock_state_change(self, str state)
None __init__(self, ConfigEntry config_entry, YoLinkCoordinator coordinator)
None async_unlock(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)