Skip to content

Commit

Permalink
ensure that usage is valid before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
ablyler committed Oct 25, 2023
1 parent 14c468b commit e24cd1b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions custom_components/aquahawk/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ async def async_update(self):
elif self.period == Period.PERIOD_TODAY:
usage = await self.aquahawk.get_usage_today()

# ensure usage is not None and that the last timeseries has a water_use
if usage is None or usage.timeseries[-1].water_use is None:
self._attr_available = False
return

self._attr_native_value = usage.timeseries[-1].water_use.gallons
self._attr_available = True
# trunk-ignore(flake8/E722)
Expand Down

0 comments on commit e24cd1b

Please sign in to comment.