Skip to content

Commit

Permalink
TC-DESC-2.2: Fix comparison when mfg label is in the list (project-ch…
Browse files Browse the repository at this point in the history
…ip#35849)

* TC-DESC-2.2: Fix comparison when mfg label is in the list

Unit tests included, also tested on an example app with mfg tags

* linter

* Restyled by isort

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
cecille and restyled-commits authored Oct 18, 2024
1 parent 1f4e81e commit 00bd828
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/python_testing/TestMatterTestingSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,14 @@ def test_tag_list_problems(self):
problems = find_tag_list_problems(roots, device_types, simple)
asserts.assert_equal(len(problems), 0, "Unexpected problems found in list")

# Tags with mfg tags
tag_mfg = Clusters.Descriptor.Structs.SemanticTagStruct(mfgCode=0xFFF1, label="test")
tag_label = Clusters.Descriptor.Structs.SemanticTagStruct(tag=1, label="test")
simple[1][Clusters.Descriptor][Clusters.Descriptor.Attributes.TagList] = [tag1, tag_mfg]
simple[2][Clusters.Descriptor][Clusters.Descriptor.Attributes.TagList] = [tag1, tag_label]
problems = find_tag_list_problems(roots, device_types, simple)
asserts.assert_equal(len(problems), 0, "Unexpected problems found in list")

def test_root_node_tag_list_functions(self):
# Example topology - see comment above for the layout.
# There are 4 direct children of root 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Any

import chip.clusters as Clusters
from chip.clusters.Types import Nullable


@dataclass
Expand Down Expand Up @@ -143,12 +144,16 @@ def create_device_type_list_for_root(direct_children, endpoint_dict: dict[int, A


def cmp_tag_list(a: Clusters.Descriptor.Structs.SemanticTagStruct, b: Clusters.Descriptor.Structs.SemanticTagStruct):
if type(a.mfgCode) != type(b.mfgCode):
return -1 if type(a.mfgCode) is Nullable else 1
if a.mfgCode != b.mfgCode:
return -1 if a.mfgCode < b.mfgCode else 1
if a.namespaceID != b.namespaceID:
return -1 if a.namespaceID < b.namespaceID else 1
if a.tag != b.tag:
return -1 if a.tag < b.tag else 1
if type(a.label) != type(b.label):
return -1 if type(a.label) is Nullable or a.label is None else 1
if a.label != b.label:
return -1 if a.label < b.label else 1
return 0
Expand Down

0 comments on commit 00bd828

Please sign in to comment.