From c574d86ddbafd6c18995ad9efb297fda3ce4292c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 30 Apr 2024 15:31:09 -0500 Subject: [PATCH] Fix local_todo blocking the event loop (#116473) --- homeassistant/components/local_todo/todo.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/local_todo/todo.py b/homeassistant/components/local_todo/todo.py index 5b25abf8e21fc..ccd3d8db7596c 100644 --- a/homeassistant/components/local_todo/todo.py +++ b/homeassistant/components/local_todo/todo.py @@ -18,6 +18,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.setup import SetupPhases, async_pause_setup from homeassistant.util import dt as dt_util from .const import CONF_TODO_LIST_NAME, DOMAIN @@ -67,9 +68,16 @@ async def async_setup_entry( ) -> None: """Set up the local_todo todo platform.""" - store = hass.data[DOMAIN][config_entry.entry_id] + store: LocalTodoListStore = hass.data[DOMAIN][config_entry.entry_id] ics = await store.async_load() - calendar = IcsCalendarStream.calendar_from_ics(ics) + + with async_pause_setup(hass, SetupPhases.WAIT_IMPORT_PACKAGES): + # calendar_from_ics will dynamically load packages + # the first time it is called, so we need to do it + # in a separate thread to avoid blocking the event loop + calendar: Calendar = await hass.async_add_import_executor_job( + IcsCalendarStream.calendar_from_ics, ics + ) migrated = _migrate_calendar(calendar) calendar.prodid = PRODID