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 a88d3da
Showing 1 changed file with 19 additions and 2 deletions.
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 a88d3da

Please sign in to comment.