mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Migrate setup to use eager tasks (#111619)
This commit is contained in:
parent
9cf874d4a0
commit
6abb8ae273
@ -29,6 +29,7 @@ from .helpers import translation
|
||||
from .helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from .helpers.typing import ConfigType, EventType
|
||||
from .util import ensure_unique_string
|
||||
from .util.async_ import create_eager_task
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -192,7 +193,7 @@ async def _async_process_dependencies(
|
||||
|
||||
dependencies_tasks = {
|
||||
dep: setup_futures.get(dep)
|
||||
or hass.loop.create_task(
|
||||
or create_eager_task(
|
||||
async_setup_component(hass, dep, config),
|
||||
name=f"setup {dep} as dependency of {integration.domain}",
|
||||
)
|
||||
@ -352,7 +353,7 @@ async def _async_setup_component( # noqa: C901
|
||||
# loaded since we try to load them in bootstrap ahead of time.
|
||||
# If for some reason the background task in bootstrap was too slow
|
||||
# or the integration was added after bootstrap, we will load them here.
|
||||
load_translations_task = asyncio.create_task(
|
||||
load_translations_task = create_eager_task(
|
||||
translation.async_load_integrations(hass, integration_set)
|
||||
)
|
||||
|
||||
@ -433,7 +434,7 @@ async def _async_setup_component( # noqa: C901
|
||||
):
|
||||
await asyncio.gather(
|
||||
*(
|
||||
asyncio.create_task(
|
||||
create_eager_task(
|
||||
entry.async_setup(hass, integration=integration),
|
||||
name=f"config entry setup {entry.title} {entry.domain} {entry.entry_id}",
|
||||
)
|
||||
@ -569,7 +570,9 @@ def _async_when_setup(
|
||||
_LOGGER.exception("Error handling when_setup callback for %s", component)
|
||||
|
||||
if component in hass.config.components:
|
||||
hass.async_create_task(when_setup(), f"when setup {component}")
|
||||
hass.async_create_task(
|
||||
when_setup(), f"when setup {component}", eager_start=True
|
||||
)
|
||||
return
|
||||
|
||||
listeners: list[CALLBACK_TYPE] = []
|
||||
|
@ -66,6 +66,7 @@ async def test_async_setup_raises_entry_auth_failed(
|
||||
|
||||
instance.list_zones.side_effect = pycfdns.AuthenticationException()
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
@ -705,6 +705,7 @@ async def test_setup_entry_no_token_reauth(hass: HomeAssistant) -> None:
|
||||
"homeassistant.components.hyperion.client.HyperionClient", return_value=client
|
||||
), patch.object(hass.config_entries.flow, "async_init") as mock_flow_init:
|
||||
assert not await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert client.async_client_disconnect.called
|
||||
mock_flow_init.assert_called_once_with(
|
||||
DOMAIN,
|
||||
@ -734,6 +735,7 @@ async def test_setup_entry_bad_token_reauth(hass: HomeAssistant) -> None:
|
||||
"homeassistant.components.hyperion.client.HyperionClient", return_value=client
|
||||
), patch.object(hass.config_entries.flow, "async_init") as mock_flow_init:
|
||||
assert not await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert client.async_client_disconnect.called
|
||||
mock_flow_init.assert_called_once_with(
|
||||
DOMAIN,
|
||||
|
@ -60,6 +60,7 @@ async def setup_rfx_test_cfg(
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
return mock_entry
|
||||
|
||||
|
||||
|
@ -130,6 +130,7 @@ async def test_reauth_started(
|
||||
side_effect=RoborockInvalidCredentials(),
|
||||
):
|
||||
await async_setup_component(hass, DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
assert mock_roborock_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
assert len(flows) == 1
|
||||
|
@ -69,4 +69,5 @@ async def test_reauth_triggered(hass: HomeAssistant) -> None:
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
assert not await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
mock_async_step_reauth.assert_called_once()
|
||||
|
@ -31,6 +31,7 @@ async def test_setup_retry(hass: HomeAssistant) -> None:
|
||||
bulb.getMac = AsyncMock(return_value=FAKE_MAC)
|
||||
|
||||
with _patch_discovery(), _patch_wizlight(device=bulb):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_time_changed(hass, utcnow() + datetime.timedelta(minutes=15))
|
||||
await hass.async_block_till_done()
|
||||
assert entry.state is config_entries.ConfigEntryState.LOADED
|
||||
|
Loading…
x
Reference in New Issue
Block a user