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.
pull/114285/head
J. Nick Koston 2024-03-26 22:55:59 -10:00 committed by GitHub
parent da78dbb61f
commit 13d6ebaabf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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."""