mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Use enums in statistics tests (#62191)
This commit is contained in:
parent
a39f0643e8
commit
af631b90e5
@ -10,8 +10,8 @@ from homeassistant.components.recorder.models import States
|
||||
from homeassistant.components.recorder.util import execute, session_scope
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorEntity,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
@ -350,7 +350,7 @@ class StatisticsSensor(SensorEntity):
|
||||
"""Return the state class of this entity."""
|
||||
if self._state_characteristic in STATS_NOT_A_NUMBER:
|
||||
return None
|
||||
return STATE_CLASS_MEASUREMENT
|
||||
return SensorStateClass.MEASUREMENT
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
|
@ -4,7 +4,7 @@ import statistics
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import config as hass_config
|
||||
from homeassistant.components.sensor import ATTR_STATE_CLASS, STATE_CLASS_MEASUREMENT
|
||||
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
|
||||
from homeassistant.components.statistics import DOMAIN as STATISTICS_DOMAIN
|
||||
from homeassistant.components.statistics.sensor import StatisticsSensor
|
||||
from homeassistant.const import (
|
||||
@ -82,7 +82,7 @@ async def test_sensor_defaults_numeric(hass):
|
||||
state = hass.states.get("sensor.test")
|
||||
assert state.state == str(round(sum(VALUES_NUMERIC) / len(VALUES_NUMERIC), 2))
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||
assert state.attributes.get("buffer_usage_ratio") == round(9 / 20, 2)
|
||||
assert state.attributes.get("source_value_valid") is True
|
||||
assert "age_coverage_ratio" not in state.attributes
|
||||
@ -167,7 +167,7 @@ async def test_sensor_defaults_binary(hass):
|
||||
state = hass.states.get("sensor.test")
|
||||
assert state.state == str(len(VALUES_BINARY))
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||
assert state.attributes.get("buffer_usage_ratio") == round(9 / 20, 2)
|
||||
assert state.attributes.get("source_value_valid") is True
|
||||
assert "age_coverage_ratio" not in state.attributes
|
||||
@ -444,7 +444,7 @@ async def test_state_class(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.test_normal")
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||
state = hass.states.get("sensor.test_nan")
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is None
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user