make use of _attr_
This commit is contained in:
@@ -17,6 +17,8 @@ from .const import DOMAIN, VERSION, ATTRIBUTION
|
|||||||
class FplEntity(CoordinatorEntity, SensorEntity):
|
class FplEntity(CoordinatorEntity, SensorEntity):
|
||||||
"""FPL base entity"""
|
"""FPL base entity"""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
|
|
||||||
def __init__(self, coordinator, config_entry, account, sensorName):
|
def __init__(self, coordinator, config_entry, account, sensorName):
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
@@ -26,9 +28,8 @@ class FplEntity(CoordinatorEntity, SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the ID of this device."""
|
"""Return the ID of this device."""
|
||||||
return "{}{}{}".format(
|
sensorName = self.sensorName.lower().replace(" ", "")
|
||||||
DOMAIN, self.account, self.sensorName.lower().replace(" ", "")
|
return f"{DOMAIN}{self.account}{sensorName}"
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@@ -51,8 +52,8 @@ class FplEntity(CoordinatorEntity, SensorEntity):
|
|||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {
|
attributes = {
|
||||||
"attribution": ATTRIBUTION,
|
# "attribution": ATTRIBUTION,
|
||||||
"integration": "FPL",
|
# "integration": "FPL",
|
||||||
}
|
}
|
||||||
attributes.update(self.customAttributes())
|
attributes.update(self.customAttributes())
|
||||||
return attributes
|
return attributes
|
||||||
@@ -65,11 +66,10 @@ class FplEntity(CoordinatorEntity, SensorEntity):
|
|||||||
class FplEnergyEntity(FplEntity):
|
class FplEnergyEntity(FplEntity):
|
||||||
"""Represents a energy sensor"""
|
"""Represents a energy sensor"""
|
||||||
|
|
||||||
@property
|
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||||
def state_class(self) -> str:
|
_attr_device_class = DEVICE_CLASS_ENERGY
|
||||||
"""Return the state class of this entity, from STATE_CLASSES, if any."""
|
_attr_icon = "mdi:flash"
|
||||||
|
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
return STATE_CLASS_MEASUREMENT
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_reset(self) -> datetime:
|
def last_reset(self) -> datetime:
|
||||||
@@ -79,65 +79,23 @@ class FplEnergyEntity(FplEntity):
|
|||||||
yesterday = today - timedelta(days=1)
|
yesterday = today - timedelta(days=1)
|
||||||
return datetime.combine(yesterday, datetime.min.time())
|
return datetime.combine(yesterday, datetime.min.time())
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> str:
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return DEVICE_CLASS_ENERGY
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self) -> str:
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return ENERGY_KILO_WATT_HOUR
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
return "mdi:flash"
|
|
||||||
|
|
||||||
|
|
||||||
class FplMoneyEntity(FplEntity):
|
class FplMoneyEntity(FplEntity):
|
||||||
"""Represents a money sensor"""
|
"""Represents a money sensor"""
|
||||||
|
|
||||||
@property
|
_attr_native_unit_of_measurement = CURRENCY_DOLLAR
|
||||||
def icon(self):
|
_attr_device_class = DEVICE_CLASS_MONETARY
|
||||||
return "mdi:currency-usd"
|
_attr_icon = "mdi:currency-usd"
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> str:
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return DEVICE_CLASS_MONETARY
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self) -> str:
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return CURRENCY_DOLLAR
|
|
||||||
|
|
||||||
|
|
||||||
class FplDateEntity(FplEntity):
|
class FplDateEntity(FplEntity):
|
||||||
"""Represents a date or days"""
|
"""Represents a date or days"""
|
||||||
|
|
||||||
# @property
|
_attr_icon = "mdi:calendar"
|
||||||
# def device_class(self) -> str:
|
|
||||||
# """Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
# return DEVICE_CLASS_DATE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
return "mdi:calendar"
|
|
||||||
|
|
||||||
|
|
||||||
class FplDayEntity(FplEntity):
|
class FplDayEntity(FplEntity):
|
||||||
"""Represents a date or days"""
|
"""Represents a date or days"""
|
||||||
|
|
||||||
# @property
|
_attr_native_unit_of_measurement = "days"
|
||||||
# def device_class(self) -> str:
|
_attr_icon = "mdi:calendar"
|
||||||
# """Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
# return DEVICE_CLASS_DATE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
return "mdi:calendar"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self) -> str:
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return "days"
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Daily Usage Sensors"""
|
"""Daily Usage Sensors"""
|
||||||
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
|
||||||
from .fplEntity import FplEnergyEntity, FplMoneyEntity
|
from .fplEntity import FplEnergyEntity, FplMoneyEntity
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ from .fplEntity import FplMoneyEntity
|
|||||||
|
|
||||||
|
|
||||||
class FplProjectedBillSensor(FplMoneyEntity):
|
class FplProjectedBillSensor(FplMoneyEntity):
|
||||||
"""projected bill sensor"""
|
"""Projected bill sensor"""
|
||||||
|
|
||||||
|
_attr_state_class = STATE_CLASS_TOTAL
|
||||||
|
|
||||||
def __init__(self, coordinator, config, account):
|
def __init__(self, coordinator, config, account):
|
||||||
super().__init__(coordinator, config, account, "Projected Bill")
|
super().__init__(coordinator, config, account, "Projected Bill")
|
||||||
@@ -22,22 +24,9 @@ class FplProjectedBillSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
return self.getData("projected_bill")
|
return self.getData("projected_bill")
|
||||||
|
|
||||||
"""
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
budget = self.getData("budget_bill")
|
|
||||||
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
|
|
||||||
|
|
||||||
if budget and budget_billing_projected_bill is not None:
|
|
||||||
return self.getData("budget_billing_projected_bill")
|
|
||||||
|
|
||||||
return self.getData("projected_bill")
|
|
||||||
"""
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL
|
|
||||||
attributes["budget_bill"] = self.getData("budget_bill")
|
attributes["budget_bill"] = self.getData("budget_bill")
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
@@ -46,51 +35,39 @@ class FplProjectedBillSensor(FplMoneyEntity):
|
|||||||
class DeferedAmountSensor(FplMoneyEntity):
|
class DeferedAmountSensor(FplMoneyEntity):
|
||||||
"""Defered amount sensor"""
|
"""Defered amount sensor"""
|
||||||
|
|
||||||
|
_attr_state_class = STATE_CLASS_TOTAL
|
||||||
|
|
||||||
def __init__(self, coordinator, config, account):
|
def __init__(self, coordinator, config, account):
|
||||||
super().__init__(coordinator, config, account, "Defered Amount")
|
super().__init__(coordinator, config, account, "Defered Amount")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def native_value(self):
|
||||||
if self.getData("budget_bill"):
|
if self.getData("budget_bill"):
|
||||||
return self.getData("defered_amount")
|
return self.getData("defered_amount")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def customAttributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
attributes = {}
|
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL
|
|
||||||
return attributes
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectedBudgetBillSensor(FplMoneyEntity):
|
class ProjectedBudgetBillSensor(FplMoneyEntity):
|
||||||
"""projected budget bill sensor"""
|
"""projected budget bill sensor"""
|
||||||
|
|
||||||
|
_attr_state_class = STATE_CLASS_TOTAL
|
||||||
|
|
||||||
def __init__(self, coordinator, config, account):
|
def __init__(self, coordinator, config, account):
|
||||||
super().__init__(coordinator, config, account, "Projected Budget Bill")
|
super().__init__(coordinator, config, account, "Projected Budget Bill")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def native_value(self):
|
||||||
return self.getData("budget_billing_projected_bill")
|
return self.getData("budget_billing_projected_bill")
|
||||||
|
|
||||||
def customAttributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
attributes = {}
|
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL
|
|
||||||
return attributes
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectedActualBillSensor(FplMoneyEntity):
|
class ProjectedActualBillSensor(FplMoneyEntity):
|
||||||
"""projeted actual bill sensor"""
|
"""projeted actual bill sensor"""
|
||||||
|
|
||||||
|
_attr_state_class = STATE_CLASS_TOTAL
|
||||||
|
|
||||||
def __init__(self, coordinator, config, account):
|
def __init__(self, coordinator, config, account):
|
||||||
super().__init__(coordinator, config, account, "Projected Actual Bill")
|
super().__init__(coordinator, config, account, "Projected Actual Bill")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def native_value(self):
|
||||||
return self.getData("projected_bill")
|
return self.getData("projected_bill")
|
||||||
|
|
||||||
def customAttributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
attributes = {}
|
|
||||||
attributes["state_class"] = STATE_CLASS_TOTAL
|
|
||||||
return attributes
|
|
||||||
|
|||||||
Reference in New Issue
Block a user