Skip to content

Commit

Permalink
[chip-tool] Add AnyCommands aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed May 23, 2023
1 parent 1efbaf6 commit 3beed99
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,80 @@
import json
import re

_ANY_COMMANDS_LIST = [
'ReadById',
'WriteById',
'SubscribeById',
'ReadEventById',
'SubscribeEventById',
'ReadAll',
'SubscribeAll',
]

_ALIASES = {
'AnyCommands': {
'alias': 'any',
'commands': {
'CommandById': {
'alias': 'command-by-id',
'arguments': {
'ClusterId': 'cluster-id',
'CommandId': 'command-id',
},
},
'ReadById': {
'alias': 'read-by-id',
'arguments': {
'ClusterId': 'cluster-ids',
'AttributeId': 'attribute-ids',
},
},
'WriteById': {
'alias': 'write-by-id',
'arguments': {
'ClusterId': 'cluster-ids',
'AttributeId': 'attribute-ids',
},
},
'SubscribeById': {
'alias': 'subscribe-by-id',
'arguments': {
'ClusterId': 'cluster-ids',
'AttributeId': 'attribute-ids',
},
},
'ReadEventById': {
'alias': 'read-event-by-id',
'arguments': {
'ClusterId': 'cluster-id',
'EventId': 'event-id',
},
},
'SubscribeEventById': {
'alias': 'subscribe-event-by-id',
'arguments': {
'ClusterId': 'cluster-id',
'EventId': 'event-id',
},
},
'ReadAll': {
'alias': 'read-all',
'arguments': {
'ClusterId': 'cluster-ids',
'AttributeId': 'attribute-ids',
'EventId': 'event-ids',
},
},
'SubscribeAll': {
'alias': 'subscribe-all',
'arguments': {
'ClusterId': 'cluster-ids',
'AttributeId': 'attribute-ids',
'EventId': 'event-ids',
},
},
}
},
'CommissionerCommands': {
'alias': 'pairing',
'commands': {
Expand Down Expand Up @@ -199,7 +272,7 @@ def __maybe_add_endpoint(self, rv, request):
endpoint_argument_name = 'endpoint-id-ignored-for-group-commands'
endpoint_argument_value = request.endpoint

if (request.is_attribute and not request.command == "writeAttribute") or request.is_event:
if (request.is_attribute and not request.command == "writeAttribute") or request.is_event or request.command in _ANY_COMMANDS_LIST:
endpoint_argument_name = 'endpoint-ids'

if rv:
Expand Down
16 changes: 14 additions & 2 deletions scripts/py_matter_yamltests/matter_yamltests/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
from .pics_checker import PICSChecker
from .yaml_loader import YamlLoader

ANY_COMMANDS_CLUSTER_NAME = 'AnyCommands'
ANY_COMMANDS_LIST = [
'CommandById',
'ReadById',
'WriteById',
'SubscribeById',
'ReadEventById',
'SubscribeEventById',
'ReadAll',
'SubscribeAll',
]


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

def _update_mappings(self, test: dict, definitions: SpecDefinitions):
cluster_name = self.cluster
if definitions is None or not definitions.has_cluster_by_name(cluster_name):
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:
self.argument_mapping = None
self.response_mapping = None
self.response_mapping_name = None
Expand Down Expand Up @@ -746,7 +758,7 @@ def _response_values_validation(self, expected_response, received_response, resu
break

received_value = received_response.get('value')
if not self.is_attribute and not self.is_event:
if not self.is_attribute and not self.is_event and not (self.command in ANY_COMMANDS_LIST):
expected_name = value.get('name')
if expected_name not in received_value:
result.error(check_type, error_name_does_not_exist.format(
Expand Down

0 comments on commit 3beed99

Please sign in to comment.