6
6
STATE_CLASS_TOTAL_INCREASING ,
7
7
SensorEntity ,
8
8
)
9
+ import homeassistant .const as ha
9
10
from homeassistant .const import (
10
11
CONF_MONITORED_VARIABLES ,
11
12
DEVICE_CLASS_BATTERY ,
@@ -59,7 +60,6 @@ def __init__(
59
60
self .central_system = central_system
60
61
self .cp_id = cp_id
61
62
self .metric = metric
62
- self ._state = None
63
63
self ._extra_attr = {}
64
64
self ._last_reset = homeassistant .util .dt .utc_from_timestamp (0 )
65
65
@@ -73,12 +73,6 @@ def unique_id(self):
73
73
"""Return the unique id of this sensor."""
74
74
return "." .join ([DOMAIN , self .cp_id , self .metric , "sensor" ])
75
75
76
- @property
77
- def state (self ):
78
- """Return the state of the sensor."""
79
- self ._state = self .central_system .get_metric (self .cp_id , self .metric )
80
- return self ._state
81
-
82
76
@property
83
77
def available (self ) -> bool :
84
78
"""Return if sensor is available."""
@@ -87,7 +81,22 @@ def available(self) -> bool:
87
81
@property
88
82
def unit_of_measurement (self ):
89
83
"""Return the unit the value is expressed in."""
90
- return self .central_system .get_ha_unit (self .cp_id , self .metric )
84
+ unit_of_measurement = None
85
+ if self .device_class is DEVICE_CLASS_BATTERY :
86
+ unit_of_measurement = ha .PERCENTAGE
87
+ elif self .device_class is DEVICE_CLASS_CURRENT :
88
+ unit_of_measurement = ha .ELECTRIC_CURRENT_AMPERE
89
+ elif self .device_class is DEVICE_CLASS_ENERGY :
90
+ unit_of_measurement = ha .ENERGY_KILO_WATT_HOUR
91
+ elif self .device_class is DEVICE_CLASS_POWER :
92
+ unit_of_measurement = ha .POWER_KILO_WATT
93
+ elif self .device_class is DEVICE_CLASS_TEMPERATURE :
94
+ unit_of_measurement = ha .TEMP_CELSIUS
95
+ elif self .device_class is DEVICE_CLASS_TIMESTAMP :
96
+ unit_of_measurement = None
97
+ elif self .device_class is DEVICE_CLASS_VOLTAGE :
98
+ unit_of_measurement = ha .ELECTRIC_POTENTIAL_VOLT
99
+ return unit_of_measurement
91
100
92
101
@property
93
102
def should_poll (self ):
0 commit comments