update native value if there are valid values from api
This commit is contained in:
@@ -12,12 +12,12 @@ class DailyAverageSensor(FplMoneyEntity):
|
||||
@property
|
||||
def native_value(self):
|
||||
budget = self.getData("budget_bill")
|
||||
budget_billing_projected_bill = self.getData("budget_billing_daily_avg")
|
||||
daily_avg = self.getData("daily_avg")
|
||||
|
||||
if budget and budget_billing_projected_bill is not None:
|
||||
return self.getData("budget_billing_daily_avg")
|
||||
if budget and daily_avg is not None:
|
||||
self._attr_native_value = daily_avg
|
||||
|
||||
return self.getData("daily_avg")
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -34,7 +34,12 @@ class BudgetDailyAverageSensor(FplMoneyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("budget_billing_daily_avg")
|
||||
budget_billing_daily_avg = self.getData("budget_billing_daily_avg")
|
||||
|
||||
if budget_billing_daily_avg is not None:
|
||||
self._attr_native_value = budget_billing_daily_avg
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -51,7 +56,12 @@ class ActualDailyAverageSensor(FplMoneyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("daily_avg")
|
||||
daily_avg = self.getData("daily_avg")
|
||||
|
||||
if daily_avg is not None:
|
||||
self._attr_native_value = daily_avg
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -11,7 +11,12 @@ class CurrentBillDateSensor(FplDateEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return datetime.date.fromisoformat(self.getData("current_bill_date"))
|
||||
current_bill_date = self.getData("current_bill_date")
|
||||
|
||||
if current_bill_date is not None:
|
||||
self._attr_native_value = datetime.date.fromisoformat(current_bill_date)
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
|
||||
class NextBillDateSensor(FplDateEntity):
|
||||
@@ -22,7 +27,12 @@ class NextBillDateSensor(FplDateEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return datetime.date.fromisoformat(self.getData("next_bill_date"))
|
||||
next_bill_date = self.getData("next_bill_date")
|
||||
|
||||
if next_bill_date is not None:
|
||||
self._attr_native_value = datetime.date.fromisoformat(next_bill_date)
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
|
||||
class ServiceDaysSensor(FplDayEntity):
|
||||
@@ -33,7 +43,12 @@ class ServiceDaysSensor(FplDayEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("service_days")
|
||||
service_days = self.getData("service_days")
|
||||
|
||||
if service_days is not None:
|
||||
self._attr_native_value = service_days
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
|
||||
class AsOfDaysSensor(FplDayEntity):
|
||||
@@ -44,7 +59,12 @@ class AsOfDaysSensor(FplDayEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("as_of_days")
|
||||
as_of_days = self.getData("as_of_days")
|
||||
|
||||
if as_of_days is not None:
|
||||
self._attr_native_value = as_of_days
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
|
||||
class RemainingDaysSensor(FplDayEntity):
|
||||
@@ -55,4 +75,9 @@ class RemainingDaysSensor(FplDayEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("remaining_days")
|
||||
remaining_days = self.getData("remaining_days")
|
||||
|
||||
if remaining_days is not None:
|
||||
self._attr_native_value = remaining_days
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
@@ -15,7 +15,12 @@ class ProjectedKWHSensor(FplEnergyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("projectedKWH")
|
||||
projectedKWH = self.getData("projectedKWH")
|
||||
|
||||
if projectedKWH is not None:
|
||||
self._attr_native_value = projectedKWH
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -32,7 +37,12 @@ class DailyAverageKWHSensor(FplEnergyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("dailyAverageKWH")
|
||||
dailyAverageKWH = self.getData("dailyAverageKWH")
|
||||
|
||||
if dailyAverageKWH is not None:
|
||||
self._attr_native_value = dailyAverageKWH
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -49,7 +59,12 @@ class BillToDateKWHSensor(FplEnergyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("billToDateKWH")
|
||||
billToDateKWH = self.getData("billToDateKWH")
|
||||
|
||||
if billToDateKWH is not None:
|
||||
self._attr_native_value = billToDateKWH
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -73,7 +88,12 @@ class NetReceivedKWHSensor(FplEnergyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("recMtrReading")
|
||||
recMtrReading = self.getData("recMtrReading")
|
||||
|
||||
if recMtrReading is not None:
|
||||
self._attr_native_value = recMtrReading
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -90,7 +110,12 @@ class NetDeliveredKWHSensor(FplEnergyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("delMtrReading")
|
||||
delMtrReading = self.getData("delMtrReading")
|
||||
|
||||
if delMtrReading is not None:
|
||||
self._attr_native_value = delMtrReading
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
|
||||
@@ -19,10 +19,15 @@ class FplProjectedBillSensor(FplMoneyEntity):
|
||||
budget = self.getData("budget_bill")
|
||||
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
|
||||
|
||||
if budget and budget_billing_projected_bill is not None:
|
||||
return self.getData("budget_billing_projected_bill")
|
||||
projected_bill = self.getData("projected_bill")
|
||||
|
||||
return self.getData("projected_bill")
|
||||
if budget and budget_billing_projected_bill is not None:
|
||||
self._attr_native_value = self.getData("budget_billing_projected_bill")
|
||||
else:
|
||||
if projected_bill is not None:
|
||||
self._attr_native_value = projected_bill
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -42,9 +47,13 @@ class DeferedAmountSensor(FplMoneyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
if self.getData("budget_bill"):
|
||||
return self.getData("defered_amount")
|
||||
return 0
|
||||
budget_bill = self.getData("budget_bill")
|
||||
defered_amount = self.getData("defered_amount")
|
||||
|
||||
if budget_bill and defered_amount is not None:
|
||||
self._attr_native_value = defered_amount
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
|
||||
class ProjectedBudgetBillSensor(FplMoneyEntity):
|
||||
@@ -57,7 +66,12 @@ class ProjectedBudgetBillSensor(FplMoneyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("budget_billing_projected_bill")
|
||||
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
|
||||
|
||||
if budget_billing_projected_bill is not None:
|
||||
self._attr_native_value = budget_billing_projected_bill
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
|
||||
class ProjectedActualBillSensor(FplMoneyEntity):
|
||||
@@ -70,7 +84,12 @@ class ProjectedActualBillSensor(FplMoneyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
return self.getData("projected_bill")
|
||||
projected_bill = self.getData("projected_bill")
|
||||
|
||||
if projected_bill is not None:
|
||||
self._attr_native_value = projected_bill
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
|
||||
class BillToDateSensor(FplMoneyEntity):
|
||||
@@ -83,7 +102,13 @@ class BillToDateSensor(FplMoneyEntity):
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
if self.getData("budget_bill"):
|
||||
return self.getData("budget_billing_bill_to_date")
|
||||
budget_bill = self.getData("budget_bill")
|
||||
budget_billing_bill_to_date = self.getData("budget_billing_bill_to_date")
|
||||
bill_to_date = self.getData("bill_to_date")
|
||||
|
||||
return self.getData("bill_to_date")
|
||||
if budget_bill:
|
||||
self._attr_native_value = budget_billing_bill_to_date
|
||||
else:
|
||||
self._attr_native_value = bill_to_date
|
||||
|
||||
return self._attr_native_value
|
||||
|
||||
Reference in New Issue
Block a user