mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Handle unhandled IQVIA data update exception (#32144)
* Handle unhandled IQVIA data update exception * Cleanup * Ask for forgiveness, not permission * Use warning-level logs * Fix log messages
This commit is contained in:
parent
9801810552
commit
db40b2fc32
@ -134,21 +134,34 @@ class IndexSensor(IQVIAEntity):
|
|||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
if not self._iqvia.data:
|
if not self._iqvia.data:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"IQVIA didn't return data for %s; trying again later", self.name
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
data = {}
|
try:
|
||||||
if self._type in (TYPE_ALLERGY_TODAY, TYPE_ALLERGY_TOMORROW):
|
if self._type in (TYPE_ALLERGY_TODAY, TYPE_ALLERGY_TOMORROW):
|
||||||
data = self._iqvia.data[TYPE_ALLERGY_INDEX].get("Location")
|
data = self._iqvia.data[TYPE_ALLERGY_INDEX].get("Location")
|
||||||
elif self._type in (TYPE_ASTHMA_TODAY, TYPE_ASTHMA_TOMORROW):
|
elif self._type in (TYPE_ASTHMA_TODAY, TYPE_ASTHMA_TOMORROW):
|
||||||
data = self._iqvia.data[TYPE_ASTHMA_INDEX].get("Location")
|
data = self._iqvia.data[TYPE_ASTHMA_INDEX].get("Location")
|
||||||
elif self._type == TYPE_DISEASE_TODAY:
|
elif self._type == TYPE_DISEASE_TODAY:
|
||||||
data = self._iqvia.data[TYPE_DISEASE_INDEX].get("Location")
|
data = self._iqvia.data[TYPE_DISEASE_INDEX].get("Location")
|
||||||
|
except KeyError:
|
||||||
if not data:
|
_LOGGER.warning(
|
||||||
|
"IQVIA didn't return data for %s; trying again later", self.name
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
key = self._type.split("_")[-1].title()
|
key = self._type.split("_")[-1].title()
|
||||||
|
|
||||||
|
try:
|
||||||
[period] = [p for p in data["periods"] if p["Type"] == key]
|
[period] = [p for p in data["periods"] if p["Type"] == key]
|
||||||
|
except ValueError:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"IQVIA didn't return data for %s; trying again later", self.name
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
[rating] = [
|
[rating] = [
|
||||||
i["label"]
|
i["label"]
|
||||||
for i in RATING_MAPPING
|
for i in RATING_MAPPING
|
||||||
|
Loading…
x
Reference in New Issue
Block a user