Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Tautulli integration."""
2 
3 from __future__ import annotations
4 
5 from pytautulli import PyTautulli, PyTautulliHostConfiguration
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL, Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.aiohttp_client import async_get_clientsession
11 
12 from .coordinator import TautulliDataUpdateCoordinator
13 
14 PLATFORMS = [Platform.SENSOR]
15 type TautulliConfigEntry = ConfigEntry[TautulliDataUpdateCoordinator]
16 
17 
18 async def async_setup_entry(hass: HomeAssistant, entry: TautulliConfigEntry) -> bool:
19  """Set up Tautulli from a config entry."""
20  host_configuration = PyTautulliHostConfiguration(
21  api_token=entry.data[CONF_API_KEY],
22  url=entry.data[CONF_URL],
23  verify_ssl=entry.data[CONF_VERIFY_SSL],
24  )
25  api_client = PyTautulli(
26  host_configuration=host_configuration,
27  session=async_get_clientsession(hass, entry.data[CONF_VERIFY_SSL]),
28  )
29  entry.runtime_data = TautulliDataUpdateCoordinator(
30  hass, host_configuration, api_client
31  )
32  await entry.runtime_data.async_config_entry_first_refresh()
33  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
34 
35  return True
36 
37 
38 async def async_unload_entry(hass: HomeAssistant, entry: TautulliConfigEntry) -> bool:
39  """Unload a config entry."""
40  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, TautulliConfigEntry entry)
Definition: __init__.py:38
bool async_setup_entry(HomeAssistant hass, TautulliConfigEntry entry)
Definition: __init__.py:18
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)