diff --git a/homeassistant/components/local_todo/__init__.py b/homeassistant/components/local_todo/__init__.py index 8245822bd9f..c01f5a748ec 100644 --- a/homeassistant/components/local_todo/__init__.py +++ b/homeassistant/components/local_todo/__init__.py @@ -10,19 +10,18 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.util import slugify -from .const import CONF_STORAGE_KEY, CONF_TODO_LIST_NAME, DOMAIN +from .const import CONF_STORAGE_KEY, CONF_TODO_LIST_NAME from .store import LocalTodoListStore PLATFORMS: list[Platform] = [Platform.TODO] STORAGE_PATH = ".storage/local_todo.{key}.ics" +LocalTodoConfigEntry = ConfigEntry[LocalTodoListStore] -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: + +async def async_setup_entry(hass: HomeAssistant, entry: LocalTodoConfigEntry) -> bool: """Set up Local To-do from a config entry.""" - - hass.data.setdefault(DOMAIN, {}) - path = Path(hass.config.path(STORAGE_PATH.format(key=entry.data[CONF_STORAGE_KEY]))) store = LocalTodoListStore(hass, path) try: @@ -30,7 +29,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except OSError as err: raise ConfigEntryNotReady("Failed to load file {path}: {err}") from err - hass.data[DOMAIN][entry.entry_id] = store + entry.runtime_data = store await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) @@ -39,10 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): - hass.data[DOMAIN].pop(entry.entry_id) - - return unload_ok + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: diff --git a/homeassistant/components/local_todo/todo.py b/homeassistant/components/local_todo/todo.py index ccd3d8db759..548b4fa87fe 100644 --- a/homeassistant/components/local_todo/todo.py +++ b/homeassistant/components/local_todo/todo.py @@ -14,14 +14,14 @@ from homeassistant.components.todo import ( TodoListEntity, TodoListEntityFeature, ) -from homeassistant.config_entries import ConfigEntry 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 +from . import LocalTodoConfigEntry +from .const import CONF_TODO_LIST_NAME from .store import LocalTodoListStore _LOGGER = logging.getLogger(__name__) @@ -63,12 +63,12 @@ def _migrate_calendar(calendar: Calendar) -> bool: async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: LocalTodoConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the local_todo todo platform.""" - store: LocalTodoListStore = hass.data[DOMAIN][config_entry.entry_id] + store = config_entry.runtime_data ics = await store.async_load() with async_pause_setup(hass, SetupPhases.WAIT_IMPORT_PACKAGES):