From 27c0829693c13da9cb36141a0e74ba781e506513 Mon Sep 17 00:00:00 2001 From: shbatm Date: Sat, 25 Feb 2023 05:43:30 -0600 Subject: [PATCH] Add Z-Wave Lock Commands and Fix ZMatter URL (#383) --- pyisy/constants.py | 1 + pyisy/nodes/node.py | 72 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/pyisy/constants.py b/pyisy/constants.py index 2dbba1d..5fae908 100644 --- a/pyisy/constants.py +++ b/pyisy/constants.py @@ -189,6 +189,7 @@ URL_VARIABLES = "vars" URL_ZWAVE = "zwave" URL_PROFILE_NS = "profiles/ns" +URL_ZMATTER_ZWAVE = "zmatter/zwave" VAR_INTEGER = "1" VAR_STATE = "2" diff --git a/pyisy/nodes/node.py b/pyisy/nodes/node.py index 5c99dd1..0b6ea99 100755 --- a/pyisy/nodes/node.py +++ b/pyisy/nodes/node.py @@ -11,6 +11,7 @@ CMD_MANUAL_DIM_BEGIN, CMD_MANUAL_DIM_STOP, CMD_SECURE, + FAMILY_ZMATTER_ZWAVE, INSTEON_SUBNODE_DIMMABLE, INSTEON_TYPE_DIMMABLE, INSTEON_TYPE_LOCK, @@ -37,6 +38,7 @@ URL_NODE, URL_NODES, URL_QUERY, + URL_ZMATTER_ZWAVE, URL_ZWAVE, ZWAVE_CAT_DIMMABLE, ZWAVE_CAT_LOCK, @@ -276,7 +278,16 @@ async def get_zwave_parameter(self, parameter): # parameter_xml = await self.isy.conn.request( self.isy.conn.compile_url( - [URL_ZWAVE, URL_NODE, self._id, URL_CONFIG, URL_QUERY, str(parameter)] + [ + URL_ZMATTER_ZWAVE + if self.family == FAMILY_ZMATTER_ZWAVE + else URL_ZWAVE, + URL_NODE, + self._id, + URL_CONFIG, + URL_QUERY, + str(parameter), + ] ) ) @@ -337,7 +348,7 @@ async def set_zwave_parameter(self, parameter, value, size): # /rest/zwave/node//config/set/// req_url = self.isy.conn.compile_url( [ - URL_ZWAVE, + URL_ZMATTER_ZWAVE if self.family == FAMILY_ZMATTER_ZWAVE else URL_ZWAVE, URL_NODE, self._id, URL_CONFIG, @@ -367,6 +378,63 @@ async def set_zwave_parameter(self, parameter, value, size): return True + async def set_zwave_lock_code(self, user_num: int, code: int) -> bool: + """Set a Z-Wave Lock User Code via the ISY.""" + if self.protocol != PROTO_ZWAVE: + raise TypeError("Cannot set parameters of non-Z-Wave device") + + # /rest/zwave/node//security/user//set/code/ + req_url = self.isy.conn.compile_url( + [ + URL_ZMATTER_ZWAVE if self.family == FAMILY_ZMATTER_ZWAVE else URL_ZWAVE, + URL_NODE, + self.address, + "security", + "user", + str(user_num), + "set/code", + str(code), + ] + ) + if not await self.isy.conn.request(req_url): + _LOGGER.warning( + "Could not set user code %s on %s.", + user_num, + self.address, + ) + return False + _LOGGER.debug("Set user code %s sent to %s.", user_num, self.address) + + return True + + async def delete_zwave_lock_code(self, user_num: int) -> bool: + """Delete a Z-Wave Lock User Code via the ISY.""" + if self.protocol != PROTO_ZWAVE: + raise TypeError("Cannot set parameters of non-Z-Wave device") + + # /rest/zwave/node//security/user//delete + req_url = self.isy.conn.compile_url( + [ + URL_ZMATTER_ZWAVE if self.family == FAMILY_ZMATTER_ZWAVE else URL_ZWAVE, + URL_NODE, + self.address, + "security", + "user", + str(user_num), + "delete", + ] + ) + if not await self.isy.conn.request(req_url): + _LOGGER.warning( + "Could not delete user code %s on %s.", + user_num, + self.address, + ) + return False + _LOGGER.debug("Deleted user code %s sent to %s.", user_num, self.address) + + return True + async def update(self, event=None, wait_time=0, xmldoc=None): """Update the value of the node from the controller.""" if not self.isy.auto_update and not xmldoc: