1 """Locks on Zigbee Home Automation networks."""
6 import voluptuous
as vol
16 async_get_current_platform,
19 from .entity
import ZHAEntity
20 from .helpers
import (
22 async_add_entities
as zha_async_add_entities,
23 convert_zha_error_to_ha_error,
27 SERVICE_SET_LOCK_USER_CODE =
"set_lock_user_code"
28 SERVICE_ENABLE_LOCK_USER_CODE =
"enable_lock_user_code"
29 SERVICE_DISABLE_LOCK_USER_CODE =
"disable_lock_user_code"
30 SERVICE_CLEAR_LOCK_USER_CODE =
"clear_lock_user_code"
35 config_entry: ConfigEntry,
36 async_add_entities: AddEntitiesCallback,
38 """Set up the Zigbee Home Automation Door Lock from config entry."""
40 entities_to_create = zha_data.platforms[Platform.LOCK]
46 zha_async_add_entities, async_add_entities, ZhaDoorLock, entities_to_create
49 config_entry.async_on_unload(unsub)
53 platform.async_register_entity_service(
54 SERVICE_SET_LOCK_USER_CODE,
56 vol.Required(
"code_slot"): vol.Coerce(int),
57 vol.Required(
"user_code"): cv.string,
59 "async_set_lock_user_code",
62 platform.async_register_entity_service(
63 SERVICE_ENABLE_LOCK_USER_CODE,
65 vol.Required(
"code_slot"): vol.Coerce(int),
67 "async_enable_lock_user_code",
70 platform.async_register_entity_service(
71 SERVICE_DISABLE_LOCK_USER_CODE,
73 vol.Required(
"code_slot"): vol.Coerce(int),
75 "async_disable_lock_user_code",
78 platform.async_register_entity_service(
79 SERVICE_CLEAR_LOCK_USER_CODE,
81 vol.Required(
"code_slot"): vol.Coerce(int),
83 "async_clear_lock_user_code",
88 """Representation of a ZHA lock."""
90 _attr_translation_key: str =
"door_lock"
94 """Return true if entity is locked."""
95 return self.entity_data.entity.is_locked
97 @convert_zha_error_to_ha_error
100 await self.entity_data.entity.async_lock()
103 @convert_zha_error_to_ha_error
105 """Unlock the lock."""
106 await self.entity_data.entity.async_unlock()
109 @convert_zha_error_to_ha_error
111 """Set the user_code to index X on the lock."""
112 await self.entity_data.entity.async_set_lock_user_code(
113 code_slot=code_slot, user_code=user_code
117 @convert_zha_error_to_ha_error
119 """Enable user_code at index X on the lock."""
120 await self.entity_data.entity.async_enable_lock_user_code(code_slot=code_slot)
123 @convert_zha_error_to_ha_error
125 """Disable user_code at index X on the lock."""
126 await self.entity_data.entity.async_disable_lock_user_code(code_slot=code_slot)
129 @convert_zha_error_to_ha_error
131 """Clear the user_code at index X on the lock."""
132 await self.entity_data.entity.async_clear_lock_user_code(code_slot=code_slot)
137 """Restore entity state."""
138 self.entity_data.entity.restore_external_state_attributes(
None async_clear_lock_user_code(self, int code_slot)
None async_disable_lock_user_code(self, int code_slot)
None async_lock(self, **Any kwargs)
None restore_external_state_attributes(self, State state)
None async_set_lock_user_code(self, int code_slot, str user_code)
None async_enable_lock_user_code(self, int code_slot)
None async_unlock(self, **Any kwargs)
None async_write_ha_state(self)
HAZHAData get_zha_data(HomeAssistant hass)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)