Skip to content

Commit

Permalink
restore tox.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
Bacher, Dominik committed Jul 13, 2023
1 parent a65c379 commit eb2dcc8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
34 changes: 34 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[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}
17 changes: 13 additions & 4 deletions xknxproject/loader/knx_master_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ def load(
for language_node in tree.findall(".//{*}ProductLanguages/{*}Language"):
product_languages.append(language_node.get("Identifier", ""))

for function_type_node in tree.findall(".//{*}FunctionTypes/{*}FunctionType"):
for function_type_node in tree.findall(
".//{*}FunctionTypes/{*}FunctionType"
):
identifier = function_type_node.get("Id", "")
function_type_mapping[identifier] = function_type_node.get("Text", "")

function_type_mapping[identifier] = function_type_node.get(
"Text", ""
)

if language is not None:
language_code = KNXMasterLoader.get_language_code(
language, product_languages
Expand All @@ -70,7 +74,12 @@ def load(
) is not None:
space_usage_mapping[_ref_id] = translation_node.get("Text", "")

return manufacturer_mapping, space_usage_mapping, language_code, function_type_mapping
return (
manufacturer_mapping,
space_usage_mapping,
language_code,
function_type_mapping,
)

@staticmethod
def get_language_code(language: str, product_languages: list[str]) -> str | None:
Expand Down
27 changes: 17 additions & 10 deletions xknxproject/loader/project_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
SpaceType,
XMLArea,
XMLFunction,
XMLGroupAddressRef,
XMLGroupAddress,
XMLGroupAddressRef,
XMLLine,
XMLProjectInformation,
XMLSpace,
Expand Down Expand Up @@ -65,8 +65,11 @@ def load(
)

location_loader = _LocationLoader(
knx_proj_contents, devices, space_usage_names,
function_type_names, group_address_list
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 @@ -294,8 +297,10 @@ def parse_space(self, node: ElementTree.Element) -> XMLSpace:
def parse_functions(self, node: ElementTree.Element) -> XMLFunction:
"""Parse a functions from the document."""
project_uid = node.get("Puid")
function_type=node.get("Type") # type: ignore[arg-type]
usage_text = self.function_type_names.get(function_type, "") if function_type else ""
function_type = node.get("Type", "")
usage_text = (
self.function_type_names.get(function_type, "") if function_type else ""
)
functions: XMLFunction = XMLFunction(
identifier=node.get("Id"), # type: ignore[arg-type]
name=node.get("Name"), # type: ignore[arg-type]
Expand All @@ -304,13 +309,15 @@ def parse_functions(self, node: ElementTree.Element) -> XMLFunction:
group_addresses=[],
usage_text=usage_text,
)

for sub_node in node:
if sub_node.tag.endswith("GroupAddressRef"):
project_uid = sub_node.get("Puid")
id=sub_node.get("RefId", "").split('_')[1]
address=[g for g in self.group_address_list if g.identifier == id][0].address

project_uid = sub_node.get("Puid")
ref_id = sub_node.get("RefId", "").split("_")[1]
address = [
g for g in self.group_address_list if g.identifier == ref_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]
Expand Down
1 change: 0 additions & 1 deletion xknxproject/models/knxproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class GroupAddressRef(TypedDict):
identifier: str
name: str
role: str
ref_id: str
address: str
project_uid: int | None

Expand Down

0 comments on commit eb2dcc8

Please sign in to comment.