mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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:
parent
3d2ecd6a28
commit
87989a88cd
@ -21,15 +21,6 @@ ICON_CACHE: HassKey[_IconsCache] = HassKey("icon_cache")
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_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(
|
def _load_icons_files(
|
||||||
icons_files: dict[str, pathlib.Path],
|
icons_files: dict[str, pathlib.Path],
|
||||||
) -> dict[str, dict[str, Any]]:
|
) -> dict[str, dict[str, Any]]:
|
||||||
@ -50,7 +41,7 @@ async def _async_get_component_icons(
|
|||||||
|
|
||||||
# Determine files to load
|
# Determine files to load
|
||||||
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
|
# Load files
|
||||||
|
@ -46,17 +46,6 @@ def recursive_flatten(
|
|||||||
return output
|
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(
|
def _load_translations_files_by_language(
|
||||||
translation_files: dict[str, dict[str, pathlib.Path]],
|
translation_files: dict[str, dict[str, pathlib.Path]],
|
||||||
) -> dict[str, dict[str, Any]]:
|
) -> dict[str, dict[str, Any]]:
|
||||||
@ -110,8 +99,9 @@ async def _async_get_component_strings(
|
|||||||
loaded_translations_by_language: dict[str, dict[str, Any]] = {}
|
loaded_translations_by_language: dict[str, dict[str, Any]] = {}
|
||||||
has_files_to_load = False
|
has_files_to_load = False
|
||||||
for language in languages:
|
for language in languages:
|
||||||
|
file_name = f"{language}.json"
|
||||||
files_to_load: dict[str, pathlib.Path] = {
|
files_to_load: dict[str, pathlib.Path] = {
|
||||||
domain: component_translation_path(language, integration)
|
domain: integration.file_path / "translations" / file_name
|
||||||
for domain in components
|
for domain in components
|
||||||
if (
|
if (
|
||||||
(integration := integrations.get(domain))
|
(integration := integrations.get(domain))
|
||||||
|
@ -162,10 +162,6 @@ async def test_get_icons_while_loading_components(hass: HomeAssistant) -> None:
|
|||||||
return {"component1": {"entity": {"climate": {"test": {"icon": "mdi:home"}}}}}
|
return {"component1": {"entity": {"climate": {"test": {"icon": "mdi:home"}}}}}
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
|
||||||
"homeassistant.helpers.icon._component_icons_path",
|
|
||||||
return_value="choochoo.json",
|
|
||||||
),
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.helpers.icon._load_icons_files",
|
"homeassistant.helpers.icon._load_icons_files",
|
||||||
mock_load_icons_files,
|
mock_load_icons_files,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Test the translation helper."""
|
"""Test the translation helper."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from os import path
|
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import Mock, call, patch
|
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.const import EVENT_CORE_CONFIG_UPDATE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import translation
|
from homeassistant.helpers import translation
|
||||||
from homeassistant.loader import async_get_integration
|
|
||||||
from homeassistant.setup import async_setup_component
|
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(
|
def test_load_translations_files_by_language(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -242,10 +221,6 @@ async def test_get_translations_loads_config_flows(
|
|||||||
integration.name = "Component 1"
|
integration.name = "Component 1"
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
|
||||||
"homeassistant.helpers.translation.component_translation_path",
|
|
||||||
return_value="bla.json",
|
|
||||||
),
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.helpers.translation._load_translations_files_by_language",
|
"homeassistant.helpers.translation._load_translations_files_by_language",
|
||||||
return_value={"en": {"component1": {"title": "world"}}},
|
return_value={"en": {"component1": {"title": "world"}}},
|
||||||
@ -275,10 +250,6 @@ async def test_get_translations_loads_config_flows(
|
|||||||
integration.name = "Component 2"
|
integration.name = "Component 2"
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
|
||||||
"homeassistant.helpers.translation.component_translation_path",
|
|
||||||
return_value="bla.json",
|
|
||||||
),
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.helpers.translation._load_translations_files_by_language",
|
"homeassistant.helpers.translation._load_translations_files_by_language",
|
||||||
return_value={"en": {"component2": {"title": "world"}}},
|
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}
|
return {language: {"component1": {"title": "world"}} for language in files}
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
|
||||||
"homeassistant.helpers.translation.component_translation_path",
|
|
||||||
return_value="bla.json",
|
|
||||||
),
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.helpers.translation._load_translations_files_by_language",
|
"homeassistant.helpers.translation._load_translations_files_by_language",
|
||||||
mock_load_translation_files,
|
mock_load_translation_files,
|
||||||
@ -697,10 +664,6 @@ async def test_get_translations_still_has_title_without_translations_files(
|
|||||||
integration.name = "Component 1"
|
integration.name = "Component 1"
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
|
||||||
"homeassistant.helpers.translation.component_translation_path",
|
|
||||||
return_value="bla.json",
|
|
||||||
),
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.helpers.translation._load_translations_files_by_language",
|
"homeassistant.helpers.translation._load_translations_files_by_language",
|
||||||
return_value={},
|
return_value={},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user