Skip to content

Commit 3a29da9

Browse files
authored
Merge pull request #98 from home-assistant-libs/release-backport-attribute-cache-improvements
Update Python controller bindings with Attribute cache improvements
2 parents 87eae96 + cd0ddab commit 3a29da9

3 files changed

+790
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From 3f6ba15267c08c8665edafd27043de6a6a3c60ee Mon Sep 17 00:00:00 2001
2+
From: Stefan Agner <stefan@agner.ch>
3+
Date: Wed, 4 Sep 2024 14:49:53 +0200
4+
Subject: [PATCH] [Python] Avoid InvalidStateError on cancel (#35380)
5+
6+
When the co-routine GetConnectedDevice() gets cancelled, the wait_for
7+
call will cancel the future we are waiting for. However, the SDK still
8+
calls the _DeviceAvailableCallback with an error (CHIP Error 0x00000074:
9+
The operation has been cancelled). However, we can't set the future
10+
result at this point as the co-routine is already cancelled.
11+
12+
Simply check the future state before setting the result.
13+
---
14+
src/controller/python/chip/ChipDeviceCtrl.py | 2 ++
15+
1 file changed, 2 insertions(+)
16+
17+
diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
18+
index 3ea996e53c..bb4119f1bc 100644
19+
--- a/src/controller/python/chip/ChipDeviceCtrl.py
20+
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
21+
@@ -854,6 +854,8 @@ class ChipDeviceControllerBase():
22+
self._future = future
23+
24+
def _deviceAvailable(self):
25+
+ if self._future.cancelled():
26+
+ return
27+
if self._returnDevice.value is not None:
28+
self._future.set_result(self._returnDevice)
29+
else:
30+
--
31+
2.46.0
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
From d586d15f83c5fb5fff30b7b7a91b0aced387aa5f Mon Sep 17 00:00:00 2001
2+
From: C Freeman <cecille@google.com>
3+
Date: Wed, 7 Aug 2024 23:05:32 -0400
4+
Subject: [PATCH] python: Add direct attribute paths to Read (#34833)
5+
6+
* python: Add direct attribute paths to Read
7+
8+
Supports one particular use case: read one or all endpoints,
9+
all clusters, specific (global) attribute. See spec 8.9.2.4. This
10+
is an allowed wildcard construct that is not currently expressable
11+
in the API.
12+
13+
Test: Used on wildcard read for matter_testing_support. This is
14+
therefore tested on any test using that decorator - switch
15+
and timesync.
16+
17+
* Restyled by isort
18+
19+
---------
20+
21+
Co-authored-by: Restyled.io <commits@restyled.io>
22+
---
23+
src/controller/python/chip/ChipDeviceCtrl.py | 18 +++++++++++++++---
24+
src/python_testing/matter_testing_support.py | 1 +
25+
2 files changed, 16 insertions(+), 3 deletions(-)
26+
27+
diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
28+
index bb4119f1bc..e337bb0c5d 100644
29+
--- a/src/controller/python/chip/ChipDeviceCtrl.py
30+
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
31+
@@ -1142,8 +1142,12 @@ class ChipDeviceControllerBase():
32+
# Wildcard attribute id
33+
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
34+
# Concrete path
35+
- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
36+
+ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
37+
+ # Directly specified attribute path
38+
+ ClusterAttribute.AttributePath
39+
]):
40+
+ if isinstance(pathTuple, ClusterAttribute.AttributePath):
41+
+ return pathTuple
42+
if pathTuple == ('*') or pathTuple == ():
43+
# Wildcard
44+
return ClusterAttribute.AttributePath()
45+
@@ -1228,7 +1232,9 @@ class ChipDeviceControllerBase():
46+
# Wildcard attribute id
47+
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
48+
# Concrete path
49+
- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
50+
+ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
51+
+ # Directly specified attribute path
52+
+ ClusterAttribute.AttributePath
53+
]] = None,
54+
dataVersionFilters: typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]] = None, events: typing.List[
55+
typing.Union[
56+
@@ -1266,6 +1272,8 @@ class ChipDeviceControllerBase():
57+
ReadAttribute(1, [ Clusters.BasicInformation ] ) -- case 5 above.
58+
ReadAttribute(1, [ (1, Clusters.BasicInformation.Attributes.Location ] ) -- case 1 above.
59+
60+
+ An AttributePath can also be specified directly by [chip.cluster.Attribute.AttributePath(...)]
61+
+
62+
dataVersionFilters: A list of tuples of (endpoint, cluster, data version).
63+
64+
events: A list of tuples of varying types depending on the type of read being requested:
65+
@@ -1326,7 +1334,9 @@ class ChipDeviceControllerBase():
66+
# Wildcard attribute id
67+
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
68+
# Concrete path
69+
- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
70+
+ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
71+
+ # Directly specified attribute path
72+
+ ClusterAttribute.AttributePath
73+
]], dataVersionFilters: typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]] = None,
74+
returnClusterObject: bool = False,
75+
reportInterval: typing.Tuple[int, int] = None,
76+
@@ -1350,6 +1360,8 @@ class ChipDeviceControllerBase():
77+
ReadAttribute(1, [ Clusters.BasicInformation ] ) -- case 5 above.
78+
ReadAttribute(1, [ (1, Clusters.BasicInformation.Attributes.Location ] ) -- case 1 above.
79+
80+
+ An AttributePath can also be specified directly by [chip.cluster.Attribute.AttributePath(...)]
81+
+
82+
returnClusterObject: This returns the data as consolidated cluster objects, with all attributes for a cluster inside
83+
a single cluster-wide cluster object.
84+
85+
diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py
86+
index a3bd5d2837..93a89192dc 100644
87+
--- a/src/python_testing/matter_testing_support.py
88+
+++ b/src/python_testing/matter_testing_support.py
89+
@@ -53,6 +53,7 @@ import chip.logging
90+
import chip.native
91+
from chip import discovery
92+
from chip.ChipStack import ChipStack
93+
+from chip.clusters import Attribute
94+
from chip.clusters import ClusterObjects as ClusterObjects
95+
from chip.clusters.Attribute import EventReadResult, SubscriptionTransaction
96+
from chip.exceptions import ChipStackError
97+
--
98+
2.46.0
99+

0 commit comments

Comments
 (0)