From 13d6ebaabfe92a6410dc16f8a35920ccd0728438 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 26 Mar 2024 22:55:59 -1000 Subject: [PATCH] Avoid delaying automation/script startup for sample blueprints (#114277) Avoid delaying automation/script startup to check if the blueprint folder exists automations and script both populate sample blueprints if none exist The check to see if the blueprint folder exists always had to create an executor job which would delay startup a bit if the executor was busy. Since we do not need the sample blueprints to be populated until the start event, we can run this in a task. --- homeassistant/components/automation/__init__.py | 9 +++++++-- homeassistant/components/script/__init__.py | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 3942ca6368f..0bd2ed87d20 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -298,8 +298,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await _async_process_config(hass, config, component) # Add some default blueprints to blueprints/automation, does nothing - # if blueprints/automation already exists - await async_get_blueprints(hass).async_populate() + # if blueprints/automation already exists but still has to create + # an executor job to check if the folder exists so we run it in a + # separate task to avoid waiting for it to finish setting up + # since a tracked task will be waited at the end of startup + hass.async_create_task( + async_get_blueprints(hass).async_populate(), eager_start=True + ) async def trigger_service_handler( entity: BaseAutomationEntity, service_call: ServiceCall diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index 79ed69d2cdf..82752ed15bc 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -223,8 +223,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await _async_process_config(hass, config, component) # Add some default blueprints to blueprints/script, does nothing - # if blueprints/script already exists - await async_get_blueprints(hass).async_populate() + # if blueprints/script already exists but still has to create + # an executor job to check if the folder exists so we run it in a + # separate task to avoid waiting for it to finish setting up + # since a tracked task will be waited at the end of startup + hass.async_create_task( + async_get_blueprints(hass).async_populate(), eager_start=True + ) async def reload_service(service: ServiceCall) -> None: """Call a service to reload scripts."""