Fix possible unhandled IQVIA exception with allergy outlook data (#54477)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>pull/54472/head
parent
d6483f2f36
commit
98a4e6a7e8
|
@ -104,7 +104,7 @@ class ForecastSensor(IQVIAEntity):
|
||||||
@callback
|
@callback
|
||||||
def update_from_latest_data(self):
|
def update_from_latest_data(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
if not self.coordinator.data:
|
if not self.available:
|
||||||
return
|
return
|
||||||
|
|
||||||
data = self.coordinator.data.get("Location", {})
|
data = self.coordinator.data.get("Location", {})
|
||||||
|
@ -120,6 +120,7 @@ class ForecastSensor(IQVIAEntity):
|
||||||
if i["minimum"] <= average <= i["maximum"]
|
if i["minimum"] <= average <= i["maximum"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
self._attr_state = average
|
||||||
self._attr_extra_state_attributes.update(
|
self._attr_extra_state_attributes.update(
|
||||||
{
|
{
|
||||||
ATTR_CITY: data["City"].title(),
|
ATTR_CITY: data["City"].title(),
|
||||||
|
@ -134,6 +135,10 @@ class ForecastSensor(IQVIAEntity):
|
||||||
outlook_coordinator = self.hass.data[DOMAIN][DATA_COORDINATOR][
|
outlook_coordinator = self.hass.data[DOMAIN][DATA_COORDINATOR][
|
||||||
self._entry.entry_id
|
self._entry.entry_id
|
||||||
][TYPE_ALLERGY_OUTLOOK]
|
][TYPE_ALLERGY_OUTLOOK]
|
||||||
|
|
||||||
|
if not outlook_coordinator.last_update_success:
|
||||||
|
return
|
||||||
|
|
||||||
self._attr_extra_state_attributes[
|
self._attr_extra_state_attributes[
|
||||||
ATTR_OUTLOOK
|
ATTR_OUTLOOK
|
||||||
] = outlook_coordinator.data.get("Outlook")
|
] = outlook_coordinator.data.get("Outlook")
|
||||||
|
@ -141,8 +146,6 @@ class ForecastSensor(IQVIAEntity):
|
||||||
ATTR_SEASON
|
ATTR_SEASON
|
||||||
] = outlook_coordinator.data.get("Season")
|
] = outlook_coordinator.data.get("Season")
|
||||||
|
|
||||||
self._attr_state = average
|
|
||||||
|
|
||||||
|
|
||||||
class IndexSensor(IQVIAEntity):
|
class IndexSensor(IQVIAEntity):
|
||||||
"""Define sensor related to indices."""
|
"""Define sensor related to indices."""
|
||||||
|
|
Loading…
Reference in New Issue