1 """The Local Calendar integration."""
3 from __future__
import annotations
6 from pathlib
import Path
14 from .const
import CONF_CALENDAR_NAME, CONF_STORAGE_KEY, DOMAIN, STORAGE_PATH
15 from .store
import LocalCalendarStore
17 _LOGGER = logging.getLogger(__name__)
20 PLATFORMS: list[Platform] = [Platform.CALENDAR]
24 """Set up Local Calendar from a config entry."""
25 hass.data.setdefault(DOMAIN, {})
27 if CONF_STORAGE_KEY
not in entry.data:
28 hass.config_entries.async_update_entry(
32 CONF_STORAGE_KEY:
slugify(entry.data[CONF_CALENDAR_NAME]),
36 path = Path(hass.config.path(STORAGE_PATH.format(key=entry.data[CONF_STORAGE_KEY])))
39 await store.async_load()
40 except OSError
as err:
43 hass.data[DOMAIN][entry.entry_id] = store
45 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
51 """Unload a config entry."""
52 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
53 hass.data[DOMAIN].pop(entry.entry_id)
59 """Handle removal of an entry."""
60 key =
slugify(entry.data[CONF_CALENDAR_NAME])
61 path = Path(hass.config.path(STORAGE_PATH.format(key=key)))
63 def unlink(path: Path) ->
None:
64 path.unlink(missing_ok=
True)
66 await hass.async_add_executor_job(unlink, path)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
None async_remove_entry(HomeAssistant hass, ConfigEntry entry)
str slugify(str|None text, *str separator="_")