Skip to content

Commit

Permalink
Add support for receiving progress report events (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
shbatm authored Jan 16, 2023
1 parent 11b6d09 commit 5c34a2c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pyisy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@
NC_PARENT_CHANGED = "PC"
NC_PENDING_DEVICE_OP = "WH"
NC_PROGRAMMING_DEVICE = "WD"
DEV_WRITING = "_7A"
DEV_MEMORY = "_7M"

# Node Change Code: (Description, EventInfo Tags)
NODE_CHANGED_ACTIONS = {
Expand All @@ -962,6 +964,8 @@
NC_PARENT_CHANGED: ("Parent Changed", ["node", "nodeType", "parent", "parentType"]),
NC_PENDING_DEVICE_OP: ("Pending Device Operation", []),
NC_PROGRAMMING_DEVICE: ("Programming Device", []),
DEV_WRITING: ("Progress Report", ["message"]),
DEV_MEMORY: ("Memory Write", ["memory", "cmd1", "cmd2", "value"]),
}

SYSTEM_NOT_BUSY = "0"
Expand Down Expand Up @@ -989,6 +993,11 @@
NODE_TO_DELETE = 0x40 # has to be deleted later
NODE_IS_DEVICE_ROOT = 0x80 # root device such as KPL load

DEV_CMD_MEMORY_WRITE = "0x2E"
DEV_BL_ADDR = "0x0264"
DEV_OL_ADDR = "0x0032"
DEV_RR_ADDR = "0x0021"

BACKLIGHT_SUPPORT = {
"DimmerMotorSwitch": UOM_PERCENTAGE,
"DimmerMotorSwitch_ADV": UOM_PERCENTAGE,
Expand Down
2 changes: 2 additions & 0 deletions pyisy/events/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ async def _route_message(self, msg):
self.isy.nodes.node_changed_received(xmldoc)
elif cntrl == "_5": # System Status Changed
self.isy.system_status_changed_received(xmldoc)
elif cntrl == "_7": # Progress report, device programming event
self.isy.nodes.progress_report_received(xmldoc)

def update_received(self, xmldoc):
"""Set the socket ID."""
Expand Down
35 changes: 35 additions & 0 deletions pyisy/nodes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Representation of ISY Nodes."""
from asyncio import sleep
from dataclasses import dataclass
import re
from xml.dom import minidom

from ..constants import (
Expand All @@ -14,6 +15,8 @@
ATTR_UNIT_OF_MEASURE,
DEFAULT_PRECISION,
DEFAULT_UNIT_OF_MEASURE,
DEV_MEMORY,
DEV_WRITING,
EVENT_PROPS_IGNORED,
FAMILY_BRULTECH,
FAMILY_NODESERVER,
Expand Down Expand Up @@ -67,6 +70,11 @@
from .group import Group
from .node import Node

MEMORY_REGEX = (
r".*dbAddr=(?P<dbAddr>[A-F0-9x]*) \[(?P<value>[A-F0-9]{2})\] "
r"cmd1=(?P<cmd1>[A-F0-9x]{4}) cmd2=(?P<cmd2>[A-F0-9x]{4})"
)


class Nodes:
"""
Expand Down Expand Up @@ -313,6 +321,33 @@ def node_changed_received(self, xmldoc):
)
# FUTURE: Handle additional node change actions to force updates.

def progress_report_received(self, xmldoc: minidom.Element) -> None:
"""Handle Progress Report '_7' events from an event stream message."""
event_info = value_from_xml(xmldoc, TAG_EVENT_INFO)
address, _, message = event_info.partition("]")
address = address.strip("[ ")
message = message.strip()
action = DEV_WRITING
detail = {"message": message}

if address != "All" and message.startswith("Memory"):
action = DEV_MEMORY
regex = re.compile(MEMORY_REGEX)
if event := regex.search(event_info):
detail = {
"memory": event.group("dbAddr"),
"cmd1": event.group("cmd1"),
"cmd2": event.group("cmd2"),
"value": int(event.group("value"), 16),
}
self.status_events.notify(event=NodeChangedEvent(address, action, detail))
_LOGGER.debug(
"ISY received a progress report %s event for node %s %s",
action,
address,
detail if detail else "",
)

def parse(self, xml):
"""
Parse the xml data.
Expand Down

0 comments on commit 5c34a2c

Please sign in to comment.