Skip to content

Commit c76f0fa

Browse files
author
lbbrhzn
authored
update state_class and device_class for timestamps (#196)
Co-authored-by: lbbrhzn <@lbbrhzn>
1 parent ac9db95 commit c76f0fa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

custom_components/ocpp/sensor.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ def state_class(self):
121121
state_class = None
122122
if self.device_class is DEVICE_CLASS_ENERGY:
123123
state_class = STATE_CLASS_TOTAL_INCREASING
124-
elif self.device_class is not None:
124+
elif self.device_class in [
125+
DEVICE_CLASS_CURRENT,
126+
DEVICE_CLASS_POWER,
127+
DEVICE_CLASS_TEMPERATURE,
128+
DEVICE_CLASS_BATTERY,
129+
]:
125130
state_class = STATE_CLASS_MEASUREMENT
126131
return state_class
127132

@@ -141,7 +146,11 @@ def device_class(self):
141146
device_class = DEVICE_CLASS_TEMPERATURE
142147
elif self.metric.lower().startswith("soc"):
143148
device_class = DEVICE_CLASS_BATTERY
144-
elif self.metric.lower().startswith("heartbeat"):
149+
elif self.metric in [
150+
HAChargerDetails.config_response.value,
151+
HAChargerDetails.data_response.value,
152+
HAChargerStatuses.heartbeat.value,
153+
]:
145154
device_class = DEVICE_CLASS_TIMESTAMP
146155
return device_class
147156

0 commit comments

Comments
 (0)