-
Notifications
You must be signed in to change notification settings - Fork 27
/
0004-Add-raw-attribute-callback.patch
105 lines (96 loc) · 4.95 KB
/
0004-Add-raw-attribute-callback.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From 475fdbd08f5b0e71c870dd602c59b2e80ebe47d4 Mon Sep 17 00:00:00 2001
From: Stefan Agner <[email protected]>
Date: Thu, 23 May 2024 12:48:54 +0200
Subject: [PATCH] Add raw attribute callback
Add new subscription callback which uses raw AttributePath as paths
of changed attributes. This allows to subscribe to custom clusters,
where no Cluster/Attribute types are part of the Python library.
Also allow to get the raw Python values (in tagged dict format)
directly from the subscription transaction.
---
.../python/chip/clusters/Attribute.py | 48 +++++++++++++++----
1 file changed, 38 insertions(+), 10 deletions(-)
diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py
index 0b51ce4bfc..2191e29d69 100644
--- a/src/controller/python/chip/clusters/Attribute.py
+++ b/src/controller/python/chip/clusters/Attribute.py
@@ -436,6 +436,7 @@ class SubscriptionTransaction:
int, int], None] = DefaultResubscriptionAttemptedCallback
self._onAttributeChangeCb: Callable[[
TypedAttributePath, SubscriptionTransaction], None] = DefaultAttributeChangeCallback
+ self._onRawAttributeChangeCb: Optional[Callable[[AttributePath, SubscriptionTransaction]]] = None
self._onEventChangeCb: Callable[[
EventReadResult, SubscriptionTransaction], None] = DefaultEventChangeCallback
self._onErrorCb: Callable[[
@@ -464,6 +465,18 @@ class SubscriptionTransaction:
else:
return data[path.Path.EndpointId][path.ClusterType][path.AttributeType]
+ def GetTLVAttributes(self) -> Dict[int, Dict[int, Dict[int, Any]]]:
+ '''Returns the attributes value cache in raw/tag dict value tracking
+ the latest state on the publisher.
+ '''
+ return self._readTransaction._cache.attributeTLVCache
+
+
+ def GetTLVAttribute(self, path: AttributePath) -> bytes:
+ '''Returns a specific attribute given a AttributePath.
+ '''
+ return self._readTransaction._cache.attributeTLVCache[path.EndpointId][path.ClusterId][path.AttributeId]
+
def GetEvents(self):
return self._readTransaction.GetAllEventValues()
@@ -546,8 +559,14 @@ class SubscriptionTransaction:
Sets the callback function for the attribute value change event,
accepts a Callable accepts an attribute path and the cached data.
'''
- if callback is not None:
- self._onAttributeChangeCb = callback
+ self._onAttributeChangeCb = callback
+
+ def SetRawAttributeUpdateCallback(self, callback: Callable[[AttributePath, SubscriptionTransaction], None]):
+ '''
+ Sets the callback function for raw attribute value change event,
+ accepts a Callable which accepts an attribute path and the cached data.
+ '''
+ self._onRawAttributeChangeCb = callback
def SetEventUpdateCallback(self, callback: Callable[[EventReadResult, SubscriptionTransaction], None]):
if callback is not None:
@@ -565,6 +584,10 @@ class SubscriptionTransaction:
def OnAttributeChangeCb(self) -> Callable[[TypedAttributePath, SubscriptionTransaction], None]:
return self._onAttributeChangeCb
+ @property
+ def OnRawAttributeChangeCb(self) -> Callable[[TypedAttributePath, SubscriptionTransaction], None]:
+ return self._onRawAttributeChangeCb
+
@property
def OnEventChangeCb(self) -> Callable[[EventReadResult, SubscriptionTransaction], None]:
return self._onEventChangeCb
@@ -781,14 +804,19 @@ class AsyncReadTransaction:
def _handleReportEnd(self):
if (self._subscription_handler is not None):
for change in self._changedPathSet:
- try:
- attribute_path = TypedAttributePath(Path=change)
- except (KeyError, ValueError) as err:
- # path could not be resolved into a TypedAttributePath
- LOGGER.exception(err)
- continue
- self._subscription_handler.OnAttributeChangeCb(
- attribute_path, self._subscription_handler)
+ if self._subscription_handler.OnAttributeChangeCb:
+ try:
+ attribute_path = TypedAttributePath(Path=change)
+ except (KeyError, ValueError) as err:
+ # path could not be resolved into a TypedAttributePath
+ LOGGER.exception(err)
+ continue
+ self._subscription_handler.OnAttributeChangeCb(
+ attribute_path, self._subscription_handler)
+
+ if self._subscription_handler.OnRawAttributeChangeCb:
+ self._subscription_handler.OnRawAttributeChangeCb(
+ change, self._subscription_handler)
# Clear it out once we've notified of all changes in this transaction.
self._changedPathSet = set()
--
2.47.0