1
- From 512ad9e0b236a4102a19924670f3be380a8dacfe Mon Sep 17 00:00:00 2001
2
- Message-ID: <512ad9e0b236a4102a19924670f3be380a8dacfe.1716462300 .git.stefan@agner.ch>
1
+ From 9bc05af1e1ef2ec93336dc0eecba16b6802b6fb1 Mon Sep 17 00:00:00 2001
2
+ Message-ID: <9bc05af1e1ef2ec93336dc0eecba16b6802b6fb1.1716466458 .git.stefan@agner.ch>
3
3
From: Stefan Agner <stefan@agner.ch>
4
4
Date: Thu, 23 May 2024 12:48:54 +0200
5
- Subject: [PATCH] [Python] Add untyped attribute callback
5
+ Subject: [PATCH] [Python] Add raw attribute callback
6
6
7
- Add new subscription callback which returns the untyped paths of
8
- attributes changed. This allows to subscribe to custom clusters, where
9
- the type is not part of the Cluster/Attribute types are not part of
10
- the Python library.
7
+ Add new subscription callback which uses raw AttributePath as paths
8
+ of changed attributes. This allows to subscribe to custom clusters,
9
+ where no Cluster/Attribute types are part of the Python library.
11
10
12
- Also allow t get the raw value (in tagged dict format for structs )
13
- directly from the read transaction.
11
+ Also allow to get the raw Python values (in tagged dict format)
12
+ directly from the subscription transaction.
14
13
---
15
14
.../python/chip/clusters/Attribute.py | 48 +++++++++++++++----
16
15
1 file changed, 38 insertions(+), 10 deletions(-)
17
16
18
17
diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py
19
- index 9e46eed469..2d7196c0c2 100644
18
+ index 9e46eed469..ce522bf452 100644
20
19
--- a/src/controller/python/chip/clusters/Attribute.py
21
20
+++ b/src/controller/python/chip/clusters/Attribute.py
22
21
@@ -466,6 +466,7 @@ class SubscriptionTransaction:
23
22
def __init__(self, transaction: AsyncReadTransaction, subscriptionId, devCtrl):
24
23
self._onResubscriptionAttemptedCb = DefaultResubscriptionAttemptedCallback
25
24
self._onAttributeChangeCb = DefaultAttributeChangeCallback
26
- + self._onUntypedAttributeChangeCb = None
25
+ + self._onRawAttributeChangeCb = None
27
26
self._onEventChangeCb = DefaultEventChangeCallback
28
27
self._onErrorCb = DefaultErrorCallback
29
28
self._readTransaction = transaction
@@ -54,12 +53,12 @@ index 9e46eed469..2d7196c0c2 100644
54
53
- self._onAttributeChangeCb = callback
55
54
+ self._onAttributeChangeCb = callback
56
55
+
57
- + def SetUntypedAttributeUpdateCallback (self, callback: Callable[[AttributePath, SubscriptionTransaction], None]):
56
+ + def SetRawAttributeUpdateCallback (self, callback: Callable[[AttributePath, SubscriptionTransaction], None]):
58
57
+ '''
59
- + Sets the callback function for untyped attribute value change event,
60
- + accepts a Callable accepts a raw attribute path and the cached data.
58
+ + Sets the callback function for raw attribute value change event,
59
+ + accepts a Callable which accepts an attribute path and the cached data.
61
60
+ '''
62
- + self._onUntypedAttributeChangeCb = callback
61
+ + self._onRawAttributeChangeCb = callback
63
62
64
63
def SetEventUpdateCallback(self, callback: Callable[[EventReadResult, SubscriptionTransaction], None]):
65
64
if callback is not None:
@@ -68,8 +67,8 @@ index 9e46eed469..2d7196c0c2 100644
68
67
return self._onAttributeChangeCb
69
68
70
69
+ @property
71
- + def OnUntypedAttributeChangeCb (self) -> Callable[[TypedAttributePath, SubscriptionTransaction], None]:
72
- + return self._onUntypedAttributeChangeCb
70
+ + def OnRawAttributeChangeCb (self) -> Callable[[TypedAttributePath, SubscriptionTransaction], None]:
71
+ + return self._onRawAttributeChangeCb
73
72
+
74
73
@property
75
74
def OnEventChangeCb(self) -> Callable[[EventReadResult, SubscriptionTransaction], None]:
@@ -96,8 +95,8 @@ index 9e46eed469..2d7196c0c2 100644
96
95
+ self._subscription_handler.OnAttributeChangeCb(
97
96
+ attribute_path, self._subscription_handler)
98
97
+
99
- + if self._subscription_handler.OnUntypedAttributeChangeCb :
100
- + self._subscription_handler.OnUntypedAttributeChangeCb (
98
+ + if self._subscription_handler.OnRawAttributeChangeCb :
99
+ + self._subscription_handler.OnRawAttributeChangeCb (
101
100
+ change, self._subscription_handler)
102
101
103
102
# Clear it out once we've notified of all changes in this transaction.
0 commit comments