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.
This commit is contained in:
J. Nick Koston 2024-05-26 22:35:52 -10:00 committed by GitHub
parent 3d2ecd6a28
commit 87989a88cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 3 additions and 63 deletions

View File

@ -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

View File

@ -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))

View File

@ -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,

View File

@ -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={},