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

Translate functions "usage_text" #262

Merged
merged 2 commits into from
Jul 31, 2023
Merged
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
1 change: 1 addition & 0 deletions script/refresh_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
("module-definition-test", "test", "de-DE"),
("xknx_test_project", "test", None),
("test_project-ets4", "test", "de-DE"),
("testprojekt-ets6-functions", None, "de-DE"),
]

for file_name, password, language in file_names:
Expand Down
4 changes: 2 additions & 2 deletions test/resources/stubs/module-definition-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"created_by": "ETS5",
"schema_version": "20",
"tool_version": "5.7.1428.39779",
"xknxproject_version": "3.0.0",
"xknxproject_version": "3.2.0",
"language_code": "de-DE"
},
"communication_objects": {
Expand Down Expand Up @@ -388,4 +388,4 @@
}
},
"functions": {}
}
}
4 changes: 2 additions & 2 deletions test/resources/stubs/test_project-ets4.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"created_by": "ETS4",
"schema_version": "11",
"tool_version": "ETS 4.2.0 (Build 3884)",
"xknxproject_version": "3.1.1",
"xknxproject_version": "3.2.0",
"language_code": "de-DE"
},
"communication_objects": {
Expand Down Expand Up @@ -313,4 +313,4 @@
}
},
"functions": {}
}
}
238 changes: 119 additions & 119 deletions test/resources/stubs/testprojekt-ets6-functions.json
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
{
"info": {
"project_id": "P-05C0",
"name": "Minimal-Example",
"last_modified": "2023-07-07T12:41:11.4132414Z",
"group_address_style": "ThreeLevel",
"guid": "efabc0f9-4e81-440d-a236-b80913e85730",
"created_by": "ETS6",
"schema_version": "22",
"tool_version": "6.1.5686.0",
"xknxproject_version": "3.2.0",
"language_code": "de-DE"
"info": {
"project_id": "P-05C0",
"name": "Minimal-Example",
"last_modified": "2023-07-07T12:41:11.4132414Z",
"group_address_style": "ThreeLevel",
"guid": "efabc0f9-4e81-440d-a236-b80913e85730",
"created_by": "ETS6",
"schema_version": "22",
"tool_version": "6.1.5686.0",
"xknxproject_version": "3.2.0",
"language_code": "de-DE"
},
"communication_objects": {},
"topology": {
"0": {
"name": "",
"description": null,
"lines": {
"0": {
"name": "",
"description": null,
"devices": [],
"medium_type": "KNXnet/IP (IP)"
}
}
},
"communication_objects": {},
"topology": {
"1": {
"name": "",
"description": null,
"lines": {
"0": {
"name": "",
"description": null,
"lines": {
"0": {
"name": "",
"description": null,
"devices": [],
"medium_type": "KNXnet/IP (IP)"
}
}
"name": "",
"description": null,
"devices": [],
"medium_type": "KNXnet/IP (IP)"
},
"1": {
"name": "",
"description": null,
"lines": {
"0": {
"name": "",
"description": null,
"devices": [],
"medium_type": "KNXnet/IP (IP)"
},
"1": {
"name": "",
"description": null,
"devices": [],
"medium_type": "Twisted Pair (TP)"
}
}
"name": "",
"description": null,
"devices": [],
"medium_type": "Twisted Pair (TP)"
}
}
}
},
"devices": {},
"group_addresses": {
"0/0/1": {
"name": "Schalten",
"identifier": "GA-1",
"raw_address": 1,
"address": "0/0/1",
"project_uid": 14,
"dpt": {
"main": 1,
"sub": 1
},
"communication_object_ids": [],
"description": "Livingroom LivingroomLight"
},
"devices": {},
"group_addresses": {
"0/0/2": {
"name": "Status",
"identifier": "GA-2",
"raw_address": 2,
"address": "0/0/2",
"project_uid": 16,
"dpt": {
"main": 1,
"sub": 1
},
"communication_object_ids": [],
"description": "Livingroom LivingroomLight"
}
},
"locations": {
"Minimal-Example": {
"type": "Building",
"identifier": "P-05C0-0_BP-1",
"name": "Minimal-Example",
"usage_id": null,
"usage_text": "",
"number": "",
"description": "",
"project_uid": 9,
"devices": [],
"spaces": {
"Livingroom": {
"type": "Room",
"identifier": "P-05C0-0_BP-2",
"name": "Livingroom",
"usage_id": "SU-4",
"usage_text": "Wohnzimmer",
"number": "",
"description": "",
"project_uid": 10,
"devices": [],
"spaces": {},
"functions": [
"F-1"
]
}
},
"functions": []
}
},
"functions": {
"F-1": {
"function_type": "FT-1",
"group_addresses": {
"0/0/1": {
"name": "Schalten",
"identifier": "GA-1",
"raw_address": 1,
"address": "0/0/1",
"project_uid": 14,
"dpt": {
"main": 1,
"sub": 1
},
"communication_object_ids": [],
"description": "Livingroom LivingroomLight"
"address": "0/0/1",
"name": "",
"project_uid": 15,
"role": "SwitchOnOff"
},
"0/0/2": {
"name": "Status",
"identifier": "GA-2",
"raw_address": 2,
"address": "0/0/2",
"project_uid": 16,
"dpt": {
"main": 1,
"sub": 1
},
"communication_object_ids": [],
"description": "Livingroom LivingroomLight"
}
},
"locations": {
"Minimal-Example": {
"type": "Building",
"identifier": "P-05C0-0_BP-1",
"name": "Minimal-Example",
"usage_id": null,
"usage_text": "",
"number": "",
"description": "",
"project_uid": 9,
"devices": [],
"spaces": {
"Livingroom": {
"type": "Room",
"identifier": "P-05C0-0_BP-2",
"name": "Livingroom",
"usage_id": "SU-4",
"usage_text": "Wohnzimmer",
"number": "",
"description": "",
"project_uid": 10,
"devices": [],
"spaces": {},
"functions": [
"F-1"
]
}
},
"functions": []
}
},
"functions": {
"F-1": {
"function_type": "FT-1",
"group_addresses": {
"0/0/1": {
"address": "0/0/1",
"name": "",
"project_uid": 15,
"role": "SwitchOnOff"
},
"0/0/2": {
"address": "0/0/2",
"name": "",
"project_uid": 17,
"role": "InfoOnOff"
}
},
"identifier": "F-1",
"name": "LivingroomLight",
"project_uid": 11,
"space_id": "P-05C0-0_BP-2",
"usage_text": "switchable light"
"address": "0/0/2",
"name": "",
"project_uid": 17,
"role": "InfoOnOff"
}
},
"identifier": "F-1",
"name": "LivingroomLight",
"project_uid": 11,
"space_id": "P-05C0-0_BP-2",
"usage_text": "Licht schalten"
}
}
}
}
4 changes: 2 additions & 2 deletions test/resources/stubs/xknx_test_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"created_by": "ETS5",
"schema_version": "20",
"tool_version": "5.7.1428.39779",
"xknxproject_version": "3.0.0",
"xknxproject_version": "3.2.0",
"language_code": null
},
"communication_objects": {
Expand Down Expand Up @@ -674,4 +674,4 @@
}
},
"functions": {}
}
}
31 changes: 17 additions & 14 deletions xknxproject/loader/knx_master_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from zipfile import Path

