Make discovery flow tasks background tasks (#116327)

pull/116317/head^2
J. Nick Koston 2024-04-28 08:13:37 -05:00 committed by GitHub
parent 5d59b4cddd
commit 76639252c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 9 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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