Include all config flow translations with backend translations (#13394)
This commit is contained in:
parent
98620d8ce8
commit
fb1fafefab
2 changed files with 29 additions and 2 deletions
|
@ -4,6 +4,7 @@ import logging
|
||||||
from typing import Optional # NOQA
|
from typing import Optional # NOQA
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
|
from homeassistant import config_entries
|
||||||
from homeassistant.loader import get_component, bind_hass
|
from homeassistant.loader import get_component, bind_hass
|
||||||
from homeassistant.util.json import load_json
|
from homeassistant.util.json import load_json
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ async def async_get_component_resources(hass, language):
|
||||||
translation_cache = hass.data[TRANSLATION_STRING_CACHE][language]
|
translation_cache = hass.data[TRANSLATION_STRING_CACHE][language]
|
||||||
|
|
||||||
# Get the set of components
|
# Get the set of components
|
||||||
components = hass.config.components
|
components = hass.config.components | set(config_entries.FLOWS)
|
||||||
|
|
||||||
# Calculate the missing components
|
# Calculate the missing components
|
||||||
missing_components = components - set(translation_cache)
|
missing_components = components - set(translation_cache)
|
||||||
|
|
|
@ -1,11 +1,23 @@
|
||||||
"""Test the translation helper."""
|
"""Test the translation helper."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
from os import path
|
from os import path
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant import config_entries
|
||||||
import homeassistant.helpers.translation as translation
|
import homeassistant.helpers.translation as translation
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_config_flows():
|
||||||
|
"""Mock the config flows."""
|
||||||
|
flows = []
|
||||||
|
with patch.object(config_entries, 'FLOWS', flows):
|
||||||
|
yield flows
|
||||||
|
|
||||||
|
|
||||||
def test_flatten():
|
def test_flatten():
|
||||||
"""Test the flatten function."""
|
"""Test the flatten function."""
|
||||||
data = {
|
data = {
|
||||||
|
@ -71,7 +83,7 @@ def test_load_translations_files(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_get_translations(hass):
|
async def test_get_translations(hass, mock_config_flows):
|
||||||
"""Test the get translations helper."""
|
"""Test the get translations helper."""
|
||||||
translations = await translation.async_get_translations(hass, 'en')
|
translations = await translation.async_get_translations(hass, 'en')
|
||||||
assert translations == {}
|
assert translations == {}
|
||||||
|
@ -106,3 +118,17 @@ async def test_get_translations(hass):
|
||||||
'component.switch.state.string1': 'Value 1',
|
'component.switch.state.string1': 'Value 1',
|
||||||
'component.switch.state.string2': 'Value 2',
|
'component.switch.state.string2': 'Value 2',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_translations_loads_config_flows(hass, mock_config_flows):
|
||||||
|
"""Test the get translations helper loads config flow translations."""
|
||||||
|
mock_config_flows.append('component1')
|
||||||
|
|
||||||
|
with patch.object(translation, 'component_translation_file',
|
||||||
|
return_value='bla.json'), \
|
||||||
|
patch.object(translation, 'load_translations_files', return_value={
|
||||||
|
'component1': {'hello': 'world'}}):
|
||||||
|
translations = await translation.async_get_translations(hass, 'en')
|
||||||
|
assert translations == {
|
||||||
|
'component.component1.hello': 'world'
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue