mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use runtime_data in buienradar (#129087)
This commit is contained in:
parent
f63332a7aa
commit
30edb2a44f
@ -6,25 +6,26 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .util import BrData
|
||||
|
||||
PLATFORMS = [Platform.CAMERA, Platform.SENSOR, Platform.WEATHER]
|
||||
|
||||
type BuienRadarConfigEntry = ConfigEntry[dict[Platform, BrData]]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: BuienRadarConfigEntry) -> bool:
|
||||
"""Set up buienradar from a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {}).setdefault(entry.entry_id, {})
|
||||
entry.runtime_data = {}
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
entry.async_on_unload(entry.add_update_listener(async_update_options))
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: BuienRadarConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
entry_data = hass.data[DOMAIN].pop(entry.entry_id)
|
||||
for platform in PLATFORMS:
|
||||
if (data := entry_data.get(platform)) and (
|
||||
if (data := entry.runtime_data.get(platform)) and (
|
||||
unsub := data.unsub_schedule_update
|
||||
):
|
||||
unsub()
|
||||
@ -32,6 +33,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return unload_ok
|
||||
|
||||
|
||||
async def async_update_options(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
async def async_update_options(
|
||||
hass: HomeAssistant, config_entry: BuienRadarConfigEntry
|
||||
) -> None:
|
||||
"""Update options."""
|
||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
|
@ -10,13 +10,13 @@ import aiohttp
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.camera import Camera
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_COUNTRY_CODE, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import BuienRadarConfigEntry
|
||||
from .const import CONF_DELTA, DEFAULT_COUNTRY, DEFAULT_DELTA, DEFAULT_DIMENSION
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -29,7 +29,9 @@ SUPPORTED_COUNTRY_CODES = ["NL", "BE"]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: BuienRadarConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up buienradar radar-loop camera component."""
|
||||
config = entry.data
|
||||
|
@ -28,7 +28,6 @@ from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_LATITUDE,
|
||||
@ -49,10 +48,10 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import BuienRadarConfigEntry
|
||||
from .const import (
|
||||
CONF_TIMEFRAME,
|
||||
DEFAULT_TIMEFRAME,
|
||||
DOMAIN,
|
||||
STATE_CONDITION_CODES,
|
||||
STATE_CONDITIONS,
|
||||
STATE_DETAILED_CONDITIONS,
|
||||
@ -690,7 +689,9 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: BuienRadarConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Create the buienradar sensor."""
|
||||
config = entry.data
|
||||
@ -723,7 +724,7 @@ async def async_setup_entry(
|
||||
|
||||
# create weather data:
|
||||
data = BrData(hass, coordinates, timeframe, entities)
|
||||
hass.data[DOMAIN][entry.entry_id][Platform.SENSOR] = data
|
||||
entry.runtime_data[Platform.SENSOR] = data
|
||||
await data.async_update()
|
||||
|
||||
async_add_entities(entities)
|
||||
|
@ -39,7 +39,6 @@ from homeassistant.components.weather import (
|
||||
WeatherEntity,
|
||||
WeatherEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
@ -54,8 +53,8 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
# Reuse data and API logic from the sensor implementation
|
||||
from .const import DEFAULT_TIMEFRAME, DOMAIN
|
||||
from . import BuienRadarConfigEntry
|
||||
from .const import DEFAULT_TIMEFRAME
|
||||
from .util import BrData
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -93,7 +92,9 @@ CONDITION_MAP = {
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: BuienRadarConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the buienradar platform."""
|
||||
config = entry.data
|
||||
@ -113,7 +114,7 @@ async def async_setup_entry(
|
||||
|
||||
# create weather data:
|
||||
data = BrData(hass, coordinates, DEFAULT_TIMEFRAME, entities)
|
||||
hass.data[DOMAIN][entry.entry_id][Platform.WEATHER] = data
|
||||
entry.runtime_data[Platform.WEATHER] = data
|
||||
await data.async_update()
|
||||
|
||||
async_add_entities(entities)
|
||||
|
Loading…
x
Reference in New Issue
Block a user