diff --git a/homeassistant/helpers/translation.py b/homeassistant/helpers/translation.py index ca79ec443ab..b799469e2d3 100644 --- a/homeassistant/helpers/translation.py +++ b/homeassistant/helpers/translation.py @@ -162,13 +162,14 @@ async def _async_get_component_strings( translations_by_language: dict[str, dict[str, Any]] = {} # Determine paths of missing components/platforms files_to_load_by_language: dict[str, dict[str, str]] = {} + has_files_to_load = False for language in languages: files_to_load: dict[str, str] = {} files_to_load_by_language[language] = files_to_load translations_by_language[language] = {} - for loaded in components: - domain, _, platform = loaded.partition(".") + for comp in components: + domain, _, platform = comp.partition(".") if not (integration := integrations.get(domain)): continue @@ -179,10 +180,11 @@ async def _async_get_component_strings( # them. continue - if path := component_translation_path(loaded, language, integration): - files_to_load[loaded] = path + if path := component_translation_path(comp, language, integration): + files_to_load[comp] = path + has_files_to_load = True - if not files_to_load: + if not has_files_to_load: return translations_by_language # Load files diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index 69d7ef274ae..839607cc8b8 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -541,6 +541,37 @@ async def test_ensure_translations_still_load_if_one_integration_fails( assert translations == sensor_translations +async def test_load_translations_all_integrations_broken( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: + """Ensure we do not try to load translations again if the integration is broken.""" + hass.config.components.add("broken") + hass.config.components.add("broken2") + + with patch( + "homeassistant.helpers.translation.async_get_integrations", + return_value={ + "broken2": Exception("unhandled failure"), + "broken": Exception("unhandled failure"), + }, + ): + translations = await translation.async_get_translations( + hass, "en", "entity_component", integrations={"broken", "broken2"} + ) + assert "Failed to load integration for translation" in caplog.text + assert "broken" in caplog.text + assert "broken2" in caplog.text + assert not translations + caplog.clear() + + translations = await translation.async_get_translations( + hass, "en", "entity_component", integrations={"broken", "broken2"} + ) + assert not translations + # Ensure we do not try again + assert "Failed to load integration for translation" not in caplog.text + + async def test_caching(hass: HomeAssistant) -> None: """Test we cache data.""" hass.config.components.add("sensor")