Add ISY994 services to set and delete lock codes (#88754)

This commit is contained in:
shbatm 2023-02-26 01:12:00 -06:00 committed by GitHub
parent 490a0908d4
commit 7c23de469e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 111 additions and 10 deletions

View File

@ -8,16 +8,43 @@ from pyisy.constants import ISY_VALUE_UNKNOWN
from homeassistant.components.lock import LockEntity from homeassistant.components.lock import LockEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import (
AddEntitiesCallback,
async_get_current_platform,
)
from .const import _LOGGER, DOMAIN from .const import DOMAIN
from .entity import ISYNodeEntity, ISYProgramEntity from .entity import ISYNodeEntity, ISYProgramEntity
from .services import (
SERVICE_DELETE_USER_CODE_SCHEMA,
SERVICE_DELETE_ZWAVE_LOCK_USER_CODE,
SERVICE_SET_USER_CODE_SCHEMA,
SERVICE_SET_ZWAVE_LOCK_USER_CODE,
)
VALUE_TO_STATE = {0: False, 100: True} VALUE_TO_STATE = {0: False, 100: True}
@callback
def async_setup_lock_services(hass: HomeAssistant) -> None:
"""Create lock-specific services for the ISY Integration."""
platform = async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SET_ZWAVE_LOCK_USER_CODE,
SERVICE_SET_USER_CODE_SCHEMA,
"async_set_zwave_lock_user_code",
)
platform.async_register_entity_service(
SERVICE_DELETE_ZWAVE_LOCK_USER_CODE,
SERVICE_DELETE_USER_CODE_SCHEMA,
"async_delete_zwave_lock_user_code",
)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
@ -32,6 +59,7 @@ async def async_setup_entry(
entities.append(ISYLockProgramEntity(name, status, actions)) entities.append(ISYLockProgramEntity(name, status, actions))
async_add_entities(entities) async_add_entities(entities)
async_setup_lock_services(hass)
class ISYLockEntity(ISYNodeEntity, LockEntity): class ISYLockEntity(ISYNodeEntity, LockEntity):
@ -47,12 +75,26 @@ class ISYLockEntity(ISYNodeEntity, LockEntity):
async def async_lock(self, **kwargs: Any) -> None: async def async_lock(self, **kwargs: Any) -> None:
"""Send the lock command to the ISY device.""" """Send the lock command to the ISY device."""
if not await self._node.secure_lock(): if not await self._node.secure_lock():
_LOGGER.error("Unable to lock device") raise HomeAssistantError(f"Unable to lock device {self._node.address}")
async def async_unlock(self, **kwargs: Any) -> None: async def async_unlock(self, **kwargs: Any) -> None:
"""Send the unlock command to the ISY device.""" """Send the unlock command to the ISY device."""
if not await self._node.secure_unlock(): if not await self._node.secure_unlock():
_LOGGER.error("Unable to lock device") raise HomeAssistantError(f"Unable to unlock device {self._node.address}")
async def async_set_zwave_lock_user_code(self, user_num: int, code: int) -> None:
"""Set a user lock code for a Z-Wave Lock."""
if not await self._node.set_zwave_lock_code(user_num, code):
raise HomeAssistantError(
f"Could not set user code {user_num} for {self._node.address}"
)
async def async_delete_zwave_lock_user_code(self, user_num: int) -> None:
"""Delete a user lock code for a Z-Wave Lock."""
if not await self._node.delete_zwave_lock_code(user_num):
raise HomeAssistantError(
f"Could not delete user code {user_num} for {self._node.address}"
)
class ISYLockProgramEntity(ISYProgramEntity, LockEntity): class ISYLockProgramEntity(ISYProgramEntity, LockEntity):
@ -66,9 +108,9 @@ class ISYLockProgramEntity(ISYProgramEntity, LockEntity):
async def async_lock(self, **kwargs: Any) -> None: async def async_lock(self, **kwargs: Any) -> None:
"""Lock the device.""" """Lock the device."""
if not await self._actions.run_then(): if not await self._actions.run_then():
_LOGGER.error("Unable to lock device") raise HomeAssistantError(f"Unable to lock device {self._node.address}")
async def async_unlock(self, **kwargs: Any) -> None: async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock the device.""" """Unlock the device."""
if not await self._actions.run_else(): if not await self._actions.run_else():
_LOGGER.error("Unable to unlock device") raise HomeAssistantError(f"Unable to unlock device {self._node.address}")

View File

@ -24,7 +24,7 @@
"integration_type": "hub", "integration_type": "hub",
"iot_class": "local_push", "iot_class": "local_push",
"loggers": ["pyisy"], "loggers": ["pyisy"],
"requirements": ["pyisy==3.1.13"], "requirements": ["pyisy==3.1.14"],
"ssdp": [ "ssdp": [
{ {
"manufacturer": "Universal Devices Inc.", "manufacturer": "Universal Devices Inc.",

View File

@ -52,8 +52,14 @@ SERVICE_RENAME_NODE = "rename_node"
SERVICE_SET_ON_LEVEL = "set_on_level" SERVICE_SET_ON_LEVEL = "set_on_level"
SERVICE_SET_RAMP_RATE = "set_ramp_rate" SERVICE_SET_RAMP_RATE = "set_ramp_rate"
# Services valid only for Z-Wave Locks
SERVICE_SET_ZWAVE_LOCK_USER_CODE = "set_zwave_lock_user_code"
SERVICE_DELETE_ZWAVE_LOCK_USER_CODE = "delete_zwave_lock_user_code"
CONF_PARAMETER = "parameter" CONF_PARAMETER = "parameter"
CONF_PARAMETERS = "parameters" CONF_PARAMETERS = "parameters"
CONF_USER_NUM = "user_num"
CONF_CODE = "code"
CONF_VALUE = "value" CONF_VALUE = "value"
CONF_INIT = "init" CONF_INIT = "init"
CONF_ISY = "isy" CONF_ISY = "isy"
@ -129,6 +135,13 @@ SERVICE_SET_ZWAVE_PARAMETER_SCHEMA = {
vol.Required(CONF_SIZE): vol.All(vol.Coerce(int), vol.In(VALID_PARAMETER_SIZES)), vol.Required(CONF_SIZE): vol.All(vol.Coerce(int), vol.In(VALID_PARAMETER_SIZES)),
} }
SERVICE_SET_USER_CODE_SCHEMA = {
vol.Required(CONF_USER_NUM): vol.Coerce(int),
vol.Required(CONF_CODE): vol.Coerce(int),
}
SERVICE_DELETE_USER_CODE_SCHEMA = {vol.Required(CONF_USER_NUM): vol.Coerce(int)}
SERVICE_SET_VARIABLE_SCHEMA = vol.All( SERVICE_SET_VARIABLE_SCHEMA = vol.All(
cv.has_at_least_one_key(CONF_ADDRESS, CONF_TYPE, CONF_NAME), cv.has_at_least_one_key(CONF_ADDRESS, CONF_TYPE, CONF_NAME),
vol.Schema( vol.Schema(

View File

@ -118,6 +118,52 @@ set_zwave_parameter:
- "1" - "1"
- "2" - "2"
- "4" - "4"
set_zwave_lock_user_code:
name: Set Z-Wave Lock User Code
description: >-
Set a Z-Wave Lock User Code via the ISY.
target:
entity:
integration: isy994
domain: lock
fields:
user_num:
name: User Number
description: The user slot number on the lock
required: true
example: 8
selector:
number:
min: 1
max: 255
code:
name: Code
description: The code to set for the user.
required: true
example: 33491663
selector:
number:
min: 1
max: 99999999
mode: box
delete_zwave_lock_user_code:
name: Delete Z-Wave Lock User Code
description: >-
Delete a Z-Wave Lock User Code via the ISY.
target:
entity:
integration: isy994
domain: lock
fields:
user_num:
name: User Number
description: The user slot number on the lock
required: true
example: 8
selector:
number:
min: 1
max: 255
rename_node: rename_node:
name: Rename Node on ISY name: Rename Node on ISY
description: >- description: >-

View File

@ -1708,7 +1708,7 @@ pyirishrail==0.0.2
pyiss==1.0.1 pyiss==1.0.1
# homeassistant.components.isy994 # homeassistant.components.isy994
pyisy==3.1.13 pyisy==3.1.14
# homeassistant.components.itach # homeassistant.components.itach
pyitachip2ir==0.0.7 pyitachip2ir==0.0.7

View File

@ -1227,7 +1227,7 @@ pyiqvia==2022.04.0
pyiss==1.0.1 pyiss==1.0.1
# homeassistant.components.isy994 # homeassistant.components.isy994
pyisy==3.1.13 pyisy==3.1.14
# homeassistant.components.kaleidescape # homeassistant.components.kaleidescape
pykaleidescape==1.0.1 pykaleidescape==1.0.1