1 """The Local To-do integration."""
3 from __future__
import annotations
5 from pathlib
import Path
13 from .const
import CONF_STORAGE_KEY, CONF_TODO_LIST_NAME
14 from .store
import LocalTodoListStore
16 PLATFORMS: list[Platform] = [Platform.TODO]
18 STORAGE_PATH =
".storage/local_todo.{key}.ics"
20 type LocalTodoConfigEntry = ConfigEntry[LocalTodoListStore]
24 """Set up Local To-do from a config entry."""
25 path = Path(hass.config.path(STORAGE_PATH.format(key=entry.data[CONF_STORAGE_KEY])))
28 await store.async_load()
29 except OSError
as err:
32 entry.runtime_data = store
34 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
40 """Unload a config entry."""
41 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
45 """Handle removal of an entry."""
46 key =
slugify(entry.data[CONF_TODO_LIST_NAME])
47 path = Path(hass.config.path(STORAGE_PATH.format(key=key)))
49 def unlink(path: Path) ->
None:
50 path.unlink(missing_ok=
True)
52 await hass.async_add_executor_job(unlink, path)
bool async_setup_entry(HomeAssistant hass, LocalTodoConfigEntry entry)
None async_remove_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
str slugify(str|None text, *str separator="_")