mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Explicitly pass in the config_entry in ukraine_alarm coordinator (#137886)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
0cbec3c4bb
commit
b54b90a604
@ -3,7 +3,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_REGION
|
|
||||||
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
|
||||||
|
|
||||||
@ -13,11 +12,9 @@ from .coordinator import UkraineAlarmDataUpdateCoordinator
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Ukraine Alarm as config entry."""
|
"""Set up Ukraine Alarm as config entry."""
|
||||||
region_id = entry.data[CONF_REGION]
|
|
||||||
|
|
||||||
websession = async_get_clientsession(hass)
|
websession = async_get_clientsession(hass)
|
||||||
|
|
||||||
coordinator = UkraineAlarmDataUpdateCoordinator(hass, websession, region_id)
|
coordinator = UkraineAlarmDataUpdateCoordinator(hass, entry, websession)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
||||||
|
@ -10,6 +10,8 @@ import aiohttp
|
|||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from uasiren.client import Client
|
from uasiren.client import Client
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_REGION
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
@ -23,17 +25,25 @@ UPDATE_INTERVAL = timedelta(seconds=10)
|
|||||||
class UkraineAlarmDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class UkraineAlarmDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Class to manage fetching Ukraine Alarm API."""
|
"""Class to manage fetching Ukraine Alarm API."""
|
||||||
|
|
||||||
|
config_entry: ConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
session: ClientSession,
|
session: ClientSession,
|
||||||
region_id: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.region_id = region_id
|
self.region_id = config_entry.data[CONF_REGION]
|
||||||
self.uasiren = Client(session)
|
self.uasiren = Client(session)
|
||||||
|
|
||||||
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL)
|
super().__init__(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
|
name=DOMAIN,
|
||||||
|
update_interval=UPDATE_INTERVAL,
|
||||||
|
)
|
||||||
|
|
||||||
async def _async_update_data(self) -> dict[str, Any]:
|
async def _async_update_data(self) -> dict[str, Any]:
|
||||||
"""Update data via library."""
|
"""Update data via library."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user