@@ -97,16 +97,13 @@ def unit_of_measurement(self):
97
97
unit_of_measurement = ha .POWER_KILO_WATT
98
98
elif self .device_class is DEVICE_CLASS_TEMPERATURE :
99
99
unit_of_measurement = ha .TEMP_CELSIUS
100
- elif self .device_class is DEVICE_CLASS_FREQUENCY :
101
- if self .metric is Measurand .rpm :
102
- unit_of_measurement = FREQUENCY_RPM
103
- else :
104
- unit_of_measurement = FREQUENCY_HERTZ
105
100
elif self .device_class is DEVICE_CLASS_TIMESTAMP :
106
101
# Home assistant does not define a unit, must be a Datetime object or timestamp string (ISO 8601).
107
102
unit_of_measurement = None
108
103
elif self .device_class is DEVICE_CLASS_VOLTAGE :
109
104
unit_of_measurement = ha .ELECTRIC_POTENTIAL_VOLT
105
+ elif self .metric in [Measurand .rpm , Measurand .frequency ]:
106
+ unit_of_measurement = FREQUENCY_RPM
110
107
return unit_of_measurement
111
108
112
109
@property
@@ -141,12 +138,17 @@ def state_class(self):
141
138
state_class = None
142
139
if self .device_class is DEVICE_CLASS_ENERGY :
143
140
state_class = STATE_CLASS_TOTAL_INCREASING
144
- elif self .device_class in [
145
- DEVICE_CLASS_CURRENT ,
146
- DEVICE_CLASS_POWER ,
147
- DEVICE_CLASS_TEMPERATURE ,
148
- DEVICE_CLASS_BATTERY ,
149
- ]:
141
+ elif (
142
+ self .device_class
143
+ in [
144
+ DEVICE_CLASS_CURRENT ,
145
+ DEVICE_CLASS_VOLTAGE ,
146
+ DEVICE_CLASS_POWER ,
147
+ DEVICE_CLASS_TEMPERATURE ,
148
+ DEVICE_CLASS_BATTERY ,
149
+ ]
150
+ or self .metric in [Measurand .rpm , Measurand .frequency ]
151
+ ):
150
152
state_class = STATE_CLASS_MEASUREMENT
151
153
return state_class
152
154
@@ -166,7 +168,7 @@ def device_class(self):
166
168
Measurand .frequency ,
167
169
Measurand .rpm ,
168
170
]
169
- or self .metric .lower ().startwith ("frequency" )
171
+ or self .metric .lower ().startswith ("frequency" )
170
172
):
171
173
device_class = DEVICE_CLASS_FREQUENCY
172
174
elif self .metric .lower ().startswith ("power." ):
0 commit comments