47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""The NMBS component."""
|
|
|
|
import logging
|
|
|
|
from pyrail import iRail
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import config_validation as cv
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
from homeassistant.helpers.typing import ConfigType
|
|
|
|
from .const import DOMAIN
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
PLATFORMS = [Platform.SENSOR]
|
|
|
|
|
|
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
|
|
|
|
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
"""Set up the NMBS component."""
|
|
|
|
api_client = iRail(session=async_get_clientsession(hass))
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
station_response = await api_client.get_stations()
|
|
if station_response is None:
|
|
return False
|
|
hass.data[DOMAIN] = station_response.stations
|
|
|
|
return True
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up NMBS from a config entry."""
|
|
|
|
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)
|