Only wait for import flows in setup of there is a config flow (#113780)

This commit is contained in:
J. Nick Koston 2024-03-19 10:38:27 -10:00 committed by GitHub
parent c52ee2a898
commit 879e5bc961
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 6 deletions

View file

@ -427,15 +427,19 @@ async def _async_setup_component( # noqa: C901
)
return False
# Flush out async_setup calling create_task. Fragile but covered by test.
if load_translations_task:
await load_translations_task
if integration.platforms_exists(("config_flow",)):
# If the integration has a config_flow, flush out async_setup calling create_task
# with an asyncio.sleep(0) so we can wait for import flows.
# Fragile but covered by test.
await asyncio.sleep(0)
await hass.config_entries.flow.async_wait_import_flow_initialized(domain)
if load_translations_task:
await load_translations_task
# Add to components before the entry.async_setup
# call to avoid a deadlock when forwarding platforms
hass.config.components.add(domain)
# Add to components before the entry.async_setup
# call to avoid a deadlock when forwarding platforms
hass.config.components.add(domain)
if entries := hass.config_entries.async_entries(
domain, include_ignore=False, include_disabled=False

View file

@ -926,6 +926,8 @@ async def test_websocket_update_preferences_alexa_report_state(
client = await hass_ws_client(hass)
with patch(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig.async_sync_entities"
), patch(
(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig"
".async_get_access_token"
@ -941,6 +943,7 @@ async def test_websocket_update_preferences_alexa_report_state(
response = await client.receive_json()
set_authorized_mock.assert_called_once_with(True)
await hass.async_block_till_done()
assert response["success"]

View file

@ -1121,6 +1121,7 @@ async def test_bootstrap_dependencies(
# We patch the _import platform method to avoid loading the platform module
# to avoid depending on non core components in the tests.
mqtt_integration._import_platform = Mock()
mqtt_integration.platforms_exists = Mock(return_value=True)
integrations = {
"mqtt": {