Use ConfigEntry.runtime_data to store runtime data in NINA (#146754)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
DeerMaximum 2025-06-13 18:47:21 +02:00 committed by GitHub
parent 1a5bc2c7e0
commit 434cd95a66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 10 deletions

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
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
@ -11,15 +10,14 @@ from .const import (
CONF_AREA_FILTER, CONF_AREA_FILTER,
CONF_FILTER_CORONA, CONF_FILTER_CORONA,
CONF_HEADLINE_FILTER, CONF_HEADLINE_FILTER,
DOMAIN,
NO_MATCH_REGEX, NO_MATCH_REGEX,
) )
from .coordinator import NINADataUpdateCoordinator from .coordinator import NinaConfigEntry, NINADataUpdateCoordinator
PLATFORMS: list[str] = [Platform.BINARY_SENSOR] PLATFORMS: list[str] = [Platform.BINARY_SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: NinaConfigEntry) -> bool:
"""Set up platform from a ConfigEntry.""" """Set up platform from a ConfigEntry."""
if CONF_HEADLINE_FILTER not in entry.data: if CONF_HEADLINE_FILTER not in entry.data:
filter_regex = NO_MATCH_REGEX filter_regex = NO_MATCH_REGEX
@ -41,18 +39,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
entry.async_on_unload(entry.add_update_listener(_async_update_listener)) entry.async_on_unload(entry.add_update_listener(_async_update_listener))
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator entry.runtime_data = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: NinaConfigEntry) -> bool:
"""Unload a config entry.""" """Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: async def _async_update_listener(hass: HomeAssistant, entry: NinaConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View File

@ -30,17 +30,17 @@ from .const import (
CONF_REGIONS, CONF_REGIONS,
DOMAIN, DOMAIN,
) )
from .coordinator import NINADataUpdateCoordinator from .coordinator import NinaConfigEntry, NINADataUpdateCoordinator
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
config_entry: ConfigEntry, config_entry: NinaConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback, async_add_entities: AddConfigEntryEntitiesCallback,
) -> None: ) -> None:
"""Set up entries.""" """Set up entries."""
coordinator: NINADataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id] coordinator = config_entry.runtime_data
regions: dict[str, str] = config_entry.data[CONF_REGIONS] regions: dict[str, str] = config_entry.data[CONF_REGIONS]
message_slots: int = config_entry.data[CONF_MESSAGE_SLOTS] message_slots: int = config_entry.data[CONF_MESSAGE_SLOTS]

View File

@ -23,6 +23,8 @@ from .const import (
SCAN_INTERVAL, SCAN_INTERVAL,
) )
type NinaConfigEntry = ConfigEntry[NINADataUpdateCoordinator]
@dataclass @dataclass
class NinaWarningData: class NinaWarningData: