mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Store runtime data inside the config entry in Local ToDo (#116818)
store runtime data inside the config entry
This commit is contained in:
parent
0380116ef6
commit
ddf9d6c53a
@ -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:
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user