Skip to content

Commit

Permalink
Add Z-Wave Lock Commands and Fix ZMatter URL (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
shbatm authored Feb 25, 2023
1 parent 135abf3 commit 27c0829
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyisy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
72 changes: 70 additions & 2 deletions pyisy/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,6 +38,7 @@
URL_NODE,
URL_NODES,
URL_QUERY,
URL_ZMATTER_ZWAVE,
URL_ZWAVE,
ZWAVE_CAT_DIMMABLE,
ZWAVE_CAT_LOCK,
Expand Down Expand Up @@ -276,7 +278,16 @@ async def get_zwave_parameter(self, parameter):
# <config paramNum="2" size="1" value="80"/>
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),
]
)
)

Expand Down Expand Up @@ -337,7 +348,7 @@ async def set_zwave_parameter(self, parameter, value, size):
# /rest/zwave/node/<nodeAddress>/config/set/<parameterNumber>/<value>/<size>
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,
Expand Down Expand Up @@ -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/<nodeAddress>/security/user/<user_num>/set/code/<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/<nodeAddress>/security/user/<user_num>/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:
Expand Down

0 comments on commit 27c0829

Please sign in to comment.