From b36059fc64c6fd27b33069df234fdea468467573 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 2 Aug 2024 13:38:56 +0200 Subject: [PATCH] Do not raise repair issue about missing integration in safe mode (#123066) --- homeassistant/setup.py | 27 ++++++++++++++------------- tests/test_setup.py | 11 ++++++++++- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 12dd17b289c..102c48e1d07 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -281,19 +281,20 @@ async def _async_setup_component( integration = await loader.async_get_integration(hass, domain) except loader.IntegrationNotFound: _log_error_setup_error(hass, domain, None, "Integration not found.") - ir.async_create_issue( - hass, - HOMEASSISTANT_DOMAIN, - f"integration_not_found.{domain}", - is_fixable=True, - issue_domain=HOMEASSISTANT_DOMAIN, - severity=IssueSeverity.ERROR, - translation_key="integration_not_found", - translation_placeholders={ - "domain": domain, - }, - data={"domain": domain}, - ) + if not hass.config.safe_mode: + ir.async_create_issue( + hass, + HOMEASSISTANT_DOMAIN, + f"integration_not_found.{domain}", + is_fixable=True, + issue_domain=HOMEASSISTANT_DOMAIN, + severity=IssueSeverity.ERROR, + translation_key="integration_not_found", + translation_placeholders={ + "domain": domain, + }, + data={"domain": domain}, + ) return False log_error = partial(_log_error_setup_error, hass, domain, integration) diff --git a/tests/test_setup.py b/tests/test_setup.py index 3430c17960c..4e7c23865da 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -245,7 +245,7 @@ async def test_validate_platform_config_4(hass: HomeAssistant) -> None: async def test_component_not_found( hass: HomeAssistant, issue_registry: IssueRegistry ) -> None: - """setup_component should not crash if component doesn't exist.""" + """setup_component should raise a repair issue if component doesn't exist.""" assert await setup.async_setup_component(hass, "non_existing", {}) is False assert len(issue_registry.issues) == 1 issue = issue_registry.async_get_issue( @@ -255,6 +255,15 @@ async def test_component_not_found( assert issue.translation_key == "integration_not_found" +async def test_component_missing_not_raising_in_safe_mode( + hass: HomeAssistant, issue_registry: IssueRegistry +) -> None: + """setup_component should not raise an issue if component doesn't exist in safe.""" + hass.config.safe_mode = True + assert await setup.async_setup_component(hass, "non_existing", {}) is False + assert len(issue_registry.issues) == 0 + + async def test_component_not_double_initialized(hass: HomeAssistant) -> None: """Test we do not set up a component twice.""" mock_setup = Mock(return_value=True)