mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Make sure Flu Near You data storage conforms to standards (#57808)
This commit is contained in:
parent
43abf38d92
commit
583ae3c953
@ -15,13 +15,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import (
|
||||
CATEGORY_CDC_REPORT,
|
||||
CATEGORY_USER_REPORT,
|
||||
DATA_COORDINATOR,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
)
|
||||
from .const import CATEGORY_CDC_REPORT, CATEGORY_USER_REPORT, DOMAIN, LOGGER
|
||||
|
||||
DEFAULT_UPDATE_INTERVAL = timedelta(minutes=30)
|
||||
|
||||
@ -32,8 +26,7 @@ PLATFORMS = ["sensor"]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Flu Near You as config entry."""
|
||||
hass.data.setdefault(DOMAIN, {DATA_COORDINATOR: {}})
|
||||
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = {}
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
websession = aiohttp_client.async_get_clientsession(hass)
|
||||
client = Client(session=websession)
|
||||
@ -57,11 +50,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
return data
|
||||
|
||||
coordinators = {}
|
||||
data_init_tasks = []
|
||||
|
||||
for api_category in (CATEGORY_CDC_REPORT, CATEGORY_USER_REPORT):
|
||||
coordinator = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][
|
||||
api_category
|
||||
] = DataUpdateCoordinator(
|
||||
coordinator = coordinators[api_category] = DataUpdateCoordinator(
|
||||
hass,
|
||||
LOGGER,
|
||||
name=f"{api_category} ({latitude}, {longitude})",
|
||||
@ -71,6 +64,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
data_init_tasks.append(coordinator.async_refresh())
|
||||
|
||||
await asyncio.gather(*data_init_tasks)
|
||||
hass.data[DOMAIN][entry.entry_id] = coordinators
|
||||
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
@ -81,6 +75,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload an Flu Near You config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN][DATA_COORDINATOR].pop(entry.entry_id)
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
|
@ -4,7 +4,5 @@ import logging
|
||||
DOMAIN = "flunearyou"
|
||||
LOGGER = logging.getLogger(__package__)
|
||||
|
||||
DATA_COORDINATOR = "coordinator"
|
||||
|
||||
CATEGORY_CDC_REPORT = "cdc_report"
|
||||
CATEGORY_USER_REPORT = "user_report"
|
||||
|
@ -24,7 +24,7 @@ from homeassistant.helpers.update_coordinator import (
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
from .const import CATEGORY_CDC_REPORT, CATEGORY_USER_REPORT, DATA_COORDINATOR, DOMAIN
|
||||
from .const import CATEGORY_CDC_REPORT, CATEGORY_USER_REPORT, DOMAIN
|
||||
|
||||
ATTR_CITY = "city"
|
||||
ATTR_REPORTED_DATE = "reported_date"
|
||||
@ -122,7 +122,7 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up Flu Near You sensors based on a config entry."""
|
||||
coordinators = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id]
|
||||
coordinators = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
sensors: list[CdcSensor | UserSensor] = [
|
||||
CdcSensor(coordinators[CATEGORY_CDC_REPORT], entry, description)
|
||||
|
Loading…
x
Reference in New Issue
Block a user