Skip to content

Commit

Permalink
fix: handle missing prices (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Nov 22, 2024
1 parent d63eb5d commit 6574956
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions custom_components/gasbuddy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ def native_value(self) -> Any:
self._state = None
if self._type in data.keys():
if self._cash and "cash_price" in data[self._type]:
if self.coordinator.data["unit_of_measure"] == "cents_per_liter":
if (
self.coordinator.data["unit_of_measure"] == "cents_per_liter"
and data[self._type]["cash_price"]
):
self._state = data[self._type]["cash_price"] / 100
else:
self._state = data[self._type]["cash_price"]
else:
if self.coordinator.data["unit_of_measure"] == "cents_per_liter":
if (
self.coordinator.data["unit_of_measure"] == "cents_per_liter"
and data[self._type]["price"]
):
self._state = data[self._type]["price"] / 100
else:
self._state = data[self._type]["price"]
Expand Down

0 comments on commit 6574956

Please sign in to comment.