From d10f5a48d40769ebcad9487878589e337a75b9ad Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 19 Apr 2020 12:37:44 -0700 Subject: [PATCH] Fix translations merging (#34417) Co-Authored-By: Martin Hjelmare --- homeassistant/helpers/translation.py | 11 +++++++---- tests/helpers/test_translation.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/translation.py b/homeassistant/helpers/translation.py index 888f2838372..9933d550f6a 100644 --- a/homeassistant/helpers/translation.py +++ b/homeassistant/helpers/translation.py @@ -104,12 +104,15 @@ def build_resources( domain_resources.update(translation_cache[component]) continue - if category not in translation_cache[component]: + new_value = translation_cache[component].get(category) + + if new_value is None: continue - domain_resources.setdefault(category, {}).update( - translation_cache[component][category] - ) + if isinstance(new_value, dict): + domain_resources.setdefault(category, {}).update(new_value) + else: + domain_resources[category] = new_value return {"component": resources} diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index d0ec7e86b0c..78f1fe8ab70 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -192,3 +192,17 @@ async def test_get_translations_while_loading_components(hass): "component.component1.title": "Component 1", "component.component1.hello": "world", } + + +async def test_get_translation_categories(hass): + """Test the get translations helper loads config flow translations.""" + with patch.object(translation, "async_get_config_flows", return_value={"light"}): + translations = await translation.async_get_translations( + hass, "en", "title", None, True + ) + assert "component.light.title" in translations + + translations = await translation.async_get_translations( + hass, "en", "device_automation", None, True + ) + assert "component.light.device_automation.action_type.turn_on" in translations