Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python controller bindings with Attribute cache improvements #98

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions 0036-Python-Avoid-InvalidStateError-on-cancel-35380.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From 3f6ba15267c08c8665edafd27043de6a6a3c60ee Mon Sep 17 00:00:00 2001
From: Stefan Agner <stefan@agner.ch>
Date: Wed, 4 Sep 2024 14:49:53 +0200
Subject: [PATCH] [Python] Avoid InvalidStateError on cancel (#35380)

When the co-routine GetConnectedDevice() gets cancelled, the wait_for
call will cancel the future we are waiting for. However, the SDK still
calls the _DeviceAvailableCallback with an error (CHIP Error 0x00000074:
The operation has been cancelled). However, we can't set the future
result at this point as the co-routine is already cancelled.

Simply check the future state before setting the result.
---
src/controller/python/chip/ChipDeviceCtrl.py | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
index 3ea996e53c..bb4119f1bc 100644
--- a/src/controller/python/chip/ChipDeviceCtrl.py
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
@@ -854,6 +854,8 @@ class ChipDeviceControllerBase():
self._future = future

def _deviceAvailable(self):
+ if self._future.cancelled():
+ return
if self._returnDevice.value is not None:
self._future.set_result(self._returnDevice)
else:
--
2.46.0

99 changes: 99 additions & 0 deletions 0037-python-Add-direct-attribute-paths-to-Read-34833.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
From d586d15f83c5fb5fff30b7b7a91b0aced387aa5f Mon Sep 17 00:00:00 2001
From: C Freeman <cecille@google.com>
Date: Wed, 7 Aug 2024 23:05:32 -0400
Subject: [PATCH] python: Add direct attribute paths to Read (#34833)

* python: Add direct attribute paths to Read

Supports one particular use case: read one or all endpoints,
all clusters, specific (global) attribute. See spec 8.9.2.4. This
is an allowed wildcard construct that is not currently expressable
in the API.

Test: Used on wildcard read for matter_testing_support. This is
therefore tested on any test using that decorator - switch
and timesync.

* Restyled by isort

---------

Co-authored-by: Restyled.io <commits@restyled.io>
---
src/controller/python/chip/ChipDeviceCtrl.py | 18 +++++++++++++++---
src/python_testing/matter_testing_support.py | 1 +
2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
index bb4119f1bc..e337bb0c5d 100644
--- a/src/controller/python/chip/ChipDeviceCtrl.py
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
@@ -1142,8 +1142,12 @@ class ChipDeviceControllerBase():
# Wildcard attribute id
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
# Concrete path
- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
+ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
+ # Directly specified attribute path
+ ClusterAttribute.AttributePath
]):
+ if isinstance(pathTuple, ClusterAttribute.AttributePath):
+ return pathTuple
if pathTuple == ('*') or pathTuple == ():
# Wildcard
return ClusterAttribute.AttributePath()
@@ -1228,7 +1232,9 @@ class ChipDeviceControllerBase():
# Wildcard attribute id
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
# Concrete path
- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
+ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
+ # Directly specified attribute path
+ ClusterAttribute.AttributePath
]] = None,
dataVersionFilters: typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]] = None, events: typing.List[
typing.Union[
@@ -1266,6 +1272,8 @@ class ChipDeviceControllerBase():
ReadAttribute(1, [ Clusters.BasicInformation ] ) -- case 5 above.
ReadAttribute(1, [ (1, Clusters.BasicInformation.Attributes.Location ] ) -- case 1 above.

+ An AttributePath can also be specified directly by [chip.cluster.Attribute.AttributePath(...)]
+
dataVersionFilters: A list of tuples of (endpoint, cluster, data version).

events: A list of tuples of varying types depending on the type of read being requested:
@@ -1326,7 +1334,9 @@ class ChipDeviceControllerBase():
# Wildcard attribute id
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
# Concrete path
- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
+ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
+ # Directly specified attribute path
+ ClusterAttribute.AttributePath
]], dataVersionFilters: typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]] = None,
returnClusterObject: bool = False,
reportInterval: typing.Tuple[int, int] = None,
@@ -1350,6 +1360,8 @@ class ChipDeviceControllerBase():
ReadAttribute(1, [ Clusters.BasicInformation ] ) -- case 5 above.
ReadAttribute(1, [ (1, Clusters.BasicInformation.Attributes.Location ] ) -- case 1 above.

+ An AttributePath can also be specified directly by [chip.cluster.Attribute.AttributePath(...)]
+
returnClusterObject: This returns the data as consolidated cluster objects, with all attributes for a cluster inside
a single cluster-wide cluster object.

diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py
index a3bd5d2837..93a89192dc 100644
--- a/src/python_testing/matter_testing_support.py
+++ b/src/python_testing/matter_testing_support.py
@@ -53,6 +53,7 @@ import chip.logging
import chip.native
from chip import discovery
from chip.ChipStack import ChipStack
+from chip.clusters import Attribute
from chip.clusters import ClusterObjects as ClusterObjects
from chip.clusters.Attribute import EventReadResult, SubscriptionTransaction
from chip.exceptions import ChipStackError
--
2.46.0

Loading