Description
I am trying to get websocket updates for attribute changes that happen on a node that I am following.
client.py
's MatterClient offers this function:
def subscribe_events(
self,
callback: Callable[[EventType, Any], None],
event_filter: Optional[EventType] = None,
node_filter: Optional[int] = None,
attr_path_filter: Optional[str] = None,
) -> Callable[[], None]:
The issue arises as the callback is only provided with the EventType and the actual value changed. If I were to use the node filter on node 3, I would receive value updates without the knowledge of which attribute's value is changing.
However, in the underlying handling of event updates _handle_event_message
, the necessary context is available yet stripped.
if msg.event == EventType.ATTRIBUTE_UPDATED:
# data is tuple[node_id, attribute_path, new_value]
node_id, attribute_path, new_value = msg.data # <== All necessary context is available
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
"Attribute updated: Node: %s - Attribute: %s - New value: %s",
node_id,
attribute_path,
new_value,
)
self._nodes[node_id].update_attribute(attribute_path, new_value)
self._signal_event(
EventType.ATTRIBUTE_UPDATED,
data=new_value, # <== context is stripped from the tuple and only the value is returned for callback
node_id=node_id,
attribute_path=attribute_path,
)
return
The alternative would be manually looping through each node's attribute in order to get all updates for that node. Please let me know if there is a better way of doing what I am trying to accomplish, or if this function can be modified to include the necessary context.