core/homeassistant/components/tautulli/__init__.py

41 lines
1.5 KiB
Python

"""The Tautulli integration."""
from __future__ import annotations
from pytautulli import PyTautulli, PyTautulliHostConfiguration
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .coordinator import TautulliDataUpdateCoordinator
PLATFORMS = [Platform.SENSOR]
type TautulliConfigEntry = ConfigEntry[TautulliDataUpdateCoordinator]
async def async_setup_entry(hass: HomeAssistant, entry: TautulliConfigEntry) -> bool:
"""Set up Tautulli from a config entry."""
host_configuration = PyTautulliHostConfiguration(
api_token=entry.data[CONF_API_KEY],
url=entry.data[CONF_URL],
verify_ssl=entry.data[CONF_VERIFY_SSL],
)
api_client = PyTautulli(
host_configuration=host_configuration,
session=async_get_clientsession(hass, entry.data[CONF_VERIFY_SSL]),
)
entry.runtime_data = TautulliDataUpdateCoordinator(
hass, host_configuration, api_client
)
await entry.runtime_data.async_config_entry_first_refresh()
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: TautulliConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)