Explicitly pass in the config_entry in nina coordinator (#138069)

* explicitly pass in the config_entry in coordinator

* add accidential removed typing
pull/138131/head
Michael 2025-02-09 18:32:34 +01:00 committed by GitHub
parent b1f3068b41
commit 233f6416f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 18 deletions

View File

@ -11,7 +11,6 @@ from .const import (
CONF_AREA_FILTER,
CONF_FILTER_CORONA,
CONF_HEADLINE_FILTER,
CONF_REGIONS,
DOMAIN,
NO_MATCH_REGEX,
)
@ -22,9 +21,6 @@ PLATFORMS: list[str] = [Platform.BINARY_SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up platform from a ConfigEntry."""
regions: dict[str, str] = entry.data[CONF_REGIONS]
if CONF_HEADLINE_FILTER not in entry.data:
filter_regex = NO_MATCH_REGEX
@ -39,12 +35,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
new_data = {**entry.data, CONF_AREA_FILTER: ALL_MATCH_REGEX}
hass.config_entries.async_update_entry(entry, data=new_data)
coordinator = NINADataUpdateCoordinator(
hass,
regions,
entry.data[CONF_HEADLINE_FILTER],
entry.data[CONF_AREA_FILTER],
)
coordinator = NINADataUpdateCoordinator(hass, entry)
await coordinator.async_config_entry_first_refresh()

View File

@ -9,11 +9,19 @@ from typing import Any
from pynina import ApiError, Nina
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import _LOGGER, DOMAIN, SCAN_INTERVAL
from .const import (
_LOGGER,
CONF_AREA_FILTER,
CONF_HEADLINE_FILTER,
CONF_REGIONS,
DOMAIN,
SCAN_INTERVAL,
)
@dataclass
@ -39,23 +47,29 @@ class NINADataUpdateCoordinator(
):
"""Class to manage fetching NINA data API."""
config_entry: ConfigEntry
def __init__(
self,
hass: HomeAssistant,
regions: dict[str, str],
headline_filter: str,
area_filter: str,
config_entry: ConfigEntry,
) -> None:
"""Initialize."""
self._regions: dict[str, str] = regions
self._nina: Nina = Nina(async_get_clientsession(hass))
self.headline_filter: str = headline_filter
self.area_filter: str = area_filter
self.headline_filter: str = config_entry.data[CONF_HEADLINE_FILTER]
self.area_filter: str = config_entry.data[CONF_AREA_FILTER]
regions: dict[str, str] = config_entry.data[CONF_REGIONS]
for region in regions:
self._nina.addRegion(region)
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)
super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=SCAN_INTERVAL,
)
async def _async_update_data(self) -> dict[str, list[NinaWarningData]]:
"""Update data."""