mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add missing state_class
to min_max sensors (#73169)
Add missing state_class
This commit is contained in:
parent
68d67a3e49
commit
c6b835dd91
@ -6,7 +6,11 @@ import statistics
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import (
|
||||||
|
PLATFORM_SCHEMA,
|
||||||
|
SensorEntity,
|
||||||
|
SensorStateClass,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
@ -232,6 +236,11 @@ class MinMaxSensor(SensorEntity):
|
|||||||
"""Return the icon to use in the frontend, if any."""
|
"""Return the icon to use in the frontend, if any."""
|
||||||
return ICON
|
return ICON
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state_class(self) -> SensorStateClass:
|
||||||
|
"""Return the state class."""
|
||||||
|
return SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_min_max_sensor_state_listener(self, event, update_state=True):
|
def _async_min_max_sensor_state_listener(self, event, update_state=True):
|
||||||
"""Handle the sensor state changes."""
|
"""Handle the sensor state changes."""
|
||||||
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
from homeassistant import config as hass_config
|
from homeassistant import config as hass_config
|
||||||
from homeassistant.components.min_max.const import DOMAIN
|
from homeassistant.components.min_max.const import DOMAIN
|
||||||
|
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
@ -76,6 +77,7 @@ async def test_min_sensor(hass):
|
|||||||
|
|
||||||
assert str(float(MIN_VALUE)) == state.state
|
assert str(float(MIN_VALUE)) == state.state
|
||||||
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
||||||
|
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
|
||||||
async def test_max_sensor(hass):
|
async def test_max_sensor(hass):
|
||||||
@ -102,6 +104,7 @@ async def test_max_sensor(hass):
|
|||||||
|
|
||||||
assert str(float(MAX_VALUE)) == state.state
|
assert str(float(MAX_VALUE)) == state.state
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
|
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
|
||||||
async def test_mean_sensor(hass):
|
async def test_mean_sensor(hass):
|
||||||
@ -127,6 +130,7 @@ async def test_mean_sensor(hass):
|
|||||||
state = hass.states.get("sensor.test_mean")
|
state = hass.states.get("sensor.test_mean")
|
||||||
|
|
||||||
assert str(float(MEAN)) == state.state
|
assert str(float(MEAN)) == state.state
|
||||||
|
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
|
||||||
async def test_mean_1_digit_sensor(hass):
|
async def test_mean_1_digit_sensor(hass):
|
||||||
@ -204,6 +208,7 @@ async def test_median_sensor(hass):
|
|||||||
state = hass.states.get("sensor.test_median")
|
state = hass.states.get("sensor.test_median")
|
||||||
|
|
||||||
assert str(float(MEDIAN)) == state.state
|
assert str(float(MEDIAN)) == state.state
|
||||||
|
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
|
||||||
async def test_not_enough_sensor_value(hass):
|
async def test_not_enough_sensor_value(hass):
|
||||||
@ -327,6 +332,7 @@ async def test_last_sensor(hass):
|
|||||||
state = hass.states.get("sensor.test_last")
|
state = hass.states.get("sensor.test_last")
|
||||||
assert str(float(value)) == state.state
|
assert str(float(value)) == state.state
|
||||||
assert entity_id == state.attributes.get("last_entity_id")
|
assert entity_id == state.attributes.get("last_entity_id")
|
||||||
|
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
|
||||||
async def test_reload(hass):
|
async def test_reload(hass):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user