From ba77a5e2c2cd218ae8b31bef52e9c0b7df32774f Mon Sep 17 00:00:00 2001 From: Adam Outler Date: Thu, 30 Dec 2021 15:34:18 -0500 Subject: [PATCH] return none if no data is available --- custom_components/fpl/sensor_DailyUsageSensor.py | 4 ++-- custom_components/fpl/sensor_KWHSensor.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/custom_components/fpl/sensor_DailyUsageSensor.py b/custom_components/fpl/sensor_DailyUsageSensor.py index cb36367..bbbb254 100644 --- a/custom_components/fpl/sensor_DailyUsageSensor.py +++ b/custom_components/fpl/sensor_DailyUsageSensor.py @@ -80,7 +80,7 @@ class FplDailyReceivedKWHSensor(FplEntity): try: return data[-1]["netReceivedKwh"] except: - return 0 + return None def defineAttributes(self): """Return the state attributes.""" @@ -113,7 +113,7 @@ class FplDailyDeliveredKWHSensor(FplEntity): try: return data[-1]["netDeliveredKwh"] except: - return 0 + return None def defineAttributes(self): """Return the state attributes.""" diff --git a/custom_components/fpl/sensor_KWHSensor.py b/custom_components/fpl/sensor_KWHSensor.py index 92b7992..038df97 100644 --- a/custom_components/fpl/sensor_KWHSensor.py +++ b/custom_components/fpl/sensor_KWHSensor.py @@ -61,7 +61,8 @@ class BillToDateKWHSensor(FplEntity): attributes["device_class"] = "energy" attributes["state_class"] = "total_increasing" attributes["unit_of_measurement"] = "kWh" - attributes["last_reset"] = self.getData("billStartDate") + if self.getData("billStartDate") is not None: + attributes["last_reset"] = self.getData("billStartDate") return attributes class NetReceivedKWHSensor(FplEntity): @@ -73,7 +74,7 @@ class NetReceivedKWHSensor(FplEntity): try: return self.getData("recMtrReading") except: - return 0 + return None @property def icon(self): @@ -86,7 +87,8 @@ class NetReceivedKWHSensor(FplEntity): attributes["device_class"] = "energy" attributes["state_class"] = "total_increasing" attributes["unit_of_measurement"] = "kWh" - attributes["last_reset"] = self.getData("billStartDate") + if self.getData("billStartDate") is not None: + attributes["last_reset"] = self.getData("billStartDate") return attributes @@ -99,7 +101,10 @@ class NetDeliveredKWHSensor(FplEntity): try: return self.getData("delMtrReading") except: - return self.getData("billToDateKWH") + try: + return self.getData("billToDateKWH") + except: + return None @property def icon(self): @@ -112,6 +117,7 @@ class NetDeliveredKWHSensor(FplEntity): attributes["device_class"] = "energy" attributes["state_class"] = "total_increasing" attributes["unit_of_measurement"] = "kWh" - attributes["last_reset"] = self.getData("billStartDate") + if self.getData("billStartDate") is not None: + attributes["last_reset"] = self.getData("billStartDate") return attributes