fill in missing gaps with previous state
This commit is contained in:
@@ -24,13 +24,12 @@ class FplProjectedBillSensor(FplSensor):
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
try:
|
||||
if "budget_bill" in self.data.keys():
|
||||
self.attr["budget_bill"] = self.data["budget_bill"]
|
||||
except:
|
||||
pass
|
||||
|
||||
return self.attr
|
||||
if "budget_bill" in self.data.keys():
|
||||
self.attr["budget_bill"] = self.data["budget_bill"]
|
||||
|
||||
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
||||
@@ -24,7 +24,8 @@ class FplEntity(CoordinatorEntity):
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.account)},
|
||||
"name": f"FPL Account {self.account}",
|
||||
"model": VERSION,
|
||||
"model": "FPL Monitoring API",
|
||||
"sw_version": VERSION,
|
||||
"manufacturer": "Florida Power & Light",
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
"bs4",
|
||||
"integrationhelper"
|
||||
],
|
||||
"homeassistant": "0.96.0",
|
||||
"homeassistant": "2021.12.7",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
@@ -13,11 +13,11 @@ class AllDataSensor(FplEntity):
|
||||
if budget == True and budget_billing_projected_bill is not None:
|
||||
return self.getData("budget_billing_projected_bill")
|
||||
|
||||
return self.getData("projected_bill")
|
||||
|
||||
def defineAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
return self.coordinator.data.get(self.account)
|
||||
try:
|
||||
self._state=self.getData("projected_bill")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
||||
@@ -13,7 +13,11 @@ class FplAverageDailySensor(FplEntity):
|
||||
if budget == True and budget_billing_projected_bill is not None:
|
||||
return self.getData("budget_billing_daily_avg")
|
||||
|
||||
return self.getData("daily_avg")
|
||||
try:
|
||||
self._state=self.getData("daily_avg")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -34,7 +38,11 @@ class BudgetDailyAverageSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("budget_billing_daily_avg")
|
||||
try:
|
||||
self._state= self.getData("budget_billing_daily_avg")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
||||
@@ -9,10 +9,11 @@ class FplDailyUsageSensor(FplEntity):
|
||||
def state(self):
|
||||
data = self.getData("daily_usage")
|
||||
|
||||
if (data is not None) and (len(data) > 0):
|
||||
return data[-1]["cost"]
|
||||
|
||||
return None
|
||||
try:
|
||||
self._state = data[-1]["cost"]
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
def defineAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -23,9 +24,17 @@ class FplDailyUsageSensor(FplEntity):
|
||||
attributes["state_class"] = "total_increasing"
|
||||
attributes["unit_of_measurement"] = "$"
|
||||
if data is not None:
|
||||
if (data[-1] is not None) and (data[-1]["readTime"] is not None):
|
||||
if (
|
||||
(len(data) > 0)
|
||||
and (data[-1] is not None)
|
||||
and (data[-1]["readTime"] is not None)
|
||||
):
|
||||
attributes["date"] = data[-1]["readTime"]
|
||||
if (data[-2] is not None) and (data[-2]["readTime"] is not None):
|
||||
if (
|
||||
(len(data) > 1)
|
||||
and (data[-2] is not None)
|
||||
and (data[-2]["readTime"] is not None)
|
||||
):
|
||||
attributes["last_reset"] = data[-2]["readTime"]
|
||||
return attributes
|
||||
|
||||
@@ -42,10 +51,11 @@ class FplDailyUsageKWHSensor(FplEntity):
|
||||
def state(self):
|
||||
data = self.getData("daily_usage")
|
||||
|
||||
if (data is not None) and (data[-1]["usage"] is not None):
|
||||
return data[-1]["usage"]
|
||||
|
||||
return None
|
||||
try:
|
||||
self._state = data[-1]["usage"]
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
def defineAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -58,9 +68,17 @@ class FplDailyUsageKWHSensor(FplEntity):
|
||||
attributes["unit_of_measurement"] = "kWh"
|
||||
|
||||
if data is not None:
|
||||
if (data[-1] is not None) and (data[-1]["readTime"] is not None):
|
||||
if (
|
||||
(len(data) > 0)
|
||||
and (data[-1] is not None)
|
||||
and (data[-1]["readTime"] is not None)
|
||||
):
|
||||
attributes["date"] = data[-1]["readTime"]
|
||||
if (data[-2] is not None) and (data[-2]["readTime"] is not None):
|
||||
if (
|
||||
(len(data) > 1)
|
||||
and (data[-2] is not None)
|
||||
and (data[-2]["readTime"] is not None)
|
||||
):
|
||||
attributes["last_reset"] = data[-2]["readTime"]
|
||||
|
||||
return attributes
|
||||
@@ -78,9 +96,10 @@ class FplDailyReceivedKWHSensor(FplEntity):
|
||||
def state(self):
|
||||
data = self.getData("daily_usage")
|
||||
try:
|
||||
return data[-1]["netReceivedKwh"]
|
||||
self._state = data[-1]["netReceivedKwh"]
|
||||
except:
|
||||
return None
|
||||
pass
|
||||
return self._state
|
||||
|
||||
def defineAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -92,9 +111,17 @@ class FplDailyReceivedKWHSensor(FplEntity):
|
||||
attributes["state_class"] = "total_increasing"
|
||||
attributes["unit_of_measurement"] = "kWh"
|
||||
if data is not None:
|
||||
if (data[-1] is not None) and (data[-1]["readTime"] is not None):
|
||||
if (
|
||||
(len(data) > 0)
|
||||
and (data[-1] is not None)
|
||||
and (data[-1]["readTime"] is not None)
|
||||
):
|
||||
attributes["date"] = data[-1]["readTime"]
|
||||
if (data[-2] is not None) and (data[-2]["readTime"] is not None):
|
||||
if (
|
||||
(len(data) > 1)
|
||||
and (data[-2] is not None)
|
||||
and (data[-2]["readTime"] is not None)
|
||||
):
|
||||
attributes["last_reset"] = data[-2]["readTime"]
|
||||
return attributes
|
||||
|
||||
@@ -111,9 +138,10 @@ class FplDailyDeliveredKWHSensor(FplEntity):
|
||||
def state(self):
|
||||
data = self.getData("daily_usage")
|
||||
try:
|
||||
return data[-1]["netDeliveredKwh"]
|
||||
self._state = data[-1]["netDeliveredKwh"]
|
||||
except:
|
||||
return None
|
||||
pass
|
||||
return self._state
|
||||
|
||||
def defineAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -125,9 +153,17 @@ class FplDailyDeliveredKWHSensor(FplEntity):
|
||||
attributes["state_class"] = "total_increasing"
|
||||
attributes["unit_of_measurement"] = "kWh"
|
||||
if data is not None:
|
||||
if (data[-1] is not None) and (data[-1]["readTime"] is not None):
|
||||
if (
|
||||
(len(data) > 0)
|
||||
and (data[-1] is not None)
|
||||
and (data[-1]["readTime"] is not None)
|
||||
):
|
||||
attributes["date"] = data[-1]["readTime"]
|
||||
if (data[-2] is not None) and (data[-2]["readTime"] is not None):
|
||||
if (
|
||||
(len(data) > 1)
|
||||
and (data[-2] is not None)
|
||||
and (data[-2]["readTime"] is not None)
|
||||
):
|
||||
attributes["last_reset"] = data[-2]["readTime"]
|
||||
return attributes
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ class CurrentBillDateSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return datetime.date.fromisoformat(self.getData("current_bill_date"))
|
||||
try:
|
||||
self._state= datetime.date.fromisoformat(self.getData("current_bill_date"))
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -26,7 +30,11 @@ class NextBillDateSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return datetime.date.fromisoformat(self.getData("next_bill_date"))
|
||||
try:
|
||||
self._state= datetime.date.fromisoformat(self.getData("next_bill_date"))
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -45,7 +53,11 @@ class ServiceDaysSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("service_days")
|
||||
try:
|
||||
self._state= self.getData("service_days")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -64,7 +76,11 @@ class AsOfDaysSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("as_of_days")
|
||||
try:
|
||||
self._state= self.getData("as_of_days")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -83,7 +99,11 @@ class RemainingDaysSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("remaining_days")
|
||||
try:
|
||||
self._state= self.getData("remaining_days")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
||||
@@ -7,11 +7,16 @@ class ProjectedKWHSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("projectedKWH")
|
||||
try:
|
||||
self._state = self.getData("projectedKWH")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
return "mdi:flash"
|
||||
|
||||
def defineAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
attributes = {}
|
||||
@@ -21,13 +26,18 @@ class ProjectedKWHSensor(FplEntity):
|
||||
attributes["unit_of_measurement"] = "kWh"
|
||||
return attributes
|
||||
|
||||
|
||||
class DailyAverageKWHSensor(FplEntity):
|
||||
def __init__(self, coordinator, config, account):
|
||||
super().__init__(coordinator, config, account, "Daily Average")
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("dailyAverageKWH")
|
||||
try:
|
||||
self._state = self.getData("dailyAverageKWH")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -42,13 +52,18 @@ class DailyAverageKWHSensor(FplEntity):
|
||||
attributes["unit_of_measurement"] = "kWh"
|
||||
return attributes
|
||||
|
||||
|
||||
class BillToDateKWHSensor(FplEntity):
|
||||
def __init__(self, coordinator, config, account):
|
||||
super().__init__(coordinator, config, account, "Bill To Date")
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("billToDateKWH")
|
||||
try:
|
||||
self._state = self.getData("billToDateKWH")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -65,6 +80,7 @@ class BillToDateKWHSensor(FplEntity):
|
||||
attributes["last_reset"] = self.getData("billStartDate")
|
||||
return attributes
|
||||
|
||||
|
||||
class NetReceivedKWHSensor(FplEntity):
|
||||
def __init__(self, coordinator, config, account):
|
||||
super().__init__(coordinator, config, account, "Received Reading")
|
||||
@@ -72,9 +88,10 @@ class NetReceivedKWHSensor(FplEntity):
|
||||
@property
|
||||
def state(self):
|
||||
try:
|
||||
return self.getData("recMtrReading")
|
||||
self._state = self.getData("recMtrReading")
|
||||
except:
|
||||
return None
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -92,6 +109,7 @@ class NetReceivedKWHSensor(FplEntity):
|
||||
|
||||
return attributes
|
||||
|
||||
|
||||
class NetDeliveredKWHSensor(FplEntity):
|
||||
def __init__(self, coordinator, config, account):
|
||||
super().__init__(coordinator, config, account, "Delivered Reading")
|
||||
@@ -99,12 +117,13 @@ class NetDeliveredKWHSensor(FplEntity):
|
||||
@property
|
||||
def state(self):
|
||||
try:
|
||||
return self.getData("delMtrReading")
|
||||
self._state = self.getData("delMtrReading")
|
||||
except:
|
||||
try:
|
||||
return self.getData("billToDateKWH")
|
||||
self._state = self.getData("billToDateKWH")
|
||||
except:
|
||||
return None
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
||||
@@ -10,10 +10,14 @@ class FplProjectedBillSensor(FplEntity):
|
||||
budget = self.getData("budget_bill")
|
||||
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
|
||||
|
||||
if budget == True and budget_billing_projected_bill is not None:
|
||||
return self.getData("budget_billing_projected_bill")
|
||||
|
||||
return self.getData("projected_bill")
|
||||
try:
|
||||
if budget == True and budget_billing_projected_bill is not None:
|
||||
self._state = self.getData("budget_billing_projected_bill")
|
||||
else:
|
||||
self._state = self.getData("projected_bill")
|
||||
except:
|
||||
self._state = None
|
||||
return self._state
|
||||
|
||||
def defineAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
@@ -36,9 +40,12 @@ class DeferedAmountSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
if self.getData("deferred_amount") is not None:
|
||||
return self.getData("deferred_amount")
|
||||
return 0
|
||||
try:
|
||||
self._state = self.getData("deferred_amount")
|
||||
except:
|
||||
self._state = 0
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -60,7 +67,11 @@ class ProjectedBudgetBillSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("budget_billing_projected_bill")
|
||||
try:
|
||||
self._state = self.getData("budget_billing_projected_bill")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -72,7 +83,7 @@ class ProjectedBudgetBillSensor(FplEntity):
|
||||
attributes["friendly_name"] = "Projected Budget Bill"
|
||||
attributes["device_class"] = "monitary"
|
||||
attributes["state_class"] = "total"
|
||||
attributes['unit_of_measurement'] = "$"
|
||||
attributes["unit_of_measurement"] = "$"
|
||||
return attributes
|
||||
|
||||
|
||||
@@ -82,7 +93,11 @@ class ProjectedActualBillSensor(FplEntity):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.getData("projected_bill")
|
||||
try:
|
||||
self._state = self.getData("projected_bill")
|
||||
except:
|
||||
pass
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -94,6 +109,6 @@ class ProjectedActualBillSensor(FplEntity):
|
||||
attributes["friendly_name"] = "Projected Actual Bill"
|
||||
attributes["device_class"] = "monitary"
|
||||
attributes["state_class"] = "total"
|
||||
attributes['unit_of_measurement'] = "$"
|
||||
attributes["unit_of_measurement"] = "$"
|
||||
|
||||
return attributes
|
||||
|
||||
Reference in New Issue
Block a user