Set state class to total for Integration sensors (#55872)
This commit is contained in:
parent
6895081595
commit
b1dbdec2ea
2 changed files with 9 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
|||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
|
||||
from homeassistant.components.sensor import STATE_CLASS_TOTAL
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_POWER,
|
||||
|
@ -39,7 +39,7 @@ async def test_state(hass) -> None:
|
|||
|
||||
state = hass.states.get("sensor.integration")
|
||||
assert state is not None
|
||||
assert state.attributes.get("state_class") == STATE_CLASS_TOTAL_INCREASING
|
||||
assert state.attributes.get("state_class") == STATE_CLASS_TOTAL
|
||||
assert "device_class" not in state.attributes
|
||||
|
||||
future_now = dt_util.utcnow() + timedelta(seconds=3600)
|
||||
|
@ -57,7 +57,7 @@ async def test_state(hass) -> None:
|
|||
|
||||
assert state.attributes.get("unit_of_measurement") == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get("device_class") == DEVICE_CLASS_ENERGY
|
||||
assert state.attributes.get("state_class") == STATE_CLASS_TOTAL_INCREASING
|
||||
assert state.attributes.get("state_class") == STATE_CLASS_TOTAL
|
||||
|
||||
|
||||
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||
|
@ -104,7 +104,9 @@ async def test_restore_state_failed(hass: HomeAssistant) -> None:
|
|||
State(
|
||||
"sensor.integration",
|
||||
"INVALID",
|
||||
{},
|
||||
{
|
||||
"last_reset": "2019-10-06T21:00:00.000000",
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
|
@ -125,7 +127,7 @@ async def test_restore_state_failed(hass: HomeAssistant) -> None:
|
|||
assert state
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get("unit_of_measurement") == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get("state_class") == STATE_CLASS_TOTAL_INCREASING
|
||||
assert state.attributes.get("state_class") == STATE_CLASS_TOTAL
|
||||
assert "device_class" not in state.attributes
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue