Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse AdditionalAddresses #204

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions xknxproject/loader/project_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ def _create_device(
for sub_node in device_element:
if sub_node.tag.endswith("AdditionalAddresses"):
for address_node in sub_node:
if _address := address_node.get("Address"):
device.additional_addresses.append(_address)
device.add_additional_address(
device_address=address_node.get("Address"), # type: ignore[arg-type]
description=address_node.get("Description", ""),
name=address_node.get("Name"),
)
if sub_node.tag.endswith("ComObjectInstanceRefs"):
for com_object in sub_node:
if instance := _TopologyLoader._create_com_object_instance(
Expand Down
24 changes: 20 additions & 4 deletions xknxproject/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def __init__(
hardware_program_ref: str,
line: XMLLine,
manufacturer: str,
additional_addresses: list[str] | None = None,
com_object_instance_refs: list[ComObjectInstanceRef] | None = None,
com_objects: list[ComObject] | None = None,
):
Expand All @@ -97,7 +96,7 @@ def __init__(
self.hardware_program_ref = hardware_program_ref
self.line = line
self.manufacturer = manufacturer
self.additional_addresses = additional_addresses or []
self.additional_addresses: list[AdditionalAddress] = []
self.com_object_instance_refs = com_object_instance_refs or []
self.com_objects = com_objects or []
self.application_program_ref: str | None = None
Expand All @@ -109,17 +108,34 @@ def __init__(
self.hardware_name: str = ""
self.manufacturer_name: str = ""

def add_additional_address(self, address: str) -> None:
def add_additional_address(
self, device_address: str, description: str, name: str | None
) -> None:
"""Add an additional individual address."""
self.additional_addresses.append(
f"{self.line.area.address}/{self.line.address}/{address}"
AdditionalAddress(
address=f"{self.line.area.address}.{self.line.address}.{device_address}",
description=description,
name=name,
)
)

def application_program_xml(self) -> str:
"""Obtain the file name to the application program XML."""
return f"{self.manufacturer}/{self.application_program_ref}.xml"


@dataclass
class AdditionalAddress:
"""Class that represents an additional address of IP interfaces."""

address: str
description: str # default: ""
# TODO: IP Secure interfaces use `BusInterface` to transport name and
# leave this an empty string. I don't know how `AddressIndex` relates.
name: str | None


@dataclass
class ComObjectInstanceRef:
"""Class that represents a ComObjectInstanceRef instance."""
Expand Down