from xknxproject.const import ETS4_PRODUCT_LANGUAGES
from xknxproject.models import KNXMasterData, TranslationsType
from xknxproject.zip import KNXProjContents

_LOGGER = logging.getLogger("xknxproject.log")
Expand All @@ -19,12 +20,13 @@ def load(
knx_proj_contents: KNXProjContents,
knx_master_file: Path,
language: str | None,
) -> tuple[dict[str, str], dict[str, str], str | None, dict[str, str]]:
"""Load KNX master data."""
) -> tuple[KNXMasterData, str | None]:
"""Load KNX master data. Returns KNXMasterData and the found language code."""
manufacturer_mapping: dict[str, str] = {}
space_usage_mapping: dict[str, str] = {}
product_languages: list[str] = [] # eg. "en-US", "de-DE", "fr-FR"
language_code: str | None = None
translations: TranslationsType = {}
function_type_mapping: dict[str, str] = {}

with knx_master_file.open(mode="rb") as master_xml:
Expand Down Expand Up @@ -64,21 +66,22 @@ def load(
f"/{{*}}Language[@Identifier='{language_code}']"
"/{*}TranslationUnit/{*}TranslationElement"
):
_ref_id = translation_element.get("RefId")
if _ref_id not in space_usage_mapping:
continue
if (
translation_node := translation_element.find(
"{*}Translation[@AttributeName='Text']"
)
) is not None:
space_usage_mapping[_ref_id] = translation_node.get("Text", "")
_ref_id = translation_element.get("RefId", "")
translations[_ref_id] = {
attr: text
for item in translation_element.findall("{*}Translation")
if (attr := item.get("AttributeName")) is not None
and (text := item.get("Text")) is not None
}

return (
manufacturer_mapping,
space_usage_mapping,
KNXMasterData(
function_type_names=function_type_mapping,
manufacturer_names=manufacturer_mapping,
space_usage_mapping=space_usage_mapping,
translations=translations,
),
language_code,
function_type_mapping,
)

@staticmethod
Expand Down
Loading