Skip to content

Commit

Permalink
Simplifying CostSensor object
Browse files Browse the repository at this point in the history
  • Loading branch information
valleedelisle committed Jan 3, 2022
1 parent eacf676 commit b705ec6
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions custom_components/hilo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
CONF_SCAN_INTERVAL,
CURRENCY_DOLLAR,
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CO2,
DEVICE_CLASS_ENERGY,
Expand Down Expand Up @@ -537,23 +538,21 @@ def icon(self):
return "mdi:access-point-network"


class HiloCostSensor(RestoreEntity):
class HiloCostSensor(RestoreEntity, SensorEntity):

_attr_device_class = DEVICE_CLASS_MONETARY
_attr_native_unit_of_measurement = f"{CURRENCY_DOLLAR}/{ENERGY_KILO_WATT_HOUR}"
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_icon = "mdi:cash"

def __init__(self, name, plan_name, amount=0):
self.data = None
self._name = name
self._attr_name = name
self.plan_name = plan_name
self._amount = amount
self._last_update = dt_util.utcnow()
LOG.info(f"Initializing energy cost sensor {name} {plan_name} Amount: {amount}")

@property
def name(self):
return self._name

@property
def icon(self):
return "mdi:cash"

@property
def state(self):
return self._amount
Expand All @@ -562,18 +561,6 @@ def state(self):
def should_poll(self) -> bool:
return False

@property
def state_class(self):
return STATE_CLASS_MEASUREMENT

@property
def device_class(self):
return "monetary"

@property
def unit_of_measurement(self):
return "$/kWh"

@property
def extra_state_attributes(self):
return {"last_update": self._last_update, "Cost": self.state}
Expand Down

0 comments on commit b705ec6

Please sign in to comment.