1 """Support for ISY locks."""
3 from __future__
import annotations
7 from pyisy.constants
import ISY_VALUE_UNKNOWN
17 async_get_current_platform,
20 from .const
import DOMAIN
21 from .entity
import ISYNodeEntity, ISYProgramEntity
22 from .models
import IsyData
23 from .services
import (
24 SERVICE_DELETE_USER_CODE_SCHEMA,
25 SERVICE_DELETE_ZWAVE_LOCK_USER_CODE,
26 SERVICE_SET_USER_CODE_SCHEMA,
27 SERVICE_SET_ZWAVE_LOCK_USER_CODE,
30 VALUE_TO_STATE = {0:
False, 100:
True}
35 """Create lock-specific services for the ISY Integration."""
38 platform.async_register_entity_service(
39 SERVICE_SET_ZWAVE_LOCK_USER_CODE,
40 SERVICE_SET_USER_CODE_SCHEMA,
41 "async_set_zwave_lock_user_code",
43 platform.async_register_entity_service(
44 SERVICE_DELETE_ZWAVE_LOCK_USER_CODE,
45 SERVICE_DELETE_USER_CODE_SCHEMA,
46 "async_delete_zwave_lock_user_code",
51 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
53 """Set up the ISY lock platform."""
54 isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
55 devices: dict[str, DeviceInfo] = isy_data.devices
56 entities: list[ISYLockEntity | ISYLockProgramEntity] = [
58 for node
in isy_data.nodes[Platform.LOCK]
63 for name, status, actions
in isy_data.programs[Platform.LOCK]
71 """Representation of an ISY lock device."""
75 """Get whether the lock is in locked state."""
76 if self.
_node_node.status == ISY_VALUE_UNKNOWN:
78 return VALUE_TO_STATE.get(self.
_node_node.status)
81 """Send the lock command to the ISY device."""
82 if not await self.
_node_node.secure_lock():
86 """Send the unlock command to the ISY device."""
87 if not await self.
_node_node.secure_unlock():
91 """Set a user lock code for a Z-Wave Lock."""
92 if not await self.
_node_node.set_zwave_lock_code(user_num, code):
94 f
"Could not set user code {user_num} for {self._node.address}"
98 """Delete a user lock code for a Z-Wave Lock."""
99 if not await self.
_node_node.delete_zwave_lock_code(user_num):
101 f
"Could not delete user code {user_num} for {self._node.address}"
106 """Representation of a ISY lock program."""
110 """Return true if the device is locked."""
114 """Lock the device."""
115 if not await self.
_actions_actions.run_then():
119 """Unlock the device."""
120 if not await self.
_actions_actions.run_else():
None async_delete_zwave_lock_user_code(self, int user_num)
bool|None is_locked(self)
None async_set_zwave_lock_user_code(self, int user_num, int code)
None async_unlock(self, **Any kwargs)
None async_lock(self, **Any kwargs)
None async_lock(self, **Any kwargs)
None async_unlock(self, **Any kwargs)
None async_setup_lock_services(HomeAssistant hass)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)