Set state class to total for net utility_meter sensors (#55877)

* Set state class to total for net utility_meter sensors

* Update tests
This commit is contained in:
Erik Montnemery 2021-09-07 08:13:14 +02:00 committed by GitHub
parent 1ca9deb520
commit 0d1412ea17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -8,7 +8,7 @@ import voluptuous as vol
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
ATTR_LAST_RESET, ATTR_LAST_RESET,
STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL,
STATE_CLASS_TOTAL_INCREASING, STATE_CLASS_TOTAL_INCREASING,
SensorEntity, SensorEntity,
) )
@ -357,7 +357,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
def state_class(self): def state_class(self):
"""Return the device class of the sensor.""" """Return the device class of the sensor."""
return ( return (
STATE_CLASS_MEASUREMENT STATE_CLASS_TOTAL
if self._sensor_net_consumption if self._sensor_net_consumption
else STATE_CLASS_TOTAL_INCREASING else STATE_CLASS_TOTAL_INCREASING
) )

View File

@ -5,7 +5,7 @@ from unittest.mock import patch
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
ATTR_STATE_CLASS, ATTR_STATE_CLASS,
STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL,
STATE_CLASS_TOTAL_INCREASING, STATE_CLASS_TOTAL_INCREASING,
) )
from homeassistant.components.utility_meter.const import ( from homeassistant.components.utility_meter.const import (
@ -219,7 +219,7 @@ async def test_device_class(hass):
assert state is not None assert state is not None
assert state.state == "0" assert state.state == "0"
assert state.attributes.get(ATTR_DEVICE_CLASS) is None assert state.attributes.get(ATTR_DEVICE_CLASS) is None
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
state = hass.states.get("sensor.gas_meter") state = hass.states.get("sensor.gas_meter")
@ -241,7 +241,7 @@ async def test_device_class(hass):
assert state is not None assert state is not None
assert state.state == "1" assert state.state == "1"
assert state.attributes.get(ATTR_DEVICE_CLASS) == "energy" assert state.attributes.get(ATTR_DEVICE_CLASS) == "energy"
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
state = hass.states.get("sensor.gas_meter") state = hass.states.get("sensor.gas_meter")