Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The todoist integration."""
2 
3 import datetime
4 import logging
5 
6 from todoist_api_python.api_async import TodoistAPIAsync
7 
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.const import CONF_TOKEN, Platform
10 from homeassistant.core import HomeAssistant
11 
12 from .const import DOMAIN
13 from .coordinator import TodoistCoordinator
14 
15 _LOGGER = logging.getLogger(__name__)
16 
17 SCAN_INTERVAL = datetime.timedelta(minutes=1)
18 
19 
20 PLATFORMS: list[Platform] = [Platform.CALENDAR, Platform.TODO]
21 
22 
23 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
24  """Set up todoist from a config entry."""
25 
26  token = entry.data[CONF_TOKEN]
27  api = TodoistAPIAsync(token)
28  coordinator = TodoistCoordinator(hass, _LOGGER, entry, SCAN_INTERVAL, api, token)
29  await coordinator.async_config_entry_first_refresh()
30 
31  hass.data.setdefault(DOMAIN, {})
32  hass.data[DOMAIN][entry.entry_id] = coordinator
33 
34  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
35 
36  return True
37 
38 
39 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
40  """Unload a config entry."""
41  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
42  hass.data[DOMAIN].pop(entry.entry_id)
43 
44  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:39
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:23