renamed defineAttributes method with customAttributes
This commit is contained in:
@@ -43,7 +43,7 @@ class FplEntity(CoordinatorEntity, SensorEntity):
|
|||||||
"manufacturer": "Florida Power & Light",
|
"manufacturer": "Florida Power & Light",
|
||||||
}
|
}
|
||||||
|
|
||||||
def defineAttributes(self) -> dict:
|
def customAttributes(self) -> dict:
|
||||||
"""override this method to set custom attributes"""
|
"""override this method to set custom attributes"""
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class FplEntity(CoordinatorEntity, SensorEntity):
|
|||||||
"attribution": ATTRIBUTION,
|
"attribution": ATTRIBUTION,
|
||||||
"integration": "FPL",
|
"integration": "FPL",
|
||||||
}
|
}
|
||||||
attributes.update(self.defineAttributes())
|
attributes.update(self.customAttributes())
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
def getData(self, field):
|
def getData(self, field):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Average daily sensors"""
|
"""Average daily sensors"""
|
||||||
|
from homeassistant.components.sensor import STATE_CLASS_TOTAL
|
||||||
from .fplEntity import FplMoneyEntity
|
from .fplEntity import FplMoneyEntity
|
||||||
|
|
||||||
|
|
||||||
@@ -18,10 +19,10 @@ class DailyAverageSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
return self.getData("daily_avg")
|
return self.getData("daily_avg")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total"
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
@@ -35,10 +36,10 @@ class BudgetDailyAverageSensor(FplMoneyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("budget_billing_daily_avg")
|
return self.getData("budget_billing_daily_avg")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total"
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
@@ -52,8 +53,8 @@ class ActualDailyAverageSensor(FplMoneyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("daily_avg")
|
return self.getData("daily_avg")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total"
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
return attributes
|
return attributes
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
"""Daily Usage Sensors"""
|
"""Daily Usage Sensors"""
|
||||||
|
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
|
||||||
|
from datetime import timedelta
|
||||||
from .fplEntity import FplEnergyEntity, FplMoneyEntity
|
from .fplEntity import FplEnergyEntity, FplMoneyEntity
|
||||||
|
|
||||||
|
|
||||||
@@ -17,11 +19,11 @@ class FplDailyUsageSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
data = self.getData("daily_usage")
|
data = self.getData("daily_usage")
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total_increasing"
|
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
||||||
if data is not None and len(data) > 0 and "readTime" in data[-1].keys():
|
if data is not None and len(data) > 0 and "readTime" in data[-1].keys():
|
||||||
attributes["date"] = data[-1]["readTime"]
|
attributes["date"] = data[-1]["readTime"]
|
||||||
|
|
||||||
@@ -43,18 +45,16 @@ class FplDailyUsageKWHSensor(FplEnergyEntity):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
data = self.getData("daily_usage")
|
data = self.getData("daily_usage")
|
||||||
|
date = data[-1]["readTime"]
|
||||||
|
last_reset = date - timedelta(days=1)
|
||||||
|
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total_increasing"
|
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
||||||
|
attributes["date"] = date
|
||||||
if data is not None:
|
attributes["last_reset"] = last_reset
|
||||||
if data[-1] is not None and "readTime" in data[-1].keys():
|
|
||||||
attributes["date"] = data[-1]["readTime"]
|
|
||||||
if data[-2] is not None and "readTime" in data[-2].keys():
|
|
||||||
attributes["last_reset"] = data[-2]["readTime"]
|
|
||||||
|
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
@@ -71,14 +71,16 @@ class FplDailyReceivedKWHSensor(FplEnergyEntity):
|
|||||||
return data[-1]["netReceivedKwh"]
|
return data[-1]["netReceivedKwh"]
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
data = self.getData("daily_usage")
|
data = self.getData("daily_usage")
|
||||||
|
date = data[-1]["readTime"]
|
||||||
|
last_reset = date - timedelta(days=1)
|
||||||
|
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total_increasing"
|
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
||||||
attributes["date"] = data[-1]["readTime"]
|
attributes["date"] = date
|
||||||
attributes["last_reset"] = data[-2]["readTime"]
|
attributes["last_reset"] = last_reset
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
@@ -95,12 +97,14 @@ class FplDailyDeliveredKWHSensor(FplEnergyEntity):
|
|||||||
return data[-1]["netDeliveredKwh"]
|
return data[-1]["netDeliveredKwh"]
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
data = self.getData("daily_usage")
|
data = self.getData("daily_usage")
|
||||||
|
date = data[-1]["readTime"]
|
||||||
|
last_reset = date - timedelta(days=1)
|
||||||
|
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total_increasing"
|
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
||||||
attributes["date"] = data[-1]["readTime"]
|
attributes["date"] = date
|
||||||
attributes["last_reset"] = data[-2]["readTime"]
|
attributes["last_reset"] = last_reset
|
||||||
return attributes
|
return attributes
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
"""energy sensors"""
|
"""energy sensors"""
|
||||||
|
from datetime import date, timedelta
|
||||||
|
import datetime
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
STATE_CLASS_TOTAL,
|
STATE_CLASS_TOTAL,
|
||||||
@@ -14,7 +16,7 @@ class ProjectedKWHSensor(FplEnergyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("projectedKWH")
|
return self.getData("projectedKWH")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
@@ -29,7 +31,7 @@ class DailyAverageKWHSensor(FplEnergyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("dailyAverageKWH")
|
return self.getData("dailyAverageKWH")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
@@ -44,10 +46,17 @@ class BillToDateKWHSensor(FplEnergyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("billToDateKWH")
|
return self.getData("billToDateKWH")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
|
||||||
|
# data = self.getData("daily_usage")
|
||||||
|
# date = data[-1]["readTime"]
|
||||||
|
asOfDays = self.getData("as_of_days")
|
||||||
|
last_reset = date.today() - timedelta(days=asOfDays)
|
||||||
|
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
||||||
|
attributes["last_reset"] = last_reset
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +68,7 @@ class NetReceivedKWHSensor(FplEnergyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("recMtrReading")
|
return self.getData("recMtrReading")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
||||||
@@ -74,7 +83,7 @@ class NetDeliveredKWHSensor(FplEnergyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("delMtrReading")
|
return self.getData("delMtrReading")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
"""Projected bill sensors"""
|
"""Projected bill sensors"""
|
||||||
|
from homeassistant.components.sensor import (
|
||||||
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
STATE_CLASS_TOTAL,
|
||||||
|
)
|
||||||
from .fplEntity import FplMoneyEntity
|
from .fplEntity import FplMoneyEntity
|
||||||
|
|
||||||
|
|
||||||
@@ -18,10 +22,10 @@ class FplProjectedBillSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
return self.getData("projected_bill")
|
return self.getData("projected_bill")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total"
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
attributes["budget_bill"] = self.getData("budget_bill")
|
attributes["budget_bill"] = self.getData("budget_bill")
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
@@ -39,10 +43,10 @@ class DeferedAmountSensor(FplMoneyEntity):
|
|||||||
return self.getData("defered_amount")
|
return self.getData("defered_amount")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total"
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
@@ -56,10 +60,10 @@ class ProjectedBudgetBillSensor(FplMoneyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("budget_billing_projected_bill")
|
return self.getData("budget_billing_projected_bill")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total"
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
@@ -73,8 +77,8 @@ class ProjectedActualBillSensor(FplMoneyEntity):
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self.getData("projected_bill")
|
return self.getData("projected_bill")
|
||||||
|
|
||||||
def defineAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = "total"
|
attributes["state_class"] = STATE_CLASS_TOTAL
|
||||||
return attributes
|
return attributes
|
||||||
|
|||||||
Reference in New Issue
Block a user