diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 056814bbc4d..88230a78428 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -1157,6 +1157,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager[ConfigFlowResult]): cooldown=DISCOVERY_COOLDOWN, immediate=True, function=self._async_discovery, + background=True, ) async def async_wait_import_flow_initialized(self, handler: str) -> None: diff --git a/homeassistant/helpers/discovery_flow.py b/homeassistant/helpers/discovery_flow.py index 314777733c3..e479a47ecfd 100644 --- a/homeassistant/helpers/discovery_flow.py +++ b/homeassistant/helpers/discovery_flow.py @@ -30,7 +30,7 @@ def async_create_flow( if not dispatcher or dispatcher.started: if init_coro := _async_init_flow(hass, domain, context, data): - hass.async_create_task( + hass.async_create_background_task( init_coro, f"discovery flow {domain} {context}", eager_start=True ) return diff --git a/tests/components/gardena_bluetooth/test_config_flow.py b/tests/components/gardena_bluetooth/test_config_flow.py index 7707a13180f..3b4e9c242b3 100644 --- a/tests/components/gardena_bluetooth/test_config_flow.py +++ b/tests/components/gardena_bluetooth/test_config_flow.py @@ -103,7 +103,7 @@ async def test_bluetooth( # Inject the service info will trigger the flow to start inject_bluetooth_service_info(hass, WATER_TIMER_SERVICE_INFO) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) result = next(iter(hass.config_entries.flow.async_progress_by_handler(DOMAIN))) diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index da49b8d9f16..572593d642b 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -1098,7 +1098,7 @@ async def test_setup_hardware_integration( ) as mock_setup_entry, ): result = await async_setup_component(hass, "hassio", {"hassio": {}}) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert result assert aioclient_mock.call_count == 19 diff --git a/tests/components/homeassistant_yellow/test_init.py b/tests/components/homeassistant_yellow/test_init.py index 0631c2cb983..ec3ba4e7005 100644 --- a/tests/components/homeassistant_yellow/test_init.py +++ b/tests/components/homeassistant_yellow/test_init.py @@ -44,7 +44,7 @@ async def test_setup_entry( ), ): assert await hass.config_entries.async_setup(config_entry.entry_id) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert len(mock_get_os_info.mock_calls) == 1 @@ -90,7 +90,7 @@ async def test_setup_zha(hass: HomeAssistant, addon_store_info) -> None: ), ): assert await hass.config_entries.async_setup(config_entry.entry_id) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert len(mock_get_os_info.mock_calls) == 1 # Finish setting up ZHA @@ -144,7 +144,7 @@ async def test_setup_zha_multipan( ), ): assert await hass.config_entries.async_setup(config_entry.entry_id) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert len(mock_get_os_info.mock_calls) == 1 # Finish setting up ZHA @@ -198,7 +198,7 @@ async def test_setup_zha_multipan_other_device( ), ): assert await hass.config_entries.async_setup(config_entry.entry_id) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) assert len(mock_get_os_info.mock_calls) == 1 # Finish setting up ZHA diff --git a/tests/components/plex/test_config_flow.py b/tests/components/plex/test_config_flow.py index 33e1b3637d8..5f2531992d4 100644 --- a/tests/components/plex/test_config_flow.py +++ b/tests/components/plex/test_config_flow.py @@ -722,7 +722,7 @@ async def test_integration_discovery(hass: HomeAssistant) -> None: with patch("homeassistant.components.plex.config_flow.GDM", return_value=mock_gdm): await config_flow.async_discover(hass) - await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) flows = hass.config_entries.flow.async_progress()