fill in missing gaps with previous state

This commit is contained in:
Adam Outler
2022-01-01 12:17:37 -05:00
parent ba77a5e2c2
commit 0b4f5abb5b
9 changed files with 159 additions and 61 deletions

View File

@@ -24,13 +24,12 @@ class FplProjectedBillSensor(FplSensor):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """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 @property
def icon(self): def icon(self):

View File

@@ -24,7 +24,8 @@ class FplEntity(CoordinatorEntity):
return { return {
"identifiers": {(DOMAIN, self.account)}, "identifiers": {(DOMAIN, self.account)},
"name": f"FPL Account {self.account}", "name": f"FPL Account {self.account}",
"model": VERSION, "model": "FPL Monitoring API",
"sw_version": VERSION,
"manufacturer": "Florida Power & Light", "manufacturer": "Florida Power & Light",
} }

View File

@@ -12,6 +12,6 @@
"bs4", "bs4",
"integrationhelper" "integrationhelper"
], ],
"homeassistant": "0.96.0", "homeassistant": "2021.12.7",
"version": "1.0.0" "version": "1.0.0"
} }

View File

@@ -13,11 +13,11 @@ class AllDataSensor(FplEntity):
if budget == True and budget_billing_projected_bill is not None: if budget == True and budget_billing_projected_bill is not None:
return self.getData("budget_billing_projected_bill") return self.getData("budget_billing_projected_bill")
return self.getData("projected_bill") try:
self._state=self.getData("projected_bill")
def defineAttributes(self): except:
"""Return the state attributes.""" pass
return self.coordinator.data.get(self.account) return self._state
@property @property
def icon(self): def icon(self):

View File

@@ -13,7 +13,11 @@ class FplAverageDailySensor(FplEntity):
if budget == True and budget_billing_projected_bill is not None: if budget == True and budget_billing_projected_bill is not None:
return self.getData("budget_billing_daily_avg") 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 @property
def icon(self): def icon(self):
@@ -34,7 +38,11 @@ class BudgetDailyAverageSensor(FplEntity):
@property @property
def state(self): 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 @property
def icon(self): def icon(self):

View File

@@ -9,10 +9,11 @@ class FplDailyUsageSensor(FplEntity):
def state(self): def state(self):
data = self.getData("daily_usage") data = self.getData("daily_usage")
if (data is not None) and (len(data) > 0): try:
return data[-1]["cost"] self._state = data[-1]["cost"]
except:
return None pass
return self._state
def defineAttributes(self): def defineAttributes(self):
"""Return the state attributes.""" """Return the state attributes."""
@@ -23,9 +24,17 @@ class FplDailyUsageSensor(FplEntity):
attributes["state_class"] = "total_increasing" attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "$" attributes["unit_of_measurement"] = "$"
if data is not None: 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"] 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"] attributes["last_reset"] = data[-2]["readTime"]
return attributes return attributes
@@ -42,10 +51,11 @@ class FplDailyUsageKWHSensor(FplEntity):
def state(self): def state(self):
data = self.getData("daily_usage") data = self.getData("daily_usage")
if (data is not None) and (data[-1]["usage"] is not None): try:
return data[-1]["usage"] self._state = data[-1]["usage"]
except:
return None pass
return self._state
def defineAttributes(self): def defineAttributes(self):
"""Return the state attributes.""" """Return the state attributes."""
@@ -58,9 +68,17 @@ class FplDailyUsageKWHSensor(FplEntity):
attributes["unit_of_measurement"] = "kWh" attributes["unit_of_measurement"] = "kWh"
if data is not None: 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"] 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"] attributes["last_reset"] = data[-2]["readTime"]
return attributes return attributes
@@ -78,9 +96,10 @@ class FplDailyReceivedKWHSensor(FplEntity):
def state(self): def state(self):
data = self.getData("daily_usage") data = self.getData("daily_usage")
try: try:
return data[-1]["netReceivedKwh"] self._state = data[-1]["netReceivedKwh"]
except: except:
return None pass
return self._state
def defineAttributes(self): def defineAttributes(self):
"""Return the state attributes.""" """Return the state attributes."""
@@ -92,9 +111,17 @@ class FplDailyReceivedKWHSensor(FplEntity):
attributes["state_class"] = "total_increasing" attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh" attributes["unit_of_measurement"] = "kWh"
if data is not None: 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"] 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"] attributes["last_reset"] = data[-2]["readTime"]
return attributes return attributes
@@ -111,9 +138,10 @@ class FplDailyDeliveredKWHSensor(FplEntity):
def state(self): def state(self):
data = self.getData("daily_usage") data = self.getData("daily_usage")
try: try:
return data[-1]["netDeliveredKwh"] self._state = data[-1]["netDeliveredKwh"]
except: except:
return None pass
return self._state
def defineAttributes(self): def defineAttributes(self):
"""Return the state attributes.""" """Return the state attributes."""
@@ -125,9 +153,17 @@ class FplDailyDeliveredKWHSensor(FplEntity):
attributes["state_class"] = "total_increasing" attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh" attributes["unit_of_measurement"] = "kWh"
if data is not None: 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"] 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"] attributes["last_reset"] = data[-2]["readTime"]
return attributes return attributes

View File

@@ -7,7 +7,11 @@ class CurrentBillDateSensor(FplEntity):
@property @property
def state(self): 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 @property
def icon(self): def icon(self):
@@ -26,7 +30,11 @@ class NextBillDateSensor(FplEntity):
@property @property
def state(self): 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 @property
def icon(self): def icon(self):
@@ -45,7 +53,11 @@ class ServiceDaysSensor(FplEntity):
@property @property
def state(self): def state(self):
return self.getData("service_days") try:
self._state= self.getData("service_days")
except:
pass
return self._state
@property @property
def icon(self): def icon(self):
@@ -64,7 +76,11 @@ class AsOfDaysSensor(FplEntity):
@property @property
def state(self): def state(self):
return self.getData("as_of_days") try:
self._state= self.getData("as_of_days")
except:
pass
return self._state
@property @property
def icon(self): def icon(self):
@@ -83,7 +99,11 @@ class RemainingDaysSensor(FplEntity):
@property @property
def state(self): def state(self):
return self.getData("remaining_days") try:
self._state= self.getData("remaining_days")
except:
pass
return self._state
@property @property
def icon(self): def icon(self):

View File

@@ -7,11 +7,16 @@ class ProjectedKWHSensor(FplEntity):
@property @property
def state(self): def state(self):
return self.getData("projectedKWH") try:
self._state = self.getData("projectedKWH")
except:
pass
return self._state
@property @property
def icon(self): def icon(self):
return "mdi:flash" return "mdi:flash"
def defineAttributes(self): def defineAttributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attributes = {} attributes = {}
@@ -21,13 +26,18 @@ class ProjectedKWHSensor(FplEntity):
attributes["unit_of_measurement"] = "kWh" attributes["unit_of_measurement"] = "kWh"
return attributes return attributes
class DailyAverageKWHSensor(FplEntity): class DailyAverageKWHSensor(FplEntity):
def __init__(self, coordinator, config, account): def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Average") super().__init__(coordinator, config, account, "Daily Average")
@property @property
def state(self): def state(self):
return self.getData("dailyAverageKWH") try:
self._state = self.getData("dailyAverageKWH")
except:
pass
return self._state
@property @property
def icon(self): def icon(self):
@@ -42,13 +52,18 @@ class DailyAverageKWHSensor(FplEntity):
attributes["unit_of_measurement"] = "kWh" attributes["unit_of_measurement"] = "kWh"
return attributes return attributes
class BillToDateKWHSensor(FplEntity): class BillToDateKWHSensor(FplEntity):
def __init__(self, coordinator, config, account): def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Bill To Date") super().__init__(coordinator, config, account, "Bill To Date")
@property @property
def state(self): def state(self):
return self.getData("billToDateKWH") try:
self._state = self.getData("billToDateKWH")
except:
pass
return self._state
@property @property
def icon(self): def icon(self):
@@ -65,6 +80,7 @@ class BillToDateKWHSensor(FplEntity):
attributes["last_reset"] = self.getData("billStartDate") attributes["last_reset"] = self.getData("billStartDate")
return attributes return attributes
class NetReceivedKWHSensor(FplEntity): class NetReceivedKWHSensor(FplEntity):
def __init__(self, coordinator, config, account): def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Received Reading") super().__init__(coordinator, config, account, "Received Reading")
@@ -72,9 +88,10 @@ class NetReceivedKWHSensor(FplEntity):
@property @property
def state(self): def state(self):
try: try:
return self.getData("recMtrReading") self._state = self.getData("recMtrReading")
except: except:
return None pass
return self._state
@property @property
def icon(self): def icon(self):
@@ -92,6 +109,7 @@ class NetReceivedKWHSensor(FplEntity):
return attributes return attributes
class NetDeliveredKWHSensor(FplEntity): class NetDeliveredKWHSensor(FplEntity):
def __init__(self, coordinator, config, account): def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Delivered Reading") super().__init__(coordinator, config, account, "Delivered Reading")
@@ -99,12 +117,13 @@ class NetDeliveredKWHSensor(FplEntity):
@property @property
def state(self): def state(self):
try: try:
return self.getData("delMtrReading") self._state = self.getData("delMtrReading")
except: except:
try: try:
return self.getData("billToDateKWH") self._state = self.getData("billToDateKWH")
except: except:
return None pass
return self._state
@property @property
def icon(self): def icon(self):

View File

@@ -10,10 +10,14 @@ class FplProjectedBillSensor(FplEntity):
budget = self.getData("budget_bill") budget = self.getData("budget_bill")
budget_billing_projected_bill = self.getData("budget_billing_projected_bill") budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
if budget == True and budget_billing_projected_bill is not None: try:
return self.getData("budget_billing_projected_bill") if budget == True and budget_billing_projected_bill is not None:
self._state = self.getData("budget_billing_projected_bill")
return self.getData("projected_bill") else:
self._state = self.getData("projected_bill")
except:
self._state = None
return self._state
def defineAttributes(self): def defineAttributes(self):
"""Return the state attributes.""" """Return the state attributes."""
@@ -36,9 +40,12 @@ class DeferedAmountSensor(FplEntity):
@property @property
def state(self): def state(self):
if self.getData("deferred_amount") is not None: try:
return self.getData("deferred_amount") self._state = self.getData("deferred_amount")
return 0 except:
self._state = 0
pass
return self._state
@property @property
def icon(self): def icon(self):
@@ -60,7 +67,11 @@ class ProjectedBudgetBillSensor(FplEntity):
@property @property
def state(self): 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 @property
def icon(self): def icon(self):
@@ -72,7 +83,7 @@ class ProjectedBudgetBillSensor(FplEntity):
attributes["friendly_name"] = "Projected Budget Bill" attributes["friendly_name"] = "Projected Budget Bill"
attributes["device_class"] = "monitary" attributes["device_class"] = "monitary"
attributes["state_class"] = "total" attributes["state_class"] = "total"
attributes['unit_of_measurement'] = "$" attributes["unit_of_measurement"] = "$"
return attributes return attributes
@@ -82,7 +93,11 @@ class ProjectedActualBillSensor(FplEntity):
@property @property
def state(self): def state(self):
return self.getData("projected_bill") try:
self._state = self.getData("projected_bill")
except:
pass
return self._state
@property @property
def icon(self): def icon(self):
@@ -94,6 +109,6 @@ class ProjectedActualBillSensor(FplEntity):
attributes["friendly_name"] = "Projected Actual Bill" attributes["friendly_name"] = "Projected Actual Bill"
attributes["device_class"] = "monitary" attributes["device_class"] = "monitary"
attributes["state_class"] = "total" attributes["state_class"] = "total"
attributes['unit_of_measurement'] = "$" attributes["unit_of_measurement"] = "$"
return attributes return attributes