diff --git a/homeassistant/auth/permissions/entities.py b/homeassistant/auth/permissions/entities.py index 3f2a0c14f19..4dc221a9ff4 100644 --- a/homeassistant/auth/permissions/entities.py +++ b/homeassistant/auth/permissions/entities.py @@ -47,7 +47,7 @@ def _lookup_domain( perm_lookup: PermissionLookup, domains_dict: SubCategoryDict, entity_id: str ) -> ValueType | None: """Look up entity permissions by domain.""" - return domains_dict.get(entity_id.split(".", 1)[0]) + return domains_dict.get(entity_id.partition(".")[0]) def _lookup_area( diff --git a/homeassistant/auth/providers/command_line.py b/homeassistant/auth/providers/command_line.py index af9a01f5d9b..92d8d617481 100644 --- a/homeassistant/auth/providers/command_line.py +++ b/homeassistant/auth/providers/command_line.py @@ -88,12 +88,12 @@ class CommandLineAuthProvider(AuthProvider): for _line in stdout.splitlines(): try: line = _line.decode().lstrip() - if line.startswith("#"): - continue - key, value = line.split("=", 1) except ValueError: # malformed line continue + if line.startswith("#") or "=" not in line: + continue + key, _, value = line.partition("=") key = key.strip() value = value.strip() if key in self.ALLOWED_META_KEYS: diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 31834c7b7a3..9ac8b2ef6e6 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -404,7 +404,7 @@ async def async_mount_local_lib_path(config_dir: str) -> str: def _get_domains(hass: core.HomeAssistant, config: dict[str, Any]) -> set[str]: """Get domains of components to set up.""" # Filter out the repeating and common config section [homeassistant] - domains = {key.split(" ")[0] for key in config if key != core.DOMAIN} + domains = {key.partition(" ")[0] for key in config if key != core.DOMAIN} # Add config entry domains if not hass.config.safe_mode: diff --git a/homeassistant/config.py b/homeassistant/config.py index c58f94ca197..a422cbea1d9 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -734,7 +734,7 @@ async def merge_packages_config( continue # If component name is given with a trailing description, remove it # when looking for component - domain = comp_name.split(" ")[0] + domain = comp_name.partition(" ")[0] try: integration = await async_get_integration_with_requirements( diff --git a/homeassistant/helpers/check_config.py b/homeassistant/helpers/check_config.py index 3bda89c9a73..bc17330f656 100644 --- a/homeassistant/helpers/check_config.py +++ b/homeassistant/helpers/check_config.py @@ -122,7 +122,7 @@ async def async_check_ha_config_file( # noqa: C901 core_config.pop(CONF_PACKAGES, None) # Filter out repeating config sections - components = {key.split(" ")[0] for key in config.keys()} + components = {key.partition(" ")[0] for key in config.keys()} # Process and validate config for domain in components: diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index f7f2b7e3dd3..1932c0397a1 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -36,7 +36,7 @@ _EntityT = TypeVar("_EntityT", bound=entity.Entity) @bind_hass async def async_update_entity(hass: HomeAssistant, entity_id: str) -> None: """Trigger an update for an entity.""" - domain = entity_id.split(".", 1)[0] + domain = entity_id.partition(".")[0] entity_comp: EntityComponent[entity.Entity] | None entity_comp = hass.data.get(DATA_INSTANCES, {}).get(domain) diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 138fa739794..ad90998cd7d 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -202,7 +202,7 @@ def async_prepare_call_from_config( f"Template rendered invalid service: {domain_service}" ) from ex - domain, service = domain_service.split(".", 1) + domain, _, service = domain_service.partition(".") target = {} if CONF_TARGET in config: diff --git a/homeassistant/helpers/trace.py b/homeassistant/helpers/trace.py index bc3e7ff3565..3a5fb83395a 100644 --- a/homeassistant/helpers/trace.py +++ b/homeassistant/helpers/trace.py @@ -63,7 +63,7 @@ class TraceElement: """Return dictionary version of this TraceElement.""" result: dict[str, Any] = {"path": self.path, "timestamp": self._timestamp} if self._child_key is not None: - domain, item_id = self._child_key.split(".", 1) + domain, _, item_id = self._child_key.partition(".") result["child_id"] = { "domain": domain, "item_id": item_id, diff --git a/homeassistant/helpers/translation.py b/homeassistant/helpers/translation.py index 616baeeea92..d1953b2fd00 100644 --- a/homeassistant/helpers/translation.py +++ b/homeassistant/helpers/translation.py @@ -97,10 +97,7 @@ def _merge_resources( # Build response resources: dict[str, dict[str, Any]] = {} for component in components: - if "." not in component: - domain = component - else: - domain = component.split(".", 1)[0] + domain = component.partition(".")[0] domain_resources = resources.setdefault(domain, {}) @@ -148,7 +145,7 @@ async def async_get_component_strings( hass: HomeAssistant, language: str, components: set[str] ) -> dict[str, Any]: """Load translations.""" - domains = list({loaded.split(".")[-1] for loaded in components}) + domains = list({loaded.rpartition(".")[-1] for loaded in components}) integrations: dict[str, Integration] = {} ints_or_excs = await async_get_integrations(hass, domains) diff --git a/homeassistant/setup.py b/homeassistant/setup.py index d85e4043505..2be22910a08 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -433,7 +433,7 @@ def async_get_loaded_integrations(hass: core.HomeAssistant) -> set[str]: if "." not in component: integrations.add(component) continue - domain, platform = component.split(".", 1) + domain, _, platform = component.partition(".") if domain in BASE_PLATFORMS: integrations.add(platform) return integrations @@ -458,10 +458,7 @@ def async_start_setup( time_taken = dt_util.utcnow() - started for unique, domain in unique_components.items(): del setup_started[unique] - if "." in domain: - _, integration = domain.split(".", 1) - else: - integration = domain + integration = domain.rpartition(".")[-1] if integration in setup_time: setup_time[integration] += time_taken else: diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index 6562ecedb4f..315c8ebda74 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -156,7 +156,7 @@ class Throttle: # be prefixed by '..' so we strip that out. is_func = ( not hasattr(method, "__self__") - and "." not in method.__qualname__.split("..")[-1] + and "." not in method.__qualname__.rpartition("..")[-1] ) @wraps(method)