Do not raise repair issue about missing integration in safe mode (#123066)

This commit is contained in:
Joost Lekkerkerker 2024-08-02 13:38:56 +02:00 committed by Franck Nijhof
parent 13c9d69440
commit b36059fc64
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
2 changed files with 24 additions and 14 deletions

View file

@ -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)

View file

@ -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)