Skip to content

Commit

Permalink
add address to function group addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Bacher, Dominik committed Jul 12, 2023
1 parent ee74f76 commit 4b679d9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/resources/stubs/testprojekt-ets6-functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@
"name": "",
"role": "SwitchOnOff",
"ref_id": "P-05C0-0_GA-1",
"address": "0/0/1",
"project_uid": 15
},
{
"identifier": "P-05C0-0_GF-2",
"name": "",
"role": "InfoOnOff",
"ref_id": "P-05C0-0_GA-2",
"address": "0/0/2",
"project_uid": 17
}
]
Expand Down
13 changes: 11 additions & 2 deletions xknxproject/loader/project_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def load(
)

location_loader = _LocationLoader(
knx_proj_contents, devices, space_usage_names, function_type_names
knx_proj_contents, devices, space_usage_names,
function_type_names, group_address_list
)
for location_element in tree.findall(
f"{{*}}Project/{{*}}Installations/{{*}}Installation/{{*}}{element_name}"
Expand Down Expand Up @@ -239,6 +240,7 @@ def __init__(
devices: list[DeviceInstance],
space_usage_names: dict[str, str],
function_type_names: dict[str, str],
group_address_list: list[XMLGroupAddress],
):
"""Initialize the LocationLoader."""
self._element_name = (
Expand All @@ -249,6 +251,7 @@ def __init__(
}
self.space_usage_names = space_usage_names
self.function_type_names = function_type_names
self.group_address_list = group_address_list

def load(self, location_element: ElementTree.Element) -> list[XMLSpace]:
"""Load Location mappings."""
Expand Down Expand Up @@ -305,11 +308,17 @@ def parse_functions(self, node: ElementTree.Element) -> XMLFunction:
for sub_node in node:
if sub_node.tag.endswith("GroupAddressRef"):
project_uid = sub_node.get("Puid")
ref_id=sub_node.get("RefId", "")

id=ref_id.split('_')[1]
address=[g for g in self.group_address_list if g.identifier == id][0].address

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", ""),
ref_id=ref_id,
address=address,
project_uid=int(project_uid) if project_uid else None,
)
functions.group_addresses.append(group_address_ref)
Expand Down
1 change: 1 addition & 0 deletions xknxproject/models/knxproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class GroupAddressRef(TypedDict):
name: str
role: str
ref_id: str
address: str
project_uid: int | None


Expand Down
1 change: 1 addition & 0 deletions xknxproject/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class XMLGroupAddressRef:
name: str
role: str
ref_id: str
address: str
project_uid: int | None


Expand Down
1 change: 1 addition & 0 deletions xknxproject/xml/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def convert_group_address_ref(
name=g.name,
role=g.role,
ref_id=g.ref_id,
address=g.address,
project_uid=g.project_uid,
)
for g in group_address_ref
Expand Down

0 comments on commit 4b679d9

Please sign in to comment.