mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use runtime_data in hvv_departures (#144951)
This commit is contained in:
parent
177afea5ad
commit
f50afae1c3
@ -1,17 +1,15 @@
|
||||
"""The HVV integration."""
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
|
||||
from .const import DOMAIN
|
||||
from .hub import GTIHub
|
||||
from .hub import GTIHub, HVVConfigEntry
|
||||
|
||||
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: HVVConfigEntry) -> bool:
|
||||
"""Set up HVV from a config entry."""
|
||||
|
||||
hub = GTIHub(
|
||||
@ -21,14 +19,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
aiohttp_client.async_get_clientsession(hass),
|
||||
)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = hub
|
||||
entry.runtime_data = hub
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: HVVConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -14,7 +14,6 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
@ -25,17 +24,18 @@ from homeassistant.helpers.update_coordinator import (
|
||||
)
|
||||
|
||||
from .const import ATTRIBUTION, CONF_STATION, DOMAIN, MANUFACTURER
|
||||
from .hub import HVVConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: HVVConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the binary_sensor platform."""
|
||||
hub = hass.data[DOMAIN][entry.entry_id]
|
||||
hub = entry.runtime_data
|
||||
station_name = entry.data[CONF_STATION]["name"]
|
||||
station = entry.data[CONF_STATION]
|
||||
|
||||
|
@ -9,18 +9,13 @@ from pygti.auth import GTI_DEFAULT_HOST
|
||||
from pygti.exceptions import CannotConnect, InvalidAuth
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import (
|
||||
ConfigEntry,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
OptionsFlow,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
|
||||
from homeassistant.const import CONF_HOST, CONF_OFFSET, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||
|
||||
from .const import CONF_FILTER, CONF_REAL_TIME, CONF_STATION, DOMAIN
|
||||
from .hub import GTIHub
|
||||
from .hub import GTIHub, HVVConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -137,7 +132,7 @@ class HVVDeparturesConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: HVVConfigEntry,
|
||||
) -> OptionsFlowHandler:
|
||||
"""Get options flow."""
|
||||
return OptionsFlowHandler()
|
||||
@ -146,6 +141,8 @@ class HVVDeparturesConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
class OptionsFlowHandler(OptionsFlow):
|
||||
"""Options flow handler."""
|
||||
|
||||
config_entry: HVVConfigEntry
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize HVV Departures options flow."""
|
||||
self.departure_filters: dict[str, Any] = {}
|
||||
@ -157,7 +154,7 @@ class OptionsFlowHandler(OptionsFlow):
|
||||
errors = {}
|
||||
if not self.departure_filters:
|
||||
departure_list = {}
|
||||
hub: GTIHub = self.hass.data[DOMAIN][self.config_entry.entry_id]
|
||||
hub = self.config_entry.runtime_data
|
||||
|
||||
try:
|
||||
departure_list = await hub.gti.departureList(
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
from pygti.gti import GTI, Auth
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
||||
type HVVConfigEntry = ConfigEntry[GTIHub]
|
||||
|
||||
|
||||
class GTIHub:
|
||||
"""GTI Hub."""
|
||||
|
@ -8,7 +8,6 @@ from aiohttp import ClientConnectorError
|
||||
from pygti.exceptions import InvalidAuth
|
||||
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ID, CONF_OFFSET
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
@ -18,6 +17,7 @@ from homeassistant.util import Throttle
|
||||
from homeassistant.util.dt import get_time_zone, utcnow
|
||||
|
||||
from .const import ATTRIBUTION, CONF_REAL_TIME, CONF_STATION, DOMAIN, MANUFACTURER
|
||||
from .hub import HVVConfigEntry
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
|
||||
MAX_LIST = 20
|
||||
@ -41,11 +41,11 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: HVVConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the sensor platform."""
|
||||
hub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
hub = config_entry.runtime_data
|
||||
|
||||
session = aiohttp_client.async_get_clientsession(hass)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user