Files
hass-fpl/custom_components/fpl/sensor_AverageDailySensor.py
2022-01-01 12:17:37 -05:00

60 lines
1.7 KiB
Python

from .fplEntity import FplEntity
class FplAverageDailySensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Average")
@property
def state(self):
budget = self.getData("budget_bill")
budget_billing_projected_bill = self.getData("budget_billing_daily_avg")
if budget == True and budget_billing_projected_bill is not None:
return self.getData("budget_billing_daily_avg")
try:
self._state=self.getData("daily_avg")
except:
pass
return self._state
@property
def icon(self):
return "mdi:currency-usd"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Daily Average"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes
class BudgetDailyAverageSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Budget Daily Average")
@property
def state(self):
try:
self._state= self.getData("budget_billing_daily_avg")
except:
pass
return self._state
@property
def icon(self):
return "mdi:currency-usd"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Budget Daily Average"
attributes["device_class"] = "monitary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes