From 4c01f0ccf85aa78213e1c56713d2f5e83f75d6db Mon Sep 17 00:00:00 2001 From: "Bacher, Dominik" Date: Mon, 10 Jul 2023 23:12:31 +0200 Subject: [PATCH] add identifier,name,role,ref_id,project_uid to group_addresse --- .../stubs/testprojekt-ets6-functions.json | 16 +++++++-- tox.ini | 34 ------------------- xknxproject/loader/project_loader.py | 19 ++++++++--- xknxproject/models/__init__.py | 4 +++ xknxproject/models/knxproject.py | 12 ++++++- xknxproject/models/models.py | 13 ++++++- xknxproject/xml/parser.py | 19 ++++++++++- 7 files changed, 73 insertions(+), 44 deletions(-) delete mode 100644 tox.ini diff --git a/test/resources/stubs/testprojekt-ets6-functions.json b/test/resources/stubs/testprojekt-ets6-functions.json index a1d8994..0a557d1 100644 --- a/test/resources/stubs/testprojekt-ets6-functions.json +++ b/test/resources/stubs/testprojekt-ets6-functions.json @@ -103,8 +103,20 @@ "function_type": "FT-1", "project_uid": 11, "group_addresses": [ - "P-05C0-0_GA-1", - "P-05C0-0_GA-2" + { + "identifier": "P-05C0-0_GF-1", + "name": "", + "role": "SwitchOnOff", + "ref_id": "P-05C0-0_GA-1", + "project_uid": 15 + }, + { + "identifier": "P-05C0-0_GF-2", + "name": "", + "role": "InfoOnOff", + "ref_id": "P-05C0-0_GA-2", + "project_uid": 17 + } ] } ] diff --git a/tox.ini b/tox.ini deleted file mode 100644 index be7e296..0000000 --- a/tox.ini +++ /dev/null @@ -1,34 +0,0 @@ -[tox] -envlist = py39, py310, py311, typing, lint, pylint -skip_missing_interpreters = True - -[testenv] -setenv = - PYTHONPATH = {toxinidir} -commands = - pytest --cov xknxproject --cov-report= {posargs} -deps = -rrequirements_testing.txt -package = wheel -wheel_build_env = .pkg - -[testenv:lint] -basepython = python3 -commands = - ruff check {posargs:.} - pre-commit run codespell {posargs: --all-files} - pre-commit run flake8 {posargs: --all-files} - pre-commit run pyupgrade {posargs: --all-files} - pre-commit run black {posargs: --all-files} - pre-commit run isort {posargs: --all-files} - pre-commit run check-json {posargs: --all-files} - pre-commit run trailing-whitespace {posargs: --all-files} - -[testenv:pylint] -basepython = python3 -commands = - pylint xknxproject - -[testenv:typing] -basepython = python3 -commands = - pre-commit run mypy {posargs: --all-files} diff --git a/xknxproject/loader/project_loader.py b/xknxproject/loader/project_loader.py index dc6fa2b..b5a3a10 100644 --- a/xknxproject/loader/project_loader.py +++ b/xknxproject/loader/project_loader.py @@ -10,6 +10,7 @@ SpaceType, XMLArea, XMLFunction, + XMLGroupAddressRef, XMLGroupAddress, XMLLine, XMLProjectInformation, @@ -292,13 +293,21 @@ def parse_functions(self, node: ElementTree.Element) -> XMLFunction: name=node.get("Name"), # type: ignore[arg-type] function_type=node.get("Type"), # type: ignore[arg-type] project_uid=int(project_uid) if project_uid else None, - group_addresses=[ - sub_node.get("RefId", "") - for sub_node in node - if sub_node.tag.endswith("GroupAddressRef") - ], + group_addresses=[], ) + for sub_node in node: + if sub_node.tag.endswith("GroupAddressRef"): + project_uid = sub_node.get("Puid") + group_address_ref: XMLGroupAddressRef = XMLGroupAddressRef( + identifier=sub_node.get("Id"), # type: ignore[arg-type] + name=sub_node.get("Name"), # type: ignore[arg-type] + role=sub_node.get("Role", ""), + ref_id=sub_node.get("RefId", ""), + project_uid=int(project_uid) if project_uid else None, + ) + functions.group_addresses.append(group_address_ref) + return functions diff --git a/xknxproject/models/__init__.py b/xknxproject/models/__init__.py index 9162df4..36fd951 100644 --- a/xknxproject/models/__init__.py +++ b/xknxproject/models/__init__.py @@ -7,6 +7,7 @@ Flags, Function, GroupAddress, + GroupAddressRef, KNXProject, Line, ProjectInfo, @@ -22,6 +23,7 @@ XMLArea, XMLFunction, XMLGroupAddress, + XMLGroupAddressRef, XMLLine, XMLProjectInformation, XMLSpace, @@ -40,6 +42,7 @@ "ProjectInfo", "Space", "Function", + "GroupAddressRef", "ComObject", "ComObjectInstanceRef", "ComObjectRef", @@ -51,6 +54,7 @@ "XMLLine", "XMLSpace", "XMLFunction", + "XMLGroupAddressRef", "XMLProjectInformation", "MEDIUM_TYPES", "SpaceType", diff --git a/xknxproject/models/knxproject.py b/xknxproject/models/knxproject.py index cdb8a71..c638e9b 100644 --- a/xknxproject/models/knxproject.py +++ b/xknxproject/models/knxproject.py @@ -102,7 +102,17 @@ class Function(TypedDict): name: str function_type: str project_uid: int | None - group_addresses: list[str] + group_addresses: list[GroupAddressRef] + + +class GroupAddressRef(TypedDict): + """GroupAddressRef typed dict.""" + + identifier: str + name: str + role: str + ref_id: str + project_uid: int | None class ProjectInfo(TypedDict): diff --git a/xknxproject/models/models.py b/xknxproject/models/models.py index fae7e2d..17a5a65 100644 --- a/xknxproject/models/models.py +++ b/xknxproject/models/models.py @@ -284,7 +284,18 @@ class XMLFunction: name: str function_type: str project_uid: int | None - group_addresses: list[str] + group_addresses: list[XMLGroupAddressRef] + + +@dataclass +class XMLGroupAddressRef: + """A GroupAddressRef in the functions XML.""" + + identifier: str + name: str + role: str + ref_id: str + project_uid: int | None @dataclass diff --git a/xknxproject/xml/parser.py b/xknxproject/xml/parser.py index 12ab9f6..c42c5bb 100644 --- a/xknxproject/xml/parser.py +++ b/xknxproject/xml/parser.py @@ -19,6 +19,7 @@ Flags, Function, GroupAddress, + GroupAddressRef, HardwareToPrograms, KNXProject, Line, @@ -28,6 +29,7 @@ XMLArea, XMLFunction, XMLGroupAddress, + XMLGroupAddressRef, XMLProjectInformation, XMLSpace, ) @@ -165,6 +167,21 @@ def parse(self, language: str | None = None) -> KNXProject: locations=space_dict, ) + def convert_group_address_ref( + self, group_address_ref: list[XMLGroupAddressRef] + ) -> list[GroupAddressRef]: + """Convert group address ref to the final output format.""" + return [ + GroupAddressRef( + identifier=g.identifier, + name=g.name, + role=g.role, + ref_id=g.ref_id, + project_uid=g.project_uid, + ) + for g in group_address_ref + ] + def convert_functions(self, functions: list[XMLFunction]) -> list[Function]: """Convert function to the final output format.""" return [ @@ -173,7 +190,7 @@ def convert_functions(self, functions: list[XMLFunction]) -> list[Function]: name=f.name, function_type=f.function_type, project_uid=f.project_uid, - group_addresses=f.group_addresses, + group_addresses=self.convert_group_address_ref(f.group_addresses), ) for f in functions ]