Skip to content

Commit

Permalink
Hack examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_…
Browse files Browse the repository at this point in the history
…adapter/encoder.py so it does use the right argument names for darwin-framework-tool
  • Loading branch information
Vivien Nicolas authored and Vivien Nicolas committed Aug 31, 2023
1 parent 8af7b6d commit 8043733
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,22 @@ def run(self, specs, value, cluster_name: str, typename: str, array: bool):
)
del value[str(field_code)]

# darwin-framework-tool returns the field name but with a different casing than what
# the test suite expects.
# To not confuse the test suite, the field name is replaced by its field name
# equivalent from the spec and then removed.
wrong_casing_field_name = field_name[0].lower(
) + field_name[1:]
if field_name not in value and field_name[0].upper() == field_name[0] and wrong_casing_field_name in value:
value[field_name] = self.run(
specs,
value[wrong_casing_field_name],
cluster_name,
field_type,
field_array
)
del value[wrong_casing_field_name]

if specs.is_fabric_scoped(struct):
value[_FABRIC_INDEX_FIELD_NAME] = self.run(
specs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

import base64
import json
import os
import re
import sys

_ANY_COMMANDS_LIST = [
'ReadById',
Expand Down Expand Up @@ -208,6 +210,12 @@ class Encoder:
def __init__(self, specifications):
self.__specs = specifications

# This is not the best way to toggle this flag. But for now it prevents having
# to build a new adapter for the very small differences that exists...
is_darwin_framework_tool = os.path.basename(
sys.argv[0]) == 'darwinframeworktool.py'
self.__is_darwin_framework_tool = is_darwin_framework_tool

def encode(self, request):
cluster = self.__get_cluster_name(request)
command, command_specifier = self.__get_command_name(request)
Expand Down Expand Up @@ -305,7 +313,10 @@ def __maybe_add_destination(self, rv, request):
if not self._supports_destination(request):
return rv

destination_argument_name = 'destination-id'
if self.__is_darwin_framework_tool:
destination_argument_name = 'node-id'
else:
destination_argument_name = 'destination-id'
destination_argument_value = None

if request.group_id:
Expand Down Expand Up @@ -333,6 +344,9 @@ def __maybe_add_endpoint(self, rv, request):
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"):
endpoint_argument_name = 'endpoint-ids'

if self.__is_darwin_framework_tool:
endpoint_argument_name = 'endpoint-id'

if rv:
rv += ', '
rv += f'"{endpoint_argument_name}": "{endpoint_argument_value}"'
Expand Down Expand Up @@ -378,7 +392,10 @@ def __get_argument_name(self, request, entry):

if request.is_attribute:
if command_name == 'writeAttribute':
argument_name = 'attribute-values'
if self.__is_darwin_framework_tool:
argument_name = 'attr-value'
else:
argument_name = 'attribute-values'
else:
argument_name = 'value'

Expand Down

0 comments on commit 8043733

Please sign in to comment.