From 87989a88cd4cff6461084434d52f27289e189732 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 26 May 2024 22:35:52 -1000 Subject: [PATCH] Remove translation and icon component path functions (#118214) These functions have been stripped down to always return the same path so there was no longer a need to have a function for this. This is left-over cleanup from previous refactoring. --- homeassistant/helpers/icon.py | 11 +-------- homeassistant/helpers/translation.py | 14 ++--------- tests/helpers/test_icon.py | 4 --- tests/helpers/test_translation.py | 37 ---------------------------- 4 files changed, 3 insertions(+), 63 deletions(-) diff --git a/homeassistant/helpers/icon.py b/homeassistant/helpers/icon.py index 0f72dfbd3ab..e759719f667 100644 --- a/homeassistant/helpers/icon.py +++ b/homeassistant/helpers/icon.py @@ -21,15 +21,6 @@ ICON_CACHE: HassKey[_IconsCache] = HassKey("icon_cache") _LOGGER = logging.getLogger(__name__) -@callback -def _component_icons_path(integration: Integration) -> pathlib.Path: - """Return the icons json file location for a component. - - Ex: components/hue/icons.json - """ - return integration.file_path / "icons.json" - - def _load_icons_files( icons_files: dict[str, pathlib.Path], ) -> dict[str, dict[str, Any]]: @@ -50,7 +41,7 @@ async def _async_get_component_icons( # Determine files to load files_to_load = { - comp: _component_icons_path(integrations[comp]) for comp in components + comp: integrations[comp].file_path / "icons.json" for comp in components } # Load files diff --git a/homeassistant/helpers/translation.py b/homeassistant/helpers/translation.py index 81f7a6f8e74..01c47aa8d0d 100644 --- a/homeassistant/helpers/translation.py +++ b/homeassistant/helpers/translation.py @@ -46,17 +46,6 @@ def recursive_flatten( return output -@callback -def component_translation_path(language: str, integration: Integration) -> pathlib.Path: - """Return the translation json file location for a component. - - For component: - - components/hue/translations/nl.json - - """ - return integration.file_path / "translations" / f"{language}.json" - - def _load_translations_files_by_language( translation_files: dict[str, dict[str, pathlib.Path]], ) -> dict[str, dict[str, Any]]: @@ -110,8 +99,9 @@ async def _async_get_component_strings( loaded_translations_by_language: dict[str, dict[str, Any]] = {} has_files_to_load = False for language in languages: + file_name = f"{language}.json" files_to_load: dict[str, pathlib.Path] = { - domain: component_translation_path(language, integration) + domain: integration.file_path / "translations" / file_name for domain in components if ( (integration := integrations.get(domain)) diff --git a/tests/helpers/test_icon.py b/tests/helpers/test_icon.py index 5ad5071266b..732f9971ac0 100644 --- a/tests/helpers/test_icon.py +++ b/tests/helpers/test_icon.py @@ -162,10 +162,6 @@ async def test_get_icons_while_loading_components(hass: HomeAssistant) -> None: return {"component1": {"entity": {"climate": {"test": {"icon": "mdi:home"}}}}} with ( - patch( - "homeassistant.helpers.icon._component_icons_path", - return_value="choochoo.json", - ), patch( "homeassistant.helpers.icon._load_icons_files", mock_load_icons_files, diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index 4cc83ad5eea..0e8bbfc4b60 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -1,7 +1,6 @@ """Test the translation helper.""" import asyncio -from os import path import pathlib from typing import Any from unittest.mock import Mock, call, patch @@ -12,7 +11,6 @@ from homeassistant import loader from homeassistant.const import EVENT_CORE_CONFIG_UPDATE from homeassistant.core import HomeAssistant from homeassistant.helpers import translation -from homeassistant.loader import async_get_integration from homeassistant.setup import async_setup_component @@ -42,25 +40,6 @@ def test_recursive_flatten() -> None: } -async def test_component_translation_path( - hass: HomeAssistant, enable_custom_integrations: None -) -> None: - """Test the component translation file function.""" - assert await async_setup_component( - hass, - "switch", - {"switch": [{"platform": "test"}, {"platform": "test_embedded"}]}, - ) - assert await async_setup_component(hass, "test_package", {"test_package": None}) - int_test_package = await async_get_integration(hass, "test_package") - - assert path.normpath( - translation.component_translation_path("en", int_test_package) - ) == path.normpath( - hass.config.path("custom_components", "test_package", "translations", "en.json") - ) - - def test_load_translations_files_by_language( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: @@ -242,10 +221,6 @@ async def test_get_translations_loads_config_flows( integration.name = "Component 1" with ( - patch( - "homeassistant.helpers.translation.component_translation_path", - return_value="bla.json", - ), patch( "homeassistant.helpers.translation._load_translations_files_by_language", return_value={"en": {"component1": {"title": "world"}}}, @@ -275,10 +250,6 @@ async def test_get_translations_loads_config_flows( integration.name = "Component 2" with ( - patch( - "homeassistant.helpers.translation.component_translation_path", - return_value="bla.json", - ), patch( "homeassistant.helpers.translation._load_translations_files_by_language", return_value={"en": {"component2": {"title": "world"}}}, @@ -329,10 +300,6 @@ async def test_get_translations_while_loading_components(hass: HomeAssistant) -> return {language: {"component1": {"title": "world"}} for language in files} with ( - patch( - "homeassistant.helpers.translation.component_translation_path", - return_value="bla.json", - ), patch( "homeassistant.helpers.translation._load_translations_files_by_language", mock_load_translation_files, @@ -697,10 +664,6 @@ async def test_get_translations_still_has_title_without_translations_files( integration.name = "Component 1" with ( - patch( - "homeassistant.helpers.translation.component_translation_path", - return_value="bla.json", - ), patch( "homeassistant.helpers.translation._load_translations_files_by_language", return_value={},