Move analytics setup to later stage to avoid delaying frontend startup (#112535)
Move analytics setup to stage 1 to avoid delaying frontend startup analytics was only needed in the frontend startup phase for onboarding. Its very unlikely the user will be able to complete the onboarding steps and get to the analytics screen before analytics is done loading so we can delay loading it until stage 1. To be absolutely sure that it is ready, the core_config step in onboarding will wait to proceed if it is some how still being setup
This commit is contained in:
parent
67a177679e
commit
1772e5257c
4 changed files with 42 additions and 9 deletions
|
@ -141,6 +141,7 @@ DEFAULT_INTEGRATIONS = {
|
|||
# These integrations are set up unless recovery mode is activated.
|
||||
#
|
||||
# Integrations providing core functionality:
|
||||
"analytics", # Needed for onboarding
|
||||
"application_credentials",
|
||||
"backup",
|
||||
"frontend",
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Home Assistant Onboarding",
|
||||
"after_dependencies": ["hassio"],
|
||||
"codeowners": ["@home-assistant/core"],
|
||||
"dependencies": ["analytics", "auth", "http", "person"],
|
||||
"dependencies": ["auth", "http", "person"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/onboarding",
|
||||
"integration_type": "system",
|
||||
"quality_scale": "internal"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Coroutine
|
||||
from http import HTTPStatus
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
|
@ -20,6 +21,8 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.helpers import area_registry as ar
|
||||
from homeassistant.helpers.system_info import async_get_system_info
|
||||
from homeassistant.helpers.translation import async_get_translations
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.async_ import create_eager_task
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import OnboadingStorage
|
||||
|
@ -215,15 +218,22 @@ class CoreConfigOnboardingView(_BaseOnboardingView):
|
|||
):
|
||||
onboard_integrations.append("rpi_power")
|
||||
|
||||
# Set up integrations after onboarding
|
||||
await asyncio.gather(
|
||||
*(
|
||||
hass.config_entries.flow.async_init(
|
||||
domain, context={"source": "onboarding"}
|
||||
)
|
||||
for domain in onboard_integrations
|
||||
coros: list[Coroutine[Any, Any, Any]] = [
|
||||
hass.config_entries.flow.async_init(
|
||||
domain, context={"source": "onboarding"}
|
||||
)
|
||||
)
|
||||
for domain in onboard_integrations
|
||||
]
|
||||
|
||||
if "analytics" not in hass.config.components:
|
||||
# If by some chance that analytics has not finished
|
||||
# setting up, wait for it here so its ready for the
|
||||
# next step.
|
||||
coros.append(async_setup_component(hass, "analytics", {}))
|
||||
|
||||
# Set up integrations after onboarding and ensure
|
||||
# analytics is ready for the next step.
|
||||
await asyncio.gather(*(create_eager_task(coro) for coro in coros))
|
||||
|
||||
return self.json({})
|
||||
|
||||
|
|
|
@ -567,6 +567,28 @@ async def test_onboarding_core_no_rpi_power(
|
|||
assert not rpi_power_state
|
||||
|
||||
|
||||
async def test_onboarding_core_ensures_analytics_loaded(
|
||||
hass: HomeAssistant,
|
||||
hass_storage: dict[str, Any],
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_default_integrations,
|
||||
) -> None:
|
||||
"""Test finishing the core step ensures analytics is ready."""
|
||||
mock_storage(hass_storage, {"done": [const.STEP_USER]})
|
||||
assert "analytics" not in hass.config.components
|
||||
|
||||
assert await async_setup_component(hass, "onboarding", {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
client = await hass_client()
|
||||
resp = await client.post("/api/onboarding/core_config")
|
||||
|
||||
assert resp.status == 200
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert "analytics" in hass.config.components
|
||||
|
||||
|
||||
async def test_onboarding_analytics(
|
||||
hass: HomeAssistant,
|
||||
hass_storage: dict[str, Any],
|
||||
|
|
Loading…
Add table
Reference in a new issue