Support requesting translations for multiple integrations in a single request (#71979)
This commit is contained in:
parent
78f0716574
commit
a614ddca28
5 changed files with 88 additions and 15 deletions
|
@ -290,12 +290,29 @@ async def test_translation_merging_loaded_apart(hass, caplog):
|
|||
assert "component.sensor.state.moon__phase.first_quarter" in translations
|
||||
|
||||
translations = await translation.async_get_translations(
|
||||
hass, "en", "state", integration="sensor"
|
||||
hass, "en", "state", integrations={"sensor"}
|
||||
)
|
||||
|
||||
assert "component.sensor.state.moon__phase.first_quarter" in translations
|
||||
|
||||
|
||||
async def test_translation_merging_loaded_together(hass, caplog):
|
||||
"""Test we merge translations of two integrations when they are loaded at the same time."""
|
||||
hass.config.components.add("hue")
|
||||
hass.config.components.add("homekit")
|
||||
hue_translations = await translation.async_get_translations(
|
||||
hass, "en", "config", integrations={"hue"}
|
||||
)
|
||||
homekit_translations = await translation.async_get_translations(
|
||||
hass, "en", "config", integrations={"homekit"}
|
||||
)
|
||||
|
||||
translations = await translation.async_get_translations(
|
||||
hass, "en", "config", integrations={"hue", "homekit"}
|
||||
)
|
||||
assert translations == hue_translations | homekit_translations
|
||||
|
||||
|
||||
async def test_caching(hass):
|
||||
"""Test we cache data."""
|
||||
hass.config.components.add("sensor")
|
||||
|
@ -320,14 +337,14 @@ async def test_caching(hass):
|
|||
)
|
||||
|
||||
load_sensor_only = await translation.async_get_translations(
|
||||
hass, "en", "state", integration="sensor"
|
||||
hass, "en", "state", integrations={"sensor"}
|
||||
)
|
||||
assert load_sensor_only
|
||||
for key in load_sensor_only:
|
||||
assert key.startswith("component.sensor.state.")
|
||||
|
||||
load_light_only = await translation.async_get_translations(
|
||||
hass, "en", "state", integration="light"
|
||||
hass, "en", "state", integrations={"light"}
|
||||
)
|
||||
assert load_light_only
|
||||
for key in load_light_only:
|
||||
|
@ -341,7 +358,7 @@ async def test_caching(hass):
|
|||
side_effect=translation._build_resources,
|
||||
) as mock_build:
|
||||
load_sensor_only = await translation.async_get_translations(
|
||||
hass, "en", "title", integration="sensor"
|
||||
hass, "en", "title", integrations={"sensor"}
|
||||
)
|
||||
assert load_sensor_only
|
||||
for key in load_sensor_only:
|
||||
|
@ -349,12 +366,12 @@ async def test_caching(hass):
|
|||
assert len(mock_build.mock_calls) == 0
|
||||
|
||||
assert await translation.async_get_translations(
|
||||
hass, "en", "title", integration="sensor"
|
||||
hass, "en", "title", integrations={"sensor"}
|
||||
)
|
||||
assert len(mock_build.mock_calls) == 0
|
||||
|
||||
load_light_only = await translation.async_get_translations(
|
||||
hass, "en", "title", integration="media_player"
|
||||
hass, "en", "title", integrations={"media_player"}
|
||||
)
|
||||
assert load_light_only
|
||||
for key in load_light_only:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue