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