Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ black==21.7b0
flake8==3.9.2
reorder-python-imports==2.6.0
websockets==9.1
sqlalchemy==1.4.17
sqlalchemy==1.4.23
ocpp>=0.8.3
30 changes: 11 additions & 19 deletions custom_components/ocpp/sensor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Sensor platform for ocpp."""

import datetime

import homeassistant
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity,
)
from homeassistant.const import (
CONF_MONITORED_VARIABLES,
DEVICE_CLASS_CURRENT,
Expand Down Expand Up @@ -78,16 +80,7 @@ def unique_id(self):
@property
def state(self):
"""Return the state of the sensor."""
old_state = self._state
new_state = self.central_system.get_metric(self.cp_id, self.metric)
self._state = new_state
if (
(self.device_class is DEVICE_CLASS_ENERGY)
and (new_state is not None)
and (old_state is not None)
and (new_state < old_state)
):
self._last_reset = datetime.datetime.now()
self._state = self.central_system.get_metric(self.cp_id, self.metric)
return self._state

@property
Expand Down Expand Up @@ -129,7 +122,11 @@ def extra_state_attributes(self):
@property
def state_class(self):
"""Return the state class of the sensor."""
return STATE_CLASS_MEASUREMENT
if self.device_class is DEVICE_CLASS_ENERGY:
state_class = STATE_CLASS_TOTAL_INCREASING
else:
state_class = STATE_CLASS_MEASUREMENT
return state_class

@property
def device_class(self):
Expand All @@ -156,11 +153,6 @@ def device_class(self):
else:
return None

@property
def last_reset(self):
"""Return the time when a metered value wwas ;ast reset."""
return self._last_reset

async def async_update(self):
"""Get the latest data and update the states."""
pass
3 changes: 1 addition & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

pre-commit
homeassistant>=2021.6.6
homeassistant>=2021.8.0
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r requirements_dev.txt
pytest-homeassistant-custom-component==0.4.3
pytest-homeassistant-custom-component==0.4.4
websockets
ocpp