mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Make discovery flow tasks background tasks (#116327)
This commit is contained in:
parent
5d59b4cddd
commit
76639252c9
@ -1157,6 +1157,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager[ConfigFlowResult]):
|
|||||||
cooldown=DISCOVERY_COOLDOWN,
|
cooldown=DISCOVERY_COOLDOWN,
|
||||||
immediate=True,
|
immediate=True,
|
||||||
function=self._async_discovery,
|
function=self._async_discovery,
|
||||||
|
background=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_wait_import_flow_initialized(self, handler: str) -> None:
|
async def async_wait_import_flow_initialized(self, handler: str) -> None:
|
||||||
|
@ -30,7 +30,7 @@ def async_create_flow(
|
|||||||
|
|
||||||
if not dispatcher or dispatcher.started:
|
if not dispatcher or dispatcher.started:
|
||||||
if init_coro := _async_init_flow(hass, domain, context, data):
|
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
|
init_coro, f"discovery flow {domain} {context}", eager_start=True
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
@ -103,7 +103,7 @@ async def test_bluetooth(
|
|||||||
|
|
||||||
# Inject the service info will trigger the flow to start
|
# Inject the service info will trigger the flow to start
|
||||||
inject_bluetooth_service_info(hass, WATER_TIMER_SERVICE_INFO)
|
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)))
|
result = next(iter(hass.config_entries.flow.async_progress_by_handler(DOMAIN)))
|
||||||
|
|
||||||
|
@ -1098,7 +1098,7 @@ async def test_setup_hardware_integration(
|
|||||||
) as mock_setup_entry,
|
) as mock_setup_entry,
|
||||||
):
|
):
|
||||||
result = await async_setup_component(hass, "hassio", {"hassio": {}})
|
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 result
|
||||||
assert aioclient_mock.call_count == 19
|
assert aioclient_mock.call_count == 19
|
||||||
|
@ -44,7 +44,7 @@ async def test_setup_entry(
|
|||||||
),
|
),
|
||||||
):
|
):
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
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
|
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)
|
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
|
assert len(mock_get_os_info.mock_calls) == 1
|
||||||
|
|
||||||
# Finish setting up ZHA
|
# 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)
|
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
|
assert len(mock_get_os_info.mock_calls) == 1
|
||||||
|
|
||||||
# Finish setting up ZHA
|
# 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)
|
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
|
assert len(mock_get_os_info.mock_calls) == 1
|
||||||
|
|
||||||
# Finish setting up ZHA
|
# Finish setting up ZHA
|
||||||
|
@ -722,7 +722,7 @@ async def test_integration_discovery(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
with patch("homeassistant.components.plex.config_flow.GDM", return_value=mock_gdm):
|
with patch("homeassistant.components.plex.config_flow.GDM", return_value=mock_gdm):
|
||||||
await config_flow.async_discover(hass)
|
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()
|
flows = hass.config_entries.flow.async_progress()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user