Fixing sensor metadata

This commit is contained in:
Adam Outler
2021-12-30 15:07:04 -05:00
parent 621fea3042
commit 485717d662
5 changed files with 48 additions and 28 deletions

View File

@@ -27,7 +27,7 @@ class AllDataSensor(FplEntity):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Budget Projected Bill"
attributes["device_class"] = "monitary"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes

View File

@@ -23,7 +23,7 @@ class FplAverageDailySensor(FplEntity):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Daily Average"
attributes["device_class"] = "monitary"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes

View File

@@ -9,7 +9,7 @@ class FplDailyUsageSensor(FplEntity):
def state(self):
data = self.getData("daily_usage")
if ((data is not None) and (len(data) > 0)):
if (data is not None) and (len(data) > 0):
return data[-1]["cost"]
return None
@@ -22,8 +22,11 @@ class FplDailyUsageSensor(FplEntity):
attributes["device_class"] = "monetary"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "$"
if ((data is not None) and (data[-1]["cost"] is not None)):
attributes["date"] = data[-1]["readTime"]
if data is not None:
if (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):
attributes["last_reset"] = data[-2]["readTime"]
return attributes
@property
@@ -39,7 +42,7 @@ class FplDailyUsageKWHSensor(FplEntity):
def state(self):
data = self.getData("daily_usage")
if ((data is not None) and (data[-1]["usage"] is not None)):
if (data is not None) and (data[-1]["usage"] is not None):
return data[-1]["usage"]
return None
@@ -55,9 +58,9 @@ 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 (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 (data[-2] is not None) and (data[-2]["readTime"] is not None):
attributes["last_reset"] = data[-2]["readTime"]
return attributes
@@ -66,6 +69,7 @@ class FplDailyUsageKWHSensor(FplEntity):
def icon(self):
return "mdi:flash"
class FplDailyReceivedKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Received KWH")
@@ -73,7 +77,10 @@ class FplDailyReceivedKWHSensor(FplEntity):
@property
def state(self):
data = self.getData("daily_usage")
return data[-1]["netReceivedKwh"]
try:
return data[-1]["netReceivedKwh"]
except:
return 0
def defineAttributes(self):
"""Return the state attributes."""
@@ -84,15 +91,18 @@ class FplDailyReceivedKWHSensor(FplEntity):
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
attributes["date"] = data[-1]["readTime"]
attributes["last_reset"] = data[-2]["readTime"]
if data is not None:
if (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):
attributes["last_reset"] = data[-2]["readTime"]
return attributes
@property
def icon(self):
return "mdi:flash"
class FplDailyDeliveredKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Delivered KWH")
@@ -100,7 +110,7 @@ class FplDailyDeliveredKWHSensor(FplEntity):
@property
def state(self):
data = self.getData("daily_usage")
return data[-1]["netDeliveredKwh"]
return data[-1]["netDeliveredKwh"]
def defineAttributes(self):
"""Return the state attributes."""
@@ -111,8 +121,11 @@ class FplDailyDeliveredKWHSensor(FplEntity):
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
attributes["date"] = data[-1]["readTime"]
attributes["last_reset"] = data[-2]["readTime"]
if data is not None:
if (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):
attributes["last_reset"] = data[-2]["readTime"]
return attributes
@property

View File

@@ -17,7 +17,7 @@ class ProjectedKWHSensor(FplEntity):
attributes = {}
attributes["friendly_name"] = "Projected KWH"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "kWh"
return attributes
@@ -38,7 +38,7 @@ class DailyAverageKWHSensor(FplEntity):
attributes = {}
attributes["friendly_name"] = "Daily Average"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "kWh"
return attributes
@@ -57,10 +57,11 @@ class BillToDateKWHSensor(FplEntity):
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Bill To Date"
attributes["friendly_name"] = "Billing Usage"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
attributes["last_reset"] = self.getData("billStartDate")
return attributes
class NetReceivedKWHSensor(FplEntity):
@@ -69,7 +70,10 @@ class NetReceivedKWHSensor(FplEntity):
@property
def state(self):
return self.getData("recMtrReading")
try:
return self.getData("recMtrReading")
except:
return 0
@property
def icon(self):
@@ -92,7 +96,10 @@ class NetDeliveredKWHSensor(FplEntity):
@property
def state(self):
return self.getData("delMtrReading")
try:
return self.getData("delMtrReading")
except:
return self.getData("billToDateKWH")
@property
def icon(self):

View File

@@ -18,8 +18,8 @@ class FplProjectedBillSensor(FplEntity):
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Projected Bill"
attributes["device_class"] = "monitary"
attributes["friendly_name"] = "Projected Bill Payment Due"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes
@@ -32,12 +32,12 @@ class FplProjectedBillSensor(FplEntity):
# Defered Amount
class DeferedAmountSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Defered Amount")
super().__init__(coordinator, config, account, "Deferred Amount")
@property
def state(self):
if self.getData("defered_amount") is not None:
return self.getData("defered_amount")
if self.getData("deferred_amount") is not None:
return self.getData("deferred_amount")
return 0
@property
@@ -47,8 +47,8 @@ class DeferedAmountSensor(FplEntity):
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Defered Amount"
attributes["device_class"] = "monitary"
attributes["friendly_name"] = "Deferred Amount"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes