|
@@ -16,6 +16,7 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
SERVICE_SET_CODE = "set_code"
|
|
SERVICE_SET_CODE = "set_code"
|
|
|
SERVICE_CLEAR_CODE = "clear_code"
|
|
SERVICE_CLEAR_CODE = "clear_code"
|
|
|
SERVICE_SET_NAME = "set_name"
|
|
SERVICE_SET_NAME = "set_name"
|
|
|
|
|
+SERVICE_SET_SLOT_ENABLED = "set_slot_enabled"
|
|
|
|
|
|
|
|
SET_CODE_SCHEMA = vol.Schema({
|
|
SET_CODE_SCHEMA = vol.Schema({
|
|
|
vol.Required("lock_entity_id"): cv.entity_id,
|
|
vol.Required("lock_entity_id"): cv.entity_id,
|
|
@@ -35,6 +36,12 @@ SET_NAME_SCHEMA = vol.Schema({
|
|
|
vol.Required("name"): cv.string,
|
|
vol.Required("name"): cv.string,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+SET_SLOT_ENABLED_SCHEMA = vol.Schema({
|
|
|
|
|
+ vol.Required("lock_entity_id"): cv.entity_id,
|
|
|
|
|
+ vol.Required("slot"): vol.All(int, vol.Range(min=1)),
|
|
|
|
|
+ vol.Required("enabled"): cv.boolean,
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
|
|
|
def _get_coordinator(hass: HomeAssistant, lock_entity_id: str) -> ZLockCoordinator:
|
|
def _get_coordinator(hass: HomeAssistant, lock_entity_id: str) -> ZLockCoordinator:
|
|
|
for entry_data in hass.data.get(DOMAIN, {}).values():
|
|
for entry_data in hass.data.get(DOMAIN, {}).values():
|
|
@@ -88,12 +95,26 @@ def register_services(hass: HomeAssistant) -> None:
|
|
|
coordinator = _get_coordinator(hass, lock_entity_id)
|
|
coordinator = _get_coordinator(hass, lock_entity_id)
|
|
|
await coordinator.async_set_name(lock_entity_id, slot, name)
|
|
await coordinator.async_set_name(lock_entity_id, slot, name)
|
|
|
|
|
|
|
|
|
|
+ async def handle_set_slot_enabled(call: ServiceCall) -> None:
|
|
|
|
|
+ from homeassistant.components.zwave_js.helpers import async_get_node_from_entity_id
|
|
|
|
|
+ from zwave_js_server.model.access_control import SetUserOptions
|
|
|
|
|
+
|
|
|
|
|
+ lock_entity_id = call.data["lock_entity_id"]
|
|
|
|
|
+ slot = call.data["slot"]
|
|
|
|
|
+ enabled = call.data["enabled"]
|
|
|
|
|
+
|
|
|
|
|
+ coordinator = _get_coordinator(hass, lock_entity_id)
|
|
|
|
|
+ node = async_get_node_from_entity_id(hass, lock_entity_id)
|
|
|
|
|
+ await node.access_control.set_user(slot, SetUserOptions(active=enabled))
|
|
|
|
|
+ await coordinator.async_refresh_lock(lock_entity_id)
|
|
|
|
|
+
|
|
|
hass.services.async_register(DOMAIN, SERVICE_SET_CODE, handle_set_code, SET_CODE_SCHEMA)
|
|
hass.services.async_register(DOMAIN, SERVICE_SET_CODE, handle_set_code, SET_CODE_SCHEMA)
|
|
|
hass.services.async_register(DOMAIN, SERVICE_CLEAR_CODE, handle_clear_code, CLEAR_CODE_SCHEMA)
|
|
hass.services.async_register(DOMAIN, SERVICE_CLEAR_CODE, handle_clear_code, CLEAR_CODE_SCHEMA)
|
|
|
hass.services.async_register(DOMAIN, SERVICE_SET_NAME, handle_set_name, SET_NAME_SCHEMA)
|
|
hass.services.async_register(DOMAIN, SERVICE_SET_NAME, handle_set_name, SET_NAME_SCHEMA)
|
|
|
|
|
+ hass.services.async_register(DOMAIN, SERVICE_SET_SLOT_ENABLED, handle_set_slot_enabled, SET_SLOT_ENABLED_SCHEMA)
|
|
|
|
|
|
|
|
|
|
|
|
|
def unregister_services(hass: HomeAssistant) -> None:
|
|
def unregister_services(hass: HomeAssistant) -> None:
|
|
|
- for service in (SERVICE_SET_CODE, SERVICE_CLEAR_CODE, SERVICE_SET_NAME):
|
|
|
|
|
|
|
+ for service in (SERVICE_SET_CODE, SERVICE_CLEAR_CODE, SERVICE_SET_NAME, SERVICE_SET_SLOT_ENABLED):
|
|
|
if hass.services.has_service(DOMAIN, service):
|
|
if hass.services.has_service(DOMAIN, service):
|
|
|
hass.services.async_remove(DOMAIN, service)
|
|
hass.services.async_remove(DOMAIN, service)
|