Skip to content

Commit

Permalink
add identifier,name,role,ref_id,project_uid to group_addresse
Browse files Browse the repository at this point in the history
  • Loading branch information
Bacher, Dominik committed Jul 10, 2023
1 parent 219934f commit 4c01f0c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 44 deletions.
16 changes: 14 additions & 2 deletions test/resources/stubs/testprojekt-ets6-functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
Expand Down
34 changes: 0 additions & 34 deletions tox.ini

This file was deleted.

19 changes: 14 additions & 5 deletions xknxproject/loader/project_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SpaceType,
XMLArea,
XMLFunction,
XMLGroupAddressRef,
XMLGroupAddress,
XMLLine,
XMLProjectInformation,
Expand Down Expand Up @@ -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


Expand Down
4 changes: 4 additions & 0 deletions xknxproject/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Flags,
Function,
GroupAddress,
GroupAddressRef,
KNXProject,
Line,
ProjectInfo,
Expand All @@ -22,6 +23,7 @@
XMLArea,
XMLFunction,
XMLGroupAddress,
XMLGroupAddressRef,
XMLLine,
XMLProjectInformation,
XMLSpace,
Expand All @@ -40,6 +42,7 @@
"ProjectInfo",
"Space",
"Function",
"GroupAddressRef",
"ComObject",
"ComObjectInstanceRef",
"ComObjectRef",
Expand All @@ -51,6 +54,7 @@
"XMLLine",
"XMLSpace",
"XMLFunction",
"XMLGroupAddressRef",
"XMLProjectInformation",
"MEDIUM_TYPES",
"SpaceType",
Expand Down
12 changes: 11 additions & 1 deletion xknxproject/models/knxproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 12 additions & 1 deletion xknxproject/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion xknxproject/xml/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Flags,
Function,
GroupAddress,
GroupAddressRef,
HardwareToPrograms,
KNXProject,
Line,
Expand All @@ -28,6 +29,7 @@
XMLArea,
XMLFunction,
XMLGroupAddress,
XMLGroupAddressRef,
XMLProjectInformation,
XMLSpace,
)
Expand Down Expand Up @@ -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 [
Expand All @@ -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
]
Expand Down

0 comments on commit 4c01f0c

Please sign in to comment.