From fbf4f95e26120c43ce003505652b713a0eb1060c Mon Sep 17 00:00:00 2001 From: "firstof9@gmail.com" Date: Fri, 22 Nov 2024 16:04:00 -0700 Subject: [PATCH] fix: handle missing prices --- custom_components/gasbuddy/sensor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/custom_components/gasbuddy/sensor.py b/custom_components/gasbuddy/sensor.py index aa2e77b..0e739ed 100644 --- a/custom_components/gasbuddy/sensor.py +++ b/custom_components/gasbuddy/sensor.py @@ -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"]