update native value if there are valid values from api

This commit is contained in:
Yordan Suarez
2022-09-13 16:53:58 -04:00
parent d9d27f7ae6
commit d7b1f3fd38
5 changed files with 124 additions and 35 deletions

View File

@@ -19,9 +19,9 @@ class FplDailyUsageSensor(FplMoneyEntity):
data = self.getData("daily_usage")
if data is not None and len(data) > 0 and "cost" in data[-1].keys():
return data[-1]["cost"]
self._attr_native_value = data[-1]["cost"]
return None
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -48,9 +48,9 @@ class FplDailyUsageKWHSensor(FplEnergyEntity):
data = self.getData("daily_usage")
if data is not None and len(data) > 0 and "usage" in data[-1].keys():
return data[-1]["usage"]
self._attr_native_value = data[-1]["usage"]
return None
return self._attr_native_value
@property
def last_reset(self) -> datetime | None:
@@ -83,9 +83,11 @@ class FplDailyReceivedKWHSensor(FplEnergyEntity):
@property
def native_value(self):
data = self.getData("daily_usage")
if data is not None and len(data) > 0 and "netReceivedKwh" in data[-1].keys():
return data[-1]["netReceivedKwh"]
return 0
self._attr_native_value = data[-1]["netReceivedKwh"]
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -110,9 +112,11 @@ class FplDailyDeliveredKWHSensor(FplEnergyEntity):
@property
def native_value(self):
data = self.getData("daily_usage")
if data is not None and len(data) > 0 and "netDeliveredKwh" in data[-1].keys():
return data[-1]["netDeliveredKwh"]
return 0
self._attr_native_value = data[-1]["netDeliveredKwh"]
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""