mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Explicitly pass in the config_entry in nina coordinator (#138069)
* explicitly pass in the config_entry in coordinator * add accidential removed typing
This commit is contained in:
parent
b1f3068b41
commit
233f6416f2
@ -11,7 +11,6 @@ from .const import (
|
|||||||
CONF_AREA_FILTER,
|
CONF_AREA_FILTER,
|
||||||
CONF_FILTER_CORONA,
|
CONF_FILTER_CORONA,
|
||||||
CONF_HEADLINE_FILTER,
|
CONF_HEADLINE_FILTER,
|
||||||
CONF_REGIONS,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
NO_MATCH_REGEX,
|
NO_MATCH_REGEX,
|
||||||
)
|
)
|
||||||
@ -22,9 +21,6 @@ PLATFORMS: list[str] = [Platform.BINARY_SENSOR]
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up platform from a ConfigEntry."""
|
"""Set up platform from a ConfigEntry."""
|
||||||
|
|
||||||
regions: dict[str, str] = entry.data[CONF_REGIONS]
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -39,12 +35,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
new_data = {**entry.data, CONF_AREA_FILTER: ALL_MATCH_REGEX}
|
new_data = {**entry.data, CONF_AREA_FILTER: ALL_MATCH_REGEX}
|
||||||
hass.config_entries.async_update_entry(entry, data=new_data)
|
hass.config_entries.async_update_entry(entry, data=new_data)
|
||||||
|
|
||||||
coordinator = NINADataUpdateCoordinator(
|
coordinator = NINADataUpdateCoordinator(hass, entry)
|
||||||
hass,
|
|
||||||
regions,
|
|
||||||
entry.data[CONF_HEADLINE_FILTER],
|
|
||||||
entry.data[CONF_AREA_FILTER],
|
|
||||||
)
|
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
|
@ -9,11 +9,19 @@ from typing import Any
|
|||||||
|
|
||||||
from pynina import ApiError, Nina
|
from pynina import ApiError, Nina
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
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.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
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
|
@dataclass
|
||||||
@ -39,23 +47,29 @@ class NINADataUpdateCoordinator(
|
|||||||
):
|
):
|
||||||
"""Class to manage fetching NINA data API."""
|
"""Class to manage fetching NINA data API."""
|
||||||
|
|
||||||
|
config_entry: ConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
regions: dict[str, str],
|
config_entry: ConfigEntry,
|
||||||
headline_filter: str,
|
|
||||||
area_filter: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self._regions: dict[str, str] = regions
|
|
||||||
self._nina: Nina = Nina(async_get_clientsession(hass))
|
self._nina: Nina = Nina(async_get_clientsession(hass))
|
||||||
self.headline_filter: str = headline_filter
|
self.headline_filter: str = config_entry.data[CONF_HEADLINE_FILTER]
|
||||||
self.area_filter: str = area_filter
|
self.area_filter: str = config_entry.data[CONF_AREA_FILTER]
|
||||||
|
|
||||||
|
regions: dict[str, str] = config_entry.data[CONF_REGIONS]
|
||||||
for region in regions:
|
for region in regions:
|
||||||
self._nina.addRegion(region)
|
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]]:
|
async def _async_update_data(self) -> dict[str, list[NinaWarningData]]:
|
||||||
"""Update data."""
|
"""Update data."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user