mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Utility meter, add STATE_CLASS_TOTAL_INCREASING (#54871)
* Utility meter, STATE_CLASS_TOTAL_INCREASING Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> * update test Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> * update test Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
This commit is contained in:
parent
f4fbc083e6
commit
7dd169b48e
@ -5,7 +5,11 @@ import logging
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
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 (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
@ -330,7 +334,11 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def state_class(self):
|
def state_class(self):
|
||||||
"""Return the device class of the sensor."""
|
"""Return the device class of the sensor."""
|
||||||
return STATE_CLASS_MEASUREMENT
|
return (
|
||||||
|
STATE_CLASS_MEASUREMENT
|
||||||
|
if self._sensor_net_consumption
|
||||||
|
else STATE_CLASS_TOTAL_INCREASING
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self):
|
def native_unit_of_measurement(self):
|
||||||
|
@ -3,7 +3,11 @@ from contextlib import contextmanager
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.sensor import ATTR_STATE_CLASS, STATE_CLASS_MEASUREMENT
|
from homeassistant.components.sensor import (
|
||||||
|
ATTR_STATE_CLASS,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
)
|
||||||
from homeassistant.components.utility_meter.const import (
|
from homeassistant.components.utility_meter.const import (
|
||||||
ATTR_TARIFF,
|
ATTR_TARIFF,
|
||||||
ATTR_VALUE,
|
ATTR_VALUE,
|
||||||
@ -165,6 +169,7 @@ async def test_device_class(hass):
|
|||||||
"utility_meter": {
|
"utility_meter": {
|
||||||
"energy_meter": {
|
"energy_meter": {
|
||||||
"source": "sensor.energy",
|
"source": "sensor.energy",
|
||||||
|
"net_consumption": True,
|
||||||
},
|
},
|
||||||
"gas_meter": {
|
"gas_meter": {
|
||||||
"source": "sensor.gas",
|
"source": "sensor.gas",
|
||||||
@ -197,7 +202,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_INCREASING
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
||||||
|
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
@ -219,7 +224,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) 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_INCREASING
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "some_archaic_unit"
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "some_archaic_unit"
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user