mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
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:
parent
1ca9deb520
commit
0d1412ea17
@ -8,7 +8,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
ATTR_LAST_RESET,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorEntity,
|
||||
)
|
||||
@ -357,7 +357,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
|
||||
def state_class(self):
|
||||
"""Return the device class of the sensor."""
|
||||
return (
|
||||
STATE_CLASS_MEASUREMENT
|
||||
STATE_CLASS_TOTAL
|
||||
if self._sensor_net_consumption
|
||||
else STATE_CLASS_TOTAL_INCREASING
|
||||
)
|
||||
|
@ -5,7 +5,7 @@ from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
ATTR_STATE_CLASS,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
)
|
||||
from homeassistant.components.utility_meter.const import (
|
||||
@ -219,7 +219,7 @@ async def test_device_class(hass):
|
||||
assert state is not None
|
||||
assert state.state == "0"
|
||||
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
|
||||
|
||||
state = hass.states.get("sensor.gas_meter")
|
||||
@ -241,7 +241,7 @@ async def test_device_class(hass):
|
||||
assert state is not None
|
||||
assert state.state == "1"
|
||||
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
|
||||
|
||||
state = hass.states.get("sensor.gas_meter")
|
||||
|
Loading…
x
Reference in New Issue
Block a user