Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local_todo blocking the event loop #116473

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions homeassistant/components/local_todo/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down