Fix unhandled exception when IQVIA API fails to return data (#43359)

This commit is contained in:
Aaron Bach 2020-11-22 05:59:23 -07:00 committed by GitHub
parent be39104a36
commit 3ffd97acd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -155,6 +155,9 @@ class IQVIAEntity(CoordinatorEntity):
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
if not self.coordinator.last_update_success:
return
self.update_from_latest_data()
self.async_write_ha_state()

View File

@ -105,6 +105,7 @@ class ForecastSensor(IQVIAEntity):
def update_from_latest_data(self):
"""Update the sensor."""
data = self.coordinator.data.get("Location")
if not data or not data.get("periods"):
return
@ -142,6 +143,9 @@ class IndexSensor(IQVIAEntity):
@callback
def update_from_latest_data(self):
"""Update the sensor."""
if not self.coordinator.last_update_success:
return
try:
if self._type in (TYPE_ALLERGY_TODAY, TYPE_ALLERGY_TOMORROW):
data = self.coordinator.data.get("Location")