diff --git a/xknxproject/loader/application_program_loader.py b/xknxproject/loader/application_program_loader.py index bedfb2a..eec1b18 100644 --- a/xknxproject/loader/application_program_loader.py +++ b/xknxproject/loader/application_program_loader.py @@ -58,7 +58,7 @@ def load( tree_iterator = ElementTree.iterparse(application_xml, events=("start",)) # get namespace from root element _, elem = next(tree_iterator) - namespace = elem.tag.split("KNX")[0] + namespace = elem.tag.split("KNX", maxsplit=1)[0] # define namespaced tag strings for faster comparison - ~15% faster # than elem.tag.endswith("tagname") or elem.tag == f"{namespace}tagname" ns_com_object = f"{namespace}ComObject" diff --git a/xknxproject/loader/project_loader.py b/xknxproject/loader/project_loader.py index a5eec4a..f4f69bd 100644 --- a/xknxproject/loader/project_loader.py +++ b/xknxproject/loader/project_loader.py @@ -322,7 +322,9 @@ def __get_links_from_ets4(com_object: ElementTree.Element) -> list[str]: ga_list = connectors.findall("{*}Send") + connectors.findall("{*}Receive") # Remove the project ID from GA - return [ga.get("GroupAddressRefId", "").split("_")[1] for ga in ga_list] + return [ + ga.get("GroupAddressRefId", "").split("_", maxsplit=1)[1] for ga in ga_list + ] @staticmethod def __get_links_from_ets5(com_object: ElementTree.Element) -> list[str]: @@ -451,7 +453,7 @@ def parse_space( def parse_functions(self, node: ElementTree.Element) -> XMLFunction: """Parse a functions from the document.""" - identifier = node.get("Id", "").split("_")[1] + identifier = node.get("Id", "").split("_", 1)[1] project_uid = node.get("Puid") function_type = node.get("Type", "") @@ -468,7 +470,7 @@ 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", "").split("_")[1] + ref_id = sub_node.get("RefId", "").split("_", 1)[1] group_address_ref: XMLGroupAddressRef = XMLGroupAddressRef( ref_id=ref_id, diff --git a/xknxproject/models/models.py b/xknxproject/models/models.py index 1c33977..af0718b 100644 --- a/xknxproject/models/models.py +++ b/xknxproject/models/models.py @@ -35,7 +35,7 @@ def __init__( ): """Initialize a group address.""" self.name = name - self.identifier = identifier.split("_")[1] + self.identifier = identifier.split("_", 1)[1] self.raw_address = int(address) self.project_uid = project_uid self.description = description @@ -284,7 +284,7 @@ def resolve_channel_module_placeholders( ): return - module_instance_ref = self.ref_id.split("_CH")[0] + module_instance_ref = self.ref_id.split("_CH", maxsplit=1)[0] try: module_instance = next( mi @@ -316,10 +316,10 @@ class ModuleInstance: def __post_init__(self) -> None: """Set is_submodule based on the identifier.""" - self.module_def_id = self.ref_id.split("_")[0] + self.module_def_id = self.ref_id.split("_", maxsplit=1)[0] _submodule_match = re.search(r"(_SM-[^_]+)", self.identifier) if _submodule_match is not None: - self.base_module = f"{self.identifier.split('_SM-')[0]}" + self.base_module = f"{self.identifier.split('_SM-', maxsplit=1)[0]}" self.definition_id = f"{self.module_def_id}{_submodule_match.group()}" else: self.base_module = None @@ -580,7 +580,9 @@ def _base_number_from_allocator( base_number_argument, ) return 0 - module_instance_index = int(self.ref_id.split("_MI-")[1].split("_")[0]) + module_instance_index = int( + self.ref_id.split("_MI-", maxsplit=1)[1].split("_", maxsplit=1)[0] + ) return allocator_object_base.start + ( allocator_size * (module_instance_index - 1) ) diff --git a/xknxproject/util.py b/xknxproject/util.py index 934921a..1ae974b 100644 --- a/xknxproject/util.py +++ b/xknxproject/util.py @@ -142,8 +142,8 @@ def text_parameter_insert_module_instance( if "_MD-" in text_parameter_ref_id and ( _module_ref := get_module_instance_part(instance_ref, next_id=instance_next_id) ): - _application_ref = text_parameter_ref_id.split("_MD-")[0] - _parameter_ref = text_parameter_ref_id.split("_P-")[1] + _application_ref = text_parameter_ref_id.split("_MD-", maxsplit=1)[0] + _parameter_ref = text_parameter_ref_id.rsplit("_P-", maxsplit=1)[-1] return f"{_application_ref}_{_module_ref}_P-{_parameter_ref}" return text_parameter_ref_id diff --git a/xknxproject/zip/extractor.py b/xknxproject/zip/extractor.py index 3978f64..59f5006 100644 --- a/xknxproject/zip/extractor.py +++ b/xknxproject/zip/extractor.py @@ -169,7 +169,7 @@ def _get_xml_namespace(project_zip: ZipFile) -> str: def _get_schema_version(namespace: str) -> int: """Get the schema version of the project.""" try: - schema_version = int(namespace.split("/")[-1]) + schema_version = int(namespace.rsplit("/", 1)[-1]) except ValueError: _LOGGER.error("Could not parse schema version from %s", namespace) raise UnexpectedFileContent("Could not parse schema version.") from None