mostly comments and formatting + 2 sensors

This commit is contained in:
Yordan Suarez
2022-01-22 11:54:54 -05:00
parent d99ea36427
commit 3be969883a
10 changed files with 220 additions and 53 deletions

View File

@@ -20,11 +20,12 @@ class FplDailyUsageSensor(FplMoneyEntity):
def defineAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
attributes = {}
attributes["state_class"] = "total_increasing"
if data is not None and len(data) > 0 and "readTime" in data[-1].keys():
attributes["date"] = data[-1]["readTime"]
if data is not None and len(data) > 0 and "date" in data[-1].keys():
return {"date": data[-1]["date"]}
return {}
return attributes
class FplDailyUsageKWHSensor(FplEnergyEntity):
@@ -45,8 +46,61 @@ class FplDailyUsageKWHSensor(FplEnergyEntity):
def defineAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
attributes = {}
attributes["state_class"] = "total_increasing"
if data is not None and len(data) > 0 and "date" in data[-1].keys():
return {"date": data[-1]["date"]}
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"]
return {}
return attributes
class FplDailyReceivedKWHSensor(FplEnergyEntity):
"""daily received Kwh sensor"""
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Received KWH")
@property
def state(self):
data = self.getData("daily_usage")
if data is not None and len(data) > 0 and "netReceivedKwh" in data[-1].keys():
return data[-1]["netReceivedKwh"]
return 0
def defineAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
attributes = {}
attributes["state_class"] = "total_increasing"
attributes["date"] = data[-1]["readTime"]
attributes["last_reset"] = data[-2]["readTime"]
return attributes
class FplDailyDeliveredKWHSensor(FplEnergyEntity):
"""daily delivered Kwh sensor"""
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Delivered KWH")
@property
def state(self):
data = self.getData("daily_usage")
if data is not None and len(data) > 0 and "netDeliveredKwh" in data[-1].keys():
return data[-1]["netDeliveredKwh"]
return 0
def defineAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
attributes = {}
attributes["state_class"] = "total_increasing"
attributes["date"] = data[-1]["readTime"]
attributes["last_reset"] = data[-2]["readTime"]
return attributes