From 25d93a1cfdb40268fcb66bf4f0e452268549376d Mon Sep 17 00:00:00 2001 From: shbatm Date: Fri, 24 Feb 2023 12:49:15 -0600 Subject: [PATCH] Add Z-Wave lock code functions (#11) --- pyisyox/nodes/node.py | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/pyisyox/nodes/node.py b/pyisyox/nodes/node.py index 582563c..d34c521 100755 --- a/pyisyox/nodes/node.py +++ b/pyisyox/nodes/node.py @@ -411,6 +411,66 @@ async def set_zwave_parameter( 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 != Protocol.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.detail.family == NodeFamily.ZMATTER_ZWAVE + else URL_ZWAVE, + URL_NODE, + self.address, + "security", + "user", + str(user_num), + 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 != Protocol.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.detail.family == NodeFamily.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 + def get_command_value(self, uom: str, cmd: str) -> str | None: """Check against the list of UOM States if this is a valid command.""" if cmd not in UOM_TO_STATES[uom].values():