mirror of
https://github.com/home-assistant/core.git
synced 2026-02-21 10:27:52 +00:00
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""The wsdot component."""
|
|
|
|
import wsdot as wsdot_api
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_API_KEY, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryError
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
PLATFORMS = [Platform.SENSOR]
|
|
|
|
|
|
type WsdotConfigEntry = ConfigEntry[wsdot_api.WsdotTravelTimes]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: WsdotConfigEntry) -> bool:
|
|
"""Set up wsdot as config entry."""
|
|
session = async_get_clientsession(hass)
|
|
api_key = entry.data[CONF_API_KEY]
|
|
wsdot_travel_times = wsdot_api.WsdotTravelTimes(api_key=api_key, session=session)
|
|
try:
|
|
# The only way to validate the provided API key is to request data
|
|
# we don't need the data here, only the non-exception
|
|
await wsdot_travel_times.get_all_travel_times()
|
|
except wsdot_api.WsdotTravelError as api_error:
|
|
raise ConfigEntryError("Bad auth") from api_error
|
|
entry.runtime_data = wsdot_travel_times
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|