mirror of
https://github.com/home-assistant/core.git
synced 2026-06-05 23:16:33 +01:00
b2fb6c0a68
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""The seventeentrack component."""
|
|
|
|
from pyseventeentrack import Client as SeventeenTrackClient
|
|
from pyseventeentrack.errors import SeventeenTrackError
|
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
from homeassistant.helpers import config_validation as cv
|
|
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
|
from homeassistant.helpers.typing import ConfigType
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import SeventeenTrackConfigEntry, SeventeenTrackCoordinator
|
|
from .services import async_setup_services
|
|
|
|
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
|
|
|
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
|
|
|
|
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
"""Set up the 17Track component."""
|
|
|
|
async_setup_services(hass)
|
|
|
|
return True
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant, entry: SeventeenTrackConfigEntry
|
|
) -> bool:
|
|
"""Set up 17Track from a config entry."""
|
|
|
|
session = async_create_clientsession(hass)
|
|
client = SeventeenTrackClient(session=session)
|
|
|
|
try:
|
|
await client.profile.login(entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD])
|
|
except SeventeenTrackError as err:
|
|
raise ConfigEntryNotReady from err
|
|
|
|
seventeen_coordinator = SeventeenTrackCoordinator(hass, entry, client)
|
|
|
|
await seventeen_coordinator.async_config_entry_first_refresh()
|
|
|
|
entry.runtime_data = seventeen_coordinator
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|