Make sure IQVIA data storage conforms to standards (#57811)
This commit is contained in:
parent
024c892b2a
commit
5c3d2a5071
3 changed files with 12 additions and 13 deletions
|
@ -24,7 +24,6 @@ from homeassistant.helpers.update_coordinator import (
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_ZIP_CODE,
|
CONF_ZIP_CODE,
|
||||||
DATA_COORDINATOR,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
TYPE_ALLERGY_FORECAST,
|
TYPE_ALLERGY_FORECAST,
|
||||||
|
@ -45,7 +44,7 @@ PLATFORMS = ["sensor"]
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up IQVIA as config entry."""
|
"""Set up IQVIA as config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
coordinators = {}
|
hass.data[DOMAIN][entry.entry_id] = {}
|
||||||
|
|
||||||
if not entry.unique_id:
|
if not entry.unique_id:
|
||||||
# If the config entry doesn't already have a unique ID, set one:
|
# If the config entry doesn't already have a unique ID, set one:
|
||||||
|
@ -67,7 +66,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|
||||||
return cast(Dict[str, Any], data)
|
return cast(Dict[str, Any], data)
|
||||||
|
|
||||||
|
coordinators = {}
|
||||||
init_data_update_tasks = []
|
init_data_update_tasks = []
|
||||||
|
|
||||||
for sensor_type, api_coro in (
|
for sensor_type, api_coro in (
|
||||||
(TYPE_ALLERGY_FORECAST, client.allergens.extended),
|
(TYPE_ALLERGY_FORECAST, client.allergens.extended),
|
||||||
(TYPE_ALLERGY_INDEX, client.allergens.current),
|
(TYPE_ALLERGY_INDEX, client.allergens.current),
|
||||||
|
@ -93,7 +94,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
# API calls fail:
|
# API calls fail:
|
||||||
raise ConfigEntryNotReady()
|
raise ConfigEntryNotReady()
|
||||||
|
|
||||||
hass.data[DOMAIN].setdefault(DATA_COORDINATOR, {})[entry.entry_id] = coordinators
|
hass.data[DOMAIN][entry.entry_id] = coordinators
|
||||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -103,7 +104,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload an OpenUV config entry."""
|
"""Unload an OpenUV config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,7 +141,7 @@ class IQVIAEntity(CoordinatorEntity):
|
||||||
|
|
||||||
if self.entity_description.key == TYPE_ALLERGY_FORECAST:
|
if self.entity_description.key == TYPE_ALLERGY_FORECAST:
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
self.hass.data[DOMAIN][DATA_COORDINATOR][self._entry.entry_id][
|
self.hass.data[DOMAIN][self._entry.entry_id][
|
||||||
TYPE_ALLERGY_OUTLOOK
|
TYPE_ALLERGY_OUTLOOK
|
||||||
].async_add_listener(self._handle_coordinator_update)
|
].async_add_listener(self._handle_coordinator_update)
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,8 +7,6 @@ DOMAIN = "iqvia"
|
||||||
|
|
||||||
CONF_ZIP_CODE = "zip_code"
|
CONF_ZIP_CODE = "zip_code"
|
||||||
|
|
||||||
DATA_COORDINATOR = "coordinator"
|
|
||||||
|
|
||||||
TYPE_ALLERGY_FORECAST = "allergy_average_forecasted"
|
TYPE_ALLERGY_FORECAST = "allergy_average_forecasted"
|
||||||
TYPE_ALLERGY_INDEX = "allergy_index"
|
TYPE_ALLERGY_INDEX = "allergy_index"
|
||||||
TYPE_ALLERGY_OUTLOOK = "allergy_outlook"
|
TYPE_ALLERGY_OUTLOOK = "allergy_outlook"
|
||||||
|
|
|
@ -18,7 +18,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import IQVIAEntity
|
from . import IQVIAEntity
|
||||||
from .const import (
|
from .const import (
|
||||||
DATA_COORDINATOR,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
TYPE_ALLERGY_FORECAST,
|
TYPE_ALLERGY_FORECAST,
|
||||||
TYPE_ALLERGY_INDEX,
|
TYPE_ALLERGY_INDEX,
|
||||||
|
@ -133,7 +132,7 @@ async def async_setup_entry(
|
||||||
"""Set up IQVIA sensors based on a config entry."""
|
"""Set up IQVIA sensors based on a config entry."""
|
||||||
sensors: list[ForecastSensor | IndexSensor] = [
|
sensors: list[ForecastSensor | IndexSensor] = [
|
||||||
ForecastSensor(
|
ForecastSensor(
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][
|
hass.data[DOMAIN][entry.entry_id][
|
||||||
API_CATEGORY_MAPPING.get(description.key, description.key)
|
API_CATEGORY_MAPPING.get(description.key, description.key)
|
||||||
],
|
],
|
||||||
entry,
|
entry,
|
||||||
|
@ -144,7 +143,7 @@ async def async_setup_entry(
|
||||||
sensors.extend(
|
sensors.extend(
|
||||||
[
|
[
|
||||||
IndexSensor(
|
IndexSensor(
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][
|
hass.data[DOMAIN][entry.entry_id][
|
||||||
API_CATEGORY_MAPPING.get(description.key, description.key)
|
API_CATEGORY_MAPPING.get(description.key, description.key)
|
||||||
],
|
],
|
||||||
entry,
|
entry,
|
||||||
|
@ -206,9 +205,9 @@ class ForecastSensor(IQVIAEntity, SensorEntity):
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.entity_description.key == TYPE_ALLERGY_FORECAST:
|
if self.entity_description.key == TYPE_ALLERGY_FORECAST:
|
||||||
outlook_coordinator = self.hass.data[DOMAIN][DATA_COORDINATOR][
|
outlook_coordinator = self.hass.data[DOMAIN][self._entry.entry_id][
|
||||||
self._entry.entry_id
|
TYPE_ALLERGY_OUTLOOK
|
||||||
][TYPE_ALLERGY_OUTLOOK]
|
]
|
||||||
|
|
||||||
if not outlook_coordinator.last_update_success:
|
if not outlook_coordinator.last_update_success:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue