Reduce hassio setup time (#111686)

Reduce supervisor setup time

The two calls that take the most time are calling
push_config ~0.4s and updating the api ~0.35s and
can be run concurrently
This commit is contained in:
J. Nick Koston 2024-02-27 16:30:48 -10:00 committed by GitHub
parent e62b709dea
commit e74e1e3008
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,6 +41,7 @@ from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util.async_ import create_eager_task
from homeassistant.util.dt import now
from .addon_manager import AddonError, AddonInfo, AddonManager, AddonState # noqa: F401
@ -490,7 +491,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, push_config)
await push_config(None)
push_config_task = hass.async_create_task(push_config(None), eager_start=True)
async def async_service_handler(service: ServiceCall) -> None:
"""Handle service calls for Hass.io."""
@ -533,12 +534,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
hass.data[DATA_SUPERVISOR_INFO],
hass.data[DATA_OS_INFO],
) = await asyncio.gather(
hassio.get_info(),
hassio.get_host_info(),
hassio.get_store(),
hassio.get_core_info(),
hassio.get_supervisor_info(),
hassio.get_os_info(),
create_eager_task(hassio.get_info()),
create_eager_task(hassio.get_host_info()),
create_eager_task(hassio.get_store()),
create_eager_task(hassio.get_core_info()),
create_eager_task(hassio.get_supervisor_info()),
create_eager_task(hassio.get_os_info()),
)
except HassioAPIError as err:
@ -552,6 +553,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
# Fetch data
await update_info_data()
await push_config_task
async def _async_stop(hass: HomeAssistant, restart: bool) -> None:
"""Stop or restart home assistant."""
@ -605,7 +607,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
_async_setup_hardware_integration()
hass.async_create_task(
hass.config_entries.flow.async_init(DOMAIN, context={"source": "system"})
hass.config_entries.flow.async_init(DOMAIN, context={"source": "system"}),
eager_start=True,
)
# Start listening for problems with supervisor and making issues