renamed defineAttributes method with customAttributes

This commit is contained in:
Yordan Suarez
2022-03-03 07:31:40 -05:00
parent 3be969883a
commit f3ccfce2e4
5 changed files with 58 additions and 40 deletions

View File

@@ -1,4 +1,6 @@
"""Daily Usage Sensors"""
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
from datetime import timedelta
from .fplEntity import FplEnergyEntity, FplMoneyEntity
@@ -17,11 +19,11 @@ class FplDailyUsageSensor(FplMoneyEntity):
return None
def defineAttributes(self):
def customAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
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():
attributes["date"] = data[-1]["readTime"]
@@ -43,18 +45,16 @@ class FplDailyUsageKWHSensor(FplEnergyEntity):
return None
def defineAttributes(self):
def customAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
date = data[-1]["readTime"]
last_reset = date - timedelta(days=1)
attributes = {}
attributes["state_class"] = "total_increasing"
if data is not None:
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"]
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
attributes["date"] = date
attributes["last_reset"] = last_reset
return attributes
@@ -71,14 +71,16 @@ class FplDailyReceivedKWHSensor(FplEnergyEntity):
return data[-1]["netReceivedKwh"]
return 0
def defineAttributes(self):
def customAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
date = data[-1]["readTime"]
last_reset = date - timedelta(days=1)
attributes = {}
attributes["state_class"] = "total_increasing"
attributes["date"] = data[-1]["readTime"]
attributes["last_reset"] = data[-2]["readTime"]
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
attributes["date"] = date
attributes["last_reset"] = last_reset
return attributes
@@ -95,12 +97,14 @@ class FplDailyDeliveredKWHSensor(FplEnergyEntity):
return data[-1]["netDeliveredKwh"]
return 0
def defineAttributes(self):
def customAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
date = data[-1]["readTime"]
last_reset = date - timedelta(days=1)
attributes = {}
attributes["state_class"] = "total_increasing"
attributes["date"] = data[-1]["readTime"]
attributes["last_reset"] = data[-2]["readTime"]
attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING
attributes["date"] = date
attributes["last_reset"] = last_reset
return attributes