Skip to content

Commit 1177111

Browse files
vivien-applepull[bot]
authored andcommitted
[chip-tool] Add AnyCommands aliases (#26755)
1 parent 35f1755 commit 1177111

File tree

7 files changed

+769
-12
lines changed

7 files changed

+769
-12
lines changed

examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@ def __translate_names(self, payloads):
9595
# Raise an error since the other fields probably needs to be translated too.
9696
raise KeyError(f'Error: field "{key}" not supported')
9797

98-
if value is None and (key == _CLUSTER or key == _RESPONSE or key == _ATTRIBUTE or key == _EVENT):
98+
if value is None and (key == _CLUSTER or key == _RESPONSE or key == _ATTRIBUTE or key == _EVENT) and _ERROR not in payload:
9999
# If the definition for this cluster/command/attribute/event is missing, there is not
100100
# much we can do to convert the response to the proper format. It usually indicates that
101101
# the cluster definition is missing something. So we just raise an exception to tell the
102102
# user something is wrong and the cluster definition needs to be updated.
103+
# The only exception being when the definition can not be found but the returned payload
104+
# contains an error. It could be because the payload is for an unknown cluster/command/attribute/event
105+
# in which case we obviously don't have a definition for it.
103106
cluster_code = hex(payload[_CLUSTER_ID])
104107
if key == _CLUSTER:
105108
raise KeyError(

examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/encoder.py

+98-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,88 @@
1616
import json
1717
import re
1818

19+
_ANY_COMMANDS_LIST = [
20+
'ReadById',
21+
'WriteById',
22+
'SubscribeById',
23+
'ReadEventById',
24+
'SubscribeEventById',
25+
'ReadAll',
26+
'SubscribeAll',
27+
]
28+
29+
_ANY_COMMANDS_LIST_ARGUMENTS_WITH_WILDCARDS = [
30+
'ClusterId',
31+
'AttributeId',
32+
'EventId',
33+
]
34+
35+
1936
_ALIASES = {
37+
'AnyCommands': {
38+
'alias': 'any',
39+
'commands': {
40+
'CommandById': {
41+
'alias': 'command-by-id',
42+
'arguments': {
43+
'ClusterId': 'cluster-id',
44+
'CommandId': 'command-id',
45+
},
46+
},
47+
'ReadById': {
48+
'alias': 'read-by-id',
49+
'arguments': {
50+
'ClusterId': 'cluster-ids',
51+
'AttributeId': 'attribute-ids',
52+
},
53+
},
54+
'WriteById': {
55+
'alias': 'write-by-id',
56+
'arguments': {
57+
'ClusterId': 'cluster-ids',
58+
'AttributeId': 'attribute-ids',
59+
'Value': 'attribute-values'
60+
},
61+
},
62+
'SubscribeById': {
63+
'alias': 'subscribe-by-id',
64+
'arguments': {
65+
'ClusterId': 'cluster-ids',
66+
'AttributeId': 'attribute-ids',
67+
},
68+
},
69+
'ReadEventById': {
70+
'alias': 'read-event-by-id',
71+
'arguments': {
72+
'ClusterId': 'cluster-id',
73+
'EventId': 'event-id',
74+
},
75+
},
76+
'SubscribeEventById': {
77+
'alias': 'subscribe-event-by-id',
78+
'arguments': {
79+
'ClusterId': 'cluster-id',
80+
'EventId': 'event-id',
81+
},
82+
},
83+
'ReadAll': {
84+
'alias': 'read-all',
85+
'arguments': {
86+
'ClusterId': 'cluster-ids',
87+
'AttributeId': 'attribute-ids',
88+
'EventId': 'event-ids',
89+
},
90+
},
91+
'SubscribeAll': {
92+
'alias': 'subscribe-all',
93+
'arguments': {
94+
'ClusterId': 'cluster-ids',
95+
'AttributeId': 'attribute-ids',
96+
'EventId': 'event-ids',
97+
},
98+
},
99+
}
100+
},
20101
'CommissionerCommands': {
21102
'alias': 'pairing',
22103
'commands': {
@@ -199,7 +280,7 @@ def __maybe_add_endpoint(self, rv, request):
199280
endpoint_argument_name = 'endpoint-id-ignored-for-group-commands'
200281
endpoint_argument_value = request.endpoint
201282

202-
if (request.is_attribute and not request.command == "writeAttribute") or request.is_event:
283+
if (request.is_attribute and not request.command == "writeAttribute") or request.is_event or (request.command in _ANY_COMMANDS_LIST and not request.command == "WriteById"):
203284
endpoint_argument_name = 'endpoint-ids'
204285

205286
if rv:
@@ -213,7 +294,8 @@ def __maybe_add_command_arguments(self, rv, request):
213294

214295
for entry in request.arguments['values']:
215296
name = self.__get_argument_name(request, entry)
216-
value = self.__encode_value(entry['value'])
297+
value = self.__encode_value(
298+
request.command, entry.get('name'), entry['value'])
217299
if rv:
218300
rv += ', '
219301
rv += f'"{name}":{value}'
@@ -242,11 +324,24 @@ def __maybe_add(self, rv, value, name):
242324
rv += f'"{name}":"{value}"'
243325
return rv
244326

245-
def __encode_value(self, value):
327+
def __encode_value(self, command_name, argument_name, value):
328+
value = self.__encode_wildcards(command_name, argument_name, value)
246329
value = self.__encode_octet_strings(value)
247330
value = self.__lower_camel_case_member_fields(value)
248331
return self.__convert_to_json_string(value)
249332

333+
def __encode_wildcards(self, command_name, argument_name, value):
334+
if value != '*':
335+
return value
336+
337+
# maybe a wildcard
338+
if command_name in _ANY_COMMANDS_LIST and argument_name in _ANY_COMMANDS_LIST_ARGUMENTS_WITH_WILDCARDS:
339+
# translate * to wildcard constant
340+
return 0xFFFFFFFF
341+
342+
# return actual '*' as value ... not a wildcard-compatible argument
343+
return value
344+
250345
def __encode_octet_strings(self, value):
251346
if isinstance(value, list):
252347
value = [self.__encode_octet_strings(entry) for entry in value]

scripts/py_matter_yamltests/matter_yamltests/parser.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
from .pics_checker import PICSChecker
2525
from .yaml_loader import YamlLoader
2626

27+
ANY_COMMANDS_CLUSTER_NAME = 'AnyCommands'
28+
ANY_COMMANDS_LIST = [
29+
'CommandById',
30+
'ReadById',
31+
'WriteById',
32+
'SubscribeById',
33+
'ReadEventById',
34+
'SubscribeEventById',
35+
'ReadAll',
36+
'SubscribeAll',
37+
]
38+
2739

2840
class UnknownPathQualifierError(TestStepError):
2941
"""Raise when an attribute/command/event name is not found in the definitions."""
@@ -235,7 +247,7 @@ def __init__(self, test: dict, config: dict, definitions: SpecDefinitions, pics_
235247

236248
def _update_mappings(self, test: dict, definitions: SpecDefinitions):
237249
cluster_name = self.cluster
238-
if definitions is None or not definitions.has_cluster_by_name(cluster_name):
250+
if definitions is None or not definitions.has_cluster_by_name(cluster_name) or cluster_name == ANY_COMMANDS_CLUSTER_NAME or self.command in ANY_COMMANDS_LIST:
239251
self.argument_mapping = None
240252
self.response_mapping = None
241253
self.response_mapping_name = None
@@ -756,7 +768,7 @@ def _response_values_validation(self, expected_response, received_response, resu
756768
break
757769

758770
received_value = received_response.get('value')
759-
if not self.is_attribute and not self.is_event:
771+
if not self.is_attribute and not self.is_event and not (self.command in ANY_COMMANDS_LIST):
760772
expected_name = value.get('name')
761773
if expected_name not in received_value:
762774
result.error(check_type, error_name_does_not_exist.format(

scripts/tests/chiptest/__init__.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,16 @@ def _GetSlowTests() -> Set[str]:
128128

129129

130130
def _GetInDevelopmentTests() -> Set[str]:
131-
"""Tests that fail in YAML for some reason.
132-
133-
Currently this is empty and returns an empty set, but this is kept around in case
134-
there are tests that are a work in progress.
135-
"""
131+
"""Tests that fail in YAML for some reason."""
136132
return {
137133
"Test_AddNewFabricFromExistingFabric.yaml", # chip-repl does not support GetCommissionerRootCertificate and IssueNocChain command
138134
"TestEqualities.yaml", # chip-repl does not support pseudo-cluster commands that return a value
139135
"TestExampleCluster.yaml", # chip-repl does not load custom pseudo clusters
140136
"TestClientMonitoringCluster.yaml", # Client Monitoring Tests need a rework after the XML update
141-
"Test_TC_TIMESYNC_1_1.yaml" # Time sync SDK is not yet ready
137+
"Test_TC_TIMESYNC_1_1.yaml", # Time sync SDK is not yet ready
138+
"TestAttributesById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
139+
"TestCommandsById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
140+
"TestEventsById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
142141
}
143142

144143

0 commit comments

Comments
 (0)