16
16
import json
17
17
import re
18
18
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
+
19
36
_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
+ },
20
101
'CommissionerCommands' : {
21
102
'alias' : 'pairing' ,
22
103
'commands' : {
@@ -199,7 +280,7 @@ def __maybe_add_endpoint(self, rv, request):
199
280
endpoint_argument_name = 'endpoint-id-ignored-for-group-commands'
200
281
endpoint_argument_value = request .endpoint
201
282
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" ) :
203
284
endpoint_argument_name = 'endpoint-ids'
204
285
205
286
if rv :
@@ -213,7 +294,8 @@ def __maybe_add_command_arguments(self, rv, request):
213
294
214
295
for entry in request .arguments ['values' ]:
215
296
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' ])
217
299
if rv :
218
300
rv += ', '
219
301
rv += f'"{ name } ":{ value } '
@@ -242,11 +324,24 @@ def __maybe_add(self, rv, value, name):
242
324
rv += f'"{ name } ":"{ value } "'
243
325
return rv
244
326
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 )
246
329
value = self .__encode_octet_strings (value )
247
330
value = self .__lower_camel_case_member_fields (value )
248
331
return self .__convert_to_json_string (value )
249
332
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
+
250
345
def __encode_octet_strings (self , value ):
251
346
if isinstance (value , list ):
252
347
value = [self .__encode_octet_strings (entry ) for entry in value ]
0 commit comments