Use enums in statistics tests (#62191)
This commit is contained in:
parent
a39f0643e8
commit
af631b90e5
2 changed files with 6 additions and 6 deletions
|
@ -10,8 +10,8 @@ from homeassistant.components.recorder.models import States
|
||||||
from homeassistant.components.recorder.util import execute, session_scope
|
from homeassistant.components.recorder.util import execute, session_scope
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
STATE_CLASS_MEASUREMENT,
|
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
|
@ -350,7 +350,7 @@ class StatisticsSensor(SensorEntity):
|
||||||
"""Return the state class of this entity."""
|
"""Return the state class of this entity."""
|
||||||
if self._state_characteristic in STATS_NOT_A_NUMBER:
|
if self._state_characteristic in STATS_NOT_A_NUMBER:
|
||||||
return None
|
return None
|
||||||
return STATE_CLASS_MEASUREMENT
|
return SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
|
|
|
@ -4,7 +4,7 @@ import statistics
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import config as hass_config
|
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 import DOMAIN as STATISTICS_DOMAIN
|
||||||
from homeassistant.components.statistics.sensor import StatisticsSensor
|
from homeassistant.components.statistics.sensor import StatisticsSensor
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -82,7 +82,7 @@ async def test_sensor_defaults_numeric(hass):
|
||||||
state = hass.states.get("sensor.test")
|
state = hass.states.get("sensor.test")
|
||||||
assert state.state == str(round(sum(VALUES_NUMERIC) / len(VALUES_NUMERIC), 2))
|
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_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("buffer_usage_ratio") == round(9 / 20, 2)
|
||||||
assert state.attributes.get("source_value_valid") is True
|
assert state.attributes.get("source_value_valid") is True
|
||||||
assert "age_coverage_ratio" not in state.attributes
|
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")
|
state = hass.states.get("sensor.test")
|
||||||
assert state.state == str(len(VALUES_BINARY))
|
assert state.state == str(len(VALUES_BINARY))
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
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("buffer_usage_ratio") == round(9 / 20, 2)
|
||||||
assert state.attributes.get("source_value_valid") is True
|
assert state.attributes.get("source_value_valid") is True
|
||||||
assert "age_coverage_ratio" not in state.attributes
|
assert "age_coverage_ratio" not in state.attributes
|
||||||
|
@ -444,7 +444,7 @@ async def test_state_class(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("sensor.test_normal")
|
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")
|
state = hass.states.get("sensor.test_nan")
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) is None
|
assert state.attributes.get(ATTR_STATE_CLASS) is None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue