Files
core/homeassistant/components/seventeentrack/__init__.py
T
e0c785b2b4 Add coordinator to 17Track (#115057)
* Add coordinator to 17Track

* Add coordinator to 17Track

remove SensorEntityDescription (different PR)

* Update homeassistant/components/seventeentrack/coordinator.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/seventeentrack/sensor.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Add coordinator to 17Track

fix CR

* Add coordinator to 17Track

fix second CR

* Add coordinator to 17Track

remove commented out code + fix display name

* Add coordinator to 17Track

created a set outside _async_create_remove_entities function

* Add coordinator to 17Track

fix CR

* Add coordinator to 17Track

fix CR 2

* Update homeassistant/components/seventeentrack/coordinator.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Add coordinator to 17Track

raise UpdateFailed if API throws an exception

* Add coordinator to 17Track

merge calls

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-04-23 09:01:45 +02:00

36 lines
1.2 KiB
Python

"""The seventeentrack component."""
from py17track import Client as SeventeenTrackClient
from py17track.errors import SeventeenTrackError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN
from .coordinator import SeventeenTrackCoordinator
PLATFORMS: list[Platform] = [Platform.SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up 17Track from a config entry."""
session = async_get_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
coordinator = SeventeenTrackCoordinator(hass, client)
await coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True