1 """Support for HomematicIP Cloud lock devices."""
3 from __future__
import annotations
8 from homematicip.aio.device
import AsyncDoorLockDrive
9 from homematicip.base.enums
import LockState, MotorState
16 from .const
import DOMAIN
17 from .entity
import HomematicipGenericEntity
18 from .helpers
import handle_errors
20 _LOGGER = logging.getLogger(__name__)
22 ATTR_AUTO_RELOCK_DELAY =
"auto_relock_delay"
23 ATTR_DOOR_HANDLE_TYPE =
"door_handle_type"
24 ATTR_DOOR_LOCK_DIRECTION =
"door_lock_direction"
25 ATTR_DOOR_LOCK_NEUTRAL_POSITION =
"door_lock_neutral_position"
26 ATTR_DOOR_LOCK_TURNS =
"door_lock_turns"
28 DEVICE_DLD_ATTRIBUTES = {
29 "autoRelockDelay": ATTR_AUTO_RELOCK_DELAY,
30 "doorHandleType": ATTR_DOOR_HANDLE_TYPE,
31 "doorLockDirection": ATTR_DOOR_LOCK_DIRECTION,
32 "doorLockNeutralPosition": ATTR_DOOR_LOCK_NEUTRAL_POSITION,
33 "doorLockTurns": ATTR_DOOR_LOCK_TURNS,
39 config_entry: ConfigEntry,
40 async_add_entities: AddEntitiesCallback,
42 """Set up the HomematicIP locks from a config entry."""
43 hap = hass.data[DOMAIN][config_entry.unique_id]
47 for device
in hap.home.devices
48 if isinstance(device, AsyncDoorLockDrive)
53 """Representation of the HomematicIP DoorLockDrive."""
55 _attr_supported_features = LockEntityFeature.OPEN
59 """Return true if device is locked."""
61 self.
_device_device.lockState == LockState.LOCKED
62 and self.
_device_device.motorState == MotorState.STOPPED
67 """Return true if device is locking."""
68 return self.
_device_device.motorState == MotorState.CLOSING
72 """Return true if device is unlocking."""
73 return self.
_device_device.motorState == MotorState.OPENING
77 """Lock the device."""
78 return await self.
_device_device.set_lock_state(LockState.LOCKED)
82 """Unlock the device."""
83 return await self.
_device_device.set_lock_state(LockState.UNLOCKED)
87 """Open the door latch."""
88 return await self.
_device_device.set_lock_state(LockState.OPEN)
92 """Return the state attributes of the device."""
93 return super().extra_state_attributes | {
95 for attr, attr_key
in DEVICE_DLD_ATTRIBUTES.items()
96 if (attr_value := getattr(self.
_device_device, attr,
None))
is not None
None async_lock(self, **Any kwargs)
None async_unlock(self, **Any kwargs)
bool|None is_locked(self)
None async_open(self, **Any kwargs)
dict[str, Any] extra_state_attributes(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)