Avoid waiting for integration platforms in the parent integration (#112467)

This commit is contained in:
J. Nick Koston
2024-03-05 21:16:42 -10:00
committed by GitHub
parent 87739bc072
commit f3a9756f81
29 changed files with 126 additions and 5 deletions

View File

@@ -16,6 +16,44 @@ from homeassistant.setup import ATTR_COMPONENT, EVENT_COMPONENT_LOADED
from tests.common import mock_platform
async def test_process_integration_platforms_with_wait(hass: HomeAssistant) -> None:
"""Test processing integrations."""
loaded_platform = Mock()
mock_platform(hass, "loaded.platform_to_check", loaded_platform)
hass.config.components.add("loaded")
event_platform = Mock()
mock_platform(hass, "event.platform_to_check", event_platform)
processed = []
async def _process_platform(hass, domain, platform):
"""Process platform."""
processed.append((domain, platform))
await async_process_integration_platforms(
hass, "platform_to_check", _process_platform, wait_for_platforms=True
)
# No block till done here, we want to make sure it waits for the platform
assert len(processed) == 1
assert processed[0][0] == "loaded"
assert processed[0][1] == loaded_platform
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: "event"})
await hass.async_block_till_done()
assert len(processed) == 2
assert processed[1][0] == "event"
assert processed[1][1] == event_platform
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: "event"})
await hass.async_block_till_done()
# Firing again should not check again
assert len(processed) == 2
async def test_process_integration_platforms(hass: HomeAssistant) -> None:
"""Test processing integrations."""
loaded_platform = Mock()
@@ -34,6 +72,7 @@ async def test_process_integration_platforms(hass: HomeAssistant) -> None:
await async_process_integration_platforms(
hass, "platform_to_check", _process_platform
)
await hass.async_block_till_done()
assert len(processed) == 1
assert processed[0][0] == "loaded"
@@ -77,6 +116,7 @@ async def test_process_integration_platforms_import_fails(
await async_process_integration_platforms(
hass, "platform_to_check", _process_platform
)
await hass.async_block_till_done()
assert len(processed) == 0
assert "Unexpected error importing platform_to_check for loaded" in caplog.text
@@ -115,6 +155,7 @@ async def test_process_integration_platforms_import_fails_after_registered(
await async_process_integration_platforms(
hass, "platform_to_check", _process_platform
)
await hass.async_block_till_done()
assert len(processed) == 1
assert processed[0][0] == "loaded"
@@ -166,6 +207,7 @@ async def test_process_integration_platforms_non_compliant(
await async_process_integration_platforms(
hass, "platform_to_check", process_platform
)
await hass.async_block_till_done()
assert len(processed) == 0
assert "Exception in " in caplog.text
@@ -204,6 +246,7 @@ async def test_broken_integration(
await async_process_integration_platforms(
hass, "platform_to_check", _process_platform
)
await hass.async_block_till_done()
# This should never actually happen as the component cannot be
# in hass.config.components without a loaded manifest
@@ -226,5 +269,6 @@ async def test_process_integration_platforms_no_integrations(
await async_process_integration_platforms(
hass, "platform_to_check", _process_platform
)
await hass.async_block_till_done()
assert len(processed) == 0