sensors mini rework

This commit is contained in:
Yordan Suarez
2021-12-13 12:02:39 -05:00
parent c4623d8234
commit ef2516ada4
6 changed files with 104 additions and 89 deletions

View File

@@ -1,10 +1,20 @@
"""BlueprintEntity class"""
from homeassistant.components.sensor import SensorEntity, STATE_CLASS_MEASUREMENT
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.const import (
CURRENCY_DOLLAR,
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
DEVICE_CLASS_MONETARY,
DEVICE_CLASS_TIMESTAMP,
)
from datetime import datetime, timedelta
from .const import DOMAIN, VERSION, ATTRIBUTION
class FplEntity(CoordinatorEntity):
class FplEntity(CoordinatorEntity, SensorEntity):
def __init__(self, coordinator, config_entry, account, sensorName):
super().__init__(coordinator)
self.config_entry = config_entry
@@ -47,3 +57,69 @@ class FplEntity(CoordinatorEntity):
def getData(self, field):
return self.coordinator.data.get(self.account).get(field)
class FplEnergyEntity(FplEntity):
def __init__(self, coordinator, config_entry, account, sensorName):
super().__init__(coordinator, config_entry, account, sensorName)
@property
def state_class(self) -> str:
"""Return the state class of this entity, from STATE_CLASSES, if any."""
return STATE_CLASS_MEASUREMENT
@property
def last_reset(self) -> datetime:
"""Return the time when the sensor was last reset, if any."""
today = datetime.today()
yesterday = today - timedelta(days=1)
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):
def __init__(self, coordinator, config_entry, account, sensorName):
super().__init__(coordinator, config_entry, account, sensorName)
@property
def icon(self):
return "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):
def __init__(self, coordinator, config_entry, account, sensorName):
super().__init__(coordinator, config_entry, account, sensorName)
# @property
# def device_class(self) -> str:
# """Return the class of this device, from component DEVICE_CLASSES."""
# return DEVICE_CLASS_TIMESTAMP
@property
def icon(self):
return "mdi:calendar"