Only raise missing integration issue for config entry integrations (#126654)

This commit is contained in:
Joost Lekkerkerker 2024-09-24 18:26:01 +02:00 committed by GitHub
parent ffa76dfd24
commit c1781cd793
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 6 deletions

View file

@ -281,7 +281,7 @@ async def _async_setup_component(
integration = await loader.async_get_integration(hass, domain) integration = await loader.async_get_integration(hass, domain)
except loader.IntegrationNotFound: except loader.IntegrationNotFound:
_log_error_setup_error(hass, domain, None, "Integration not found.") _log_error_setup_error(hass, domain, None, "Integration not found.")
if not hass.config.safe_mode: if not hass.config.safe_mode and hass.config_entries.async_entries(domain):
ir.async_create_issue( ir.async_create_issue(
hass, hass,
HOMEASSISTANT_DOMAIN, HOMEASSISTANT_DOMAIN,

View file

@ -23,6 +23,7 @@ async def test_integration_not_found_confirm_step(
await hass.async_block_till_done() await hass.async_block_till_done()
assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}}) assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}})
await hass.async_block_till_done() await hass.async_block_till_done()
MockConfigEntry(domain="test1").add_to_hass(hass)
assert await async_setup_component(hass, "test1", {}) is False assert await async_setup_component(hass, "test1", {}) is False
await hass.async_block_till_done() await hass.async_block_till_done()
entry1 = MockConfigEntry(domain="test1") entry1 = MockConfigEntry(domain="test1")
@ -83,6 +84,7 @@ async def test_integration_not_found_ignore_step(
await hass.async_block_till_done() await hass.async_block_till_done()
assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}}) assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}})
await hass.async_block_till_done() await hass.async_block_till_done()
MockConfigEntry(domain="test1").add_to_hass(hass)
assert await async_setup_component(hass, "test1", {}) is False assert await async_setup_component(hass, "test1", {}) is False
await hass.async_block_till_done() await hass.async_block_till_done()
entry1 = MockConfigEntry(domain="test1") entry1 = MockConfigEntry(domain="test1")

View file

@ -248,22 +248,39 @@ async def test_component_not_found(
hass: HomeAssistant, issue_registry: IssueRegistry hass: HomeAssistant, issue_registry: IssueRegistry
) -> None: ) -> None:
"""setup_component should raise a repair issue if component doesn't exist.""" """setup_component should raise a repair issue if component doesn't exist."""
MockConfigEntry(domain="non_existing").add_to_hass(hass)
assert await setup.async_setup_component(hass, "non_existing", {}) is False assert await setup.async_setup_component(hass, "non_existing", {}) is False
assert len(issue_registry.issues) == 1 assert len(issue_registry.issues) == 1
issue = issue_registry.async_get_issue( assert (
HOMEASSISTANT_DOMAIN, "integration_not_found.non_existing" HOMEASSISTANT_DOMAIN,
) "integration_not_found.non_existing",
assert issue ) in issue_registry.issues
assert issue.translation_key == "integration_not_found"
async def test_yaml_component_not_found(
hass: HomeAssistant, issue_registry: IssueRegistry
) -> None:
"""setup_component should only raise an exception for missing config entry integrations."""
assert await setup.async_setup_component(hass, "non_existing", {}) is False
assert len(issue_registry.issues) == 0
assert (
HOMEASSISTANT_DOMAIN,
"integration_not_found.non_existing",
) not in issue_registry.issues
async def test_component_missing_not_raising_in_safe_mode( async def test_component_missing_not_raising_in_safe_mode(
hass: HomeAssistant, issue_registry: IssueRegistry hass: HomeAssistant, issue_registry: IssueRegistry
) -> None: ) -> None:
"""setup_component should not raise an issue if component doesn't exist in safe.""" """setup_component should not raise an issue if component doesn't exist in safe."""
MockConfigEntry(domain="non_existing").add_to_hass(hass)
hass.config.safe_mode = True hass.config.safe_mode = True
assert await setup.async_setup_component(hass, "non_existing", {}) is False assert await setup.async_setup_component(hass, "non_existing", {}) is False
assert len(issue_registry.issues) == 0 assert len(issue_registry.issues) == 0
assert (
HOMEASSISTANT_DOMAIN,
"integration_not_found.non_existing",
) not in issue_registry.issues
async def test_component_not_double_initialized(hass: HomeAssistant) -> None: async def test_component_not_double_initialized(hass: HomeAssistant) -> None: