@@ -76,6 +76,7 @@ def __str__(self):
76
76
77
77
@dataclass
78
78
class XmlCommand :
79
+ id : int
79
80
name : str
80
81
conformance : Callable [[uint ], ConformanceDecision ]
81
82
@@ -100,6 +101,7 @@ class XmlCluster:
100
101
attributes : dict [uint , XmlAttribute ]
101
102
accepted_commands : dict [uint , XmlCommand ]
102
103
generated_commands : dict [uint , XmlCommand ]
104
+ unknown_commands : list [XmlCommand ]
103
105
events : dict [uint , XmlEvent ]
104
106
pics : str
105
107
@@ -346,27 +348,37 @@ def parse_attributes(self) -> dict[uint, XmlAttribute]:
346
348
), read_access = Clusters .AccessControl .Enums .AccessControlEntryPrivilegeEnum .kView , write_access = Clusters .AccessControl .Enums .AccessControlEntryPrivilegeEnum .kUnknownEnumValue , write_optional = False )
347
349
return attributes
348
350
349
- def parse_commands (self , command_type : CommandType ) -> dict [uint , XmlAttribute ]:
350
- commands = {}
351
+ def get_command_direction (self , element : ElementTree .Element ) -> CommandType :
352
+ try :
353
+ if element .attrib ['direction' ].lower () == 'responsefromserver' :
354
+ return CommandType .GENERATED
355
+ if element .attrib ['direction' ].lower () == 'commandtoclient' :
356
+ return CommandType .UNKNOWN
357
+ except KeyError :
358
+ return CommandType .ACCEPTED
359
+
360
+ def parse_unknown_commands (self ) -> list [XmlCommand ]:
361
+ commands = []
351
362
for element , conformance_xml , access_xml in self .command_elements :
363
+ if self .get_command_direction (element ) != CommandType .UNKNOWN :
364
+ continue
352
365
code = int (element .attrib ['id' ], 0 )
353
- dir = CommandType .ACCEPTED
354
- try :
355
- if element .attrib ['direction' ].lower () == 'responsefromserver' :
356
- dir = CommandType .GENERATED
357
- if element .attrib ['direction' ].lower () == 'commandtoclient' :
358
- dir = CommandType .UNKNOWN
359
- except KeyError :
360
- pass
361
- if dir != command_type :
366
+ conformance = self .parse_conformance (conformance_xml )
367
+ commands .append (XmlCommand (id = code , name = element .attrib ['name' ], conformance = conformance ))
368
+ return commands
369
+
370
+ def parse_commands (self , command_type : CommandType ) -> dict [uint , XmlCommand ]:
371
+ commands = {}
372
+ for element , conformance_xml , access_xml in self .command_elements :
373
+ if self .get_command_direction (element ) != command_type :
362
374
continue
363
375
code = int (element .attrib ['id' ], 0 )
364
376
conformance = self .parse_conformance (conformance_xml )
365
377
if conformance is None :
366
378
continue
367
379
if code in commands :
368
380
conformance = or_operation ([conformance , commands [code ].conformance ])
369
- commands [code ] = XmlCommand (name = element .attrib ['name' ], conformance = conformance )
381
+ commands [code ] = XmlCommand (id = code , name = element .attrib ['name' ], conformance = conformance )
370
382
return commands
371
383
372
384
def parse_events (self ) -> dict [uint , XmlAttribute ]:
@@ -393,6 +405,7 @@ def create_cluster(self) -> XmlCluster:
393
405
attributes = self .parse_attributes (),
394
406
accepted_commands = self .parse_commands (CommandType .ACCEPTED ),
395
407
generated_commands = self .parse_commands (CommandType .GENERATED ),
408
+ unknown_commands = self .parse_unknown_commands (),
396
409
events = self .parse_events (), pics = self ._pics )
397
410
398
411
def get_problems (self ) -> list [ProblemNotice ]:
@@ -423,6 +436,13 @@ def add_cluster_data_from_xml(xml: ElementTree.Element, clusters: dict[int, XmlC
423
436
derived_clusters [name ] = new
424
437
425
438
439
+ def check_clusters_for_unknown_commands (clusters : dict [int , XmlCluster ], problems : list [ProblemNotice ]):
440
+ for id , cluster in clusters .items ():
441
+ for cmd in cluster .unknown_commands :
442
+ problems .append (ProblemNotice (test_name = "Spec XML parsing" , location = CommandPathLocation (
443
+ endpoint_id = 0 , cluster_id = id , command_id = cmd .id ), severity = ProblemSeverity .WARNING , problem = "Command with unknown direction" ))
444
+
445
+
426
446
def build_xml_clusters () -> tuple [list [XmlCluster ], list [ProblemNotice ]]:
427
447
dir = os .path .join (os .path .dirname (os .path .realpath (__file__ )), '..' , '..' , 'data_model' , 'clusters' )
428
448
clusters : dict [int , XmlCluster ] = {}
@@ -489,6 +509,8 @@ def remove_problem(location: typing.Union[CommandPathLocation, FeaturePathLocati
489
509
clusters [acl_id ].attributes [Clusters .AccessControl .Attributes .Acl .attribute_id ].write_access = Clusters .AccessControl .Enums .AccessControlEntryPrivilegeEnum .kAdminister
490
510
clusters [acl_id ].attributes [Clusters .AccessControl .Attributes .Extension .attribute_id ].write_access = Clusters .AccessControl .Enums .AccessControlEntryPrivilegeEnum .kAdminister
491
511
512
+ check_clusters_for_unknown_commands (clusters , problems )
513
+
492
514
return clusters , problems
493
515
494
516
@@ -522,7 +544,6 @@ def combine_attributes(base: dict[uint, XmlAttribute], derived: dict[uint, XmlAt
522
544
for id , c in xml_clusters .items ():
523
545
if c .derived :
524
546
base_name = c .derived
525
- print (f"fixing cluster { base_name } " )
526
547
if base_name in ids_by_name :
527
548
base = xml_clusters [ids_by_name [c .derived ]]
528
549
else :
@@ -543,9 +564,17 @@ def combine_attributes(base: dict[uint, XmlAttribute], derived: dict[uint, XmlAt
543
564
generated_commands .update (c .generated_commands )
544
565
events = deepcopy (base .events )
545
566
events .update (c .events )
567
+ unknown_commands = deepcopy (base .unknown_commands )
568
+ for cmd in c .unknown_commands :
569
+ if cmd .id in accepted_commands .keys () and cmd .name == accepted_commands [cmd .id ].name :
570
+ accepted_commands [cmd .id ].conformance = cmd .conformance
571
+ elif cmd .id in generated_commands .keys () and cmd .name == generated_commands [cmd .id ].name :
572
+ generated_commands [cmd .id ].conformance = cmd .conformance
573
+ else :
574
+ unknown_commands .append (cmd )
575
+
546
576
new = XmlCluster (revision = c .revision , derived = c .derived , name = c .name ,
547
577
feature_map = feature_map , attribute_map = attribute_map , command_map = command_map ,
548
578
features = features , attributes = attributes , accepted_commands = accepted_commands ,
549
- generated_commands = generated_commands , events = events , pics = c .pics )
550
- print (new )
579
+ generated_commands = generated_commands , unknown_commands = unknown_commands , events = events , pics = c .pics )
551
580
xml_clusters [id ] = new
0 commit comments