Rewrite min_max unittest tests to pytest style test function (#41296)
* Rewrite min_max unittest tests to pytest style test function For: #40866 * Use uppercase letters for constants * Remove not needed line * Fix missing rename to uppercase Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
8e6a616846
commit
329e56fac0
1 changed files with 252 additions and 248 deletions
|
@ -1,7 +1,6 @@
|
||||||
"""The test for the min/max sensor platform."""
|
"""The test for the min/max sensor platform."""
|
||||||
from os import path
|
from os import path
|
||||||
import statistics
|
import statistics
|
||||||
import unittest
|
|
||||||
|
|
||||||
from homeassistant import config as hass_config
|
from homeassistant import config as hass_config
|
||||||
from homeassistant.components.min_max import DOMAIN
|
from homeassistant.components.min_max import DOMAIN
|
||||||
|
@ -14,32 +13,21 @@ from homeassistant.const import (
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component, setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.async_mock import patch
|
from tests.async_mock import patch
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
|
VALUES = [17, 20, 15.3]
|
||||||
|
COUNT = len(VALUES)
|
||||||
|
MIN_VALUE = min(VALUES)
|
||||||
|
MAX_VALUE = max(VALUES)
|
||||||
|
MEAN = round(sum(VALUES) / COUNT, 2)
|
||||||
|
MEAN_1_DIGIT = round(sum(VALUES) / COUNT, 1)
|
||||||
|
MEAN_4_DIGITS = round(sum(VALUES) / COUNT, 4)
|
||||||
|
MEDIAN = round(statistics.median(VALUES), 2)
|
||||||
|
|
||||||
|
|
||||||
class TestMinMaxSensor(unittest.TestCase):
|
async def test_min_sensor(hass):
|
||||||
"""Test the min/max sensor."""
|
|
||||||
|
|
||||||
def setup_method(self, method):
|
|
||||||
"""Set up things to be run when tests are started."""
|
|
||||||
self.hass = get_test_home_assistant()
|
|
||||||
self.values = [17, 20, 15.3]
|
|
||||||
self.count = len(self.values)
|
|
||||||
self.min = min(self.values)
|
|
||||||
self.max = max(self.values)
|
|
||||||
self.mean = round(sum(self.values) / self.count, 2)
|
|
||||||
self.mean_1_digit = round(sum(self.values) / self.count, 1)
|
|
||||||
self.mean_4_digits = round(sum(self.values) / self.count, 4)
|
|
||||||
self.median = round(statistics.median(self.values), 2)
|
|
||||||
|
|
||||||
def teardown_method(self, method):
|
|
||||||
"""Stop everything that was started."""
|
|
||||||
self.hass.stop()
|
|
||||||
|
|
||||||
def test_min_sensor(self):
|
|
||||||
"""Test the min sensor."""
|
"""Test the min sensor."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -50,24 +38,26 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
|
|
||||||
for entity_id, value in dict(zip(entity_ids, self.values)).items():
|
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
|
||||||
self.hass.states.set(entity_id, value)
|
hass.states.async_set(entity_id, value)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_min")
|
state = hass.states.get("sensor.test_min")
|
||||||
|
|
||||||
assert str(float(self.min)) == 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 self.max == state.attributes.get("max_value")
|
assert MAX_VALUE == state.attributes.get("max_value")
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
assert self.mean == state.attributes.get("mean")
|
assert MEAN == state.attributes.get("mean")
|
||||||
assert self.median == state.attributes.get("median")
|
assert MEDIAN == state.attributes.get("median")
|
||||||
|
|
||||||
def test_max_sensor(self):
|
|
||||||
|
async def test_max_sensor(hass):
|
||||||
"""Test the max sensor."""
|
"""Test the max sensor."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -78,24 +68,26 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
|
|
||||||
for entity_id, value in dict(zip(entity_ids, self.values)).items():
|
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
|
||||||
self.hass.states.set(entity_id, value)
|
hass.states.async_set(entity_id, value)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_max")
|
state = hass.states.get("sensor.test_max")
|
||||||
|
|
||||||
assert str(float(self.max)) == state.state
|
assert str(float(MAX_VALUE)) == state.state
|
||||||
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
||||||
assert self.min == state.attributes.get("min_value")
|
assert MIN_VALUE == state.attributes.get("min_value")
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
assert self.mean == state.attributes.get("mean")
|
assert MEAN == state.attributes.get("mean")
|
||||||
assert self.median == state.attributes.get("median")
|
assert MEDIAN == state.attributes.get("median")
|
||||||
|
|
||||||
def test_mean_sensor(self):
|
|
||||||
|
async def test_mean_sensor(hass):
|
||||||
"""Test the mean sensor."""
|
"""Test the mean sensor."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -106,24 +98,26 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
|
|
||||||
for entity_id, value in dict(zip(entity_ids, self.values)).items():
|
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
|
||||||
self.hass.states.set(entity_id, value)
|
hass.states.async_set(entity_id, value)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = hass.states.get("sensor.test_mean")
|
||||||
|
|
||||||
assert str(float(self.mean)) == state.state
|
assert str(float(MEAN)) == state.state
|
||||||
assert self.min == state.attributes.get("min_value")
|
assert MIN_VALUE == state.attributes.get("min_value")
|
||||||
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
||||||
assert self.max == state.attributes.get("max_value")
|
assert MAX_VALUE == state.attributes.get("max_value")
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
assert self.median == state.attributes.get("median")
|
assert MEDIAN == state.attributes.get("median")
|
||||||
|
|
||||||
def test_mean_1_digit_sensor(self):
|
|
||||||
|
async def test_mean_1_digit_sensor(hass):
|
||||||
"""Test the mean with 1-digit precision sensor."""
|
"""Test the mean with 1-digit precision sensor."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -135,24 +129,26 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
|
|
||||||
for entity_id, value in dict(zip(entity_ids, self.values)).items():
|
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
|
||||||
self.hass.states.set(entity_id, value)
|
hass.states.async_set(entity_id, value)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = hass.states.get("sensor.test_mean")
|
||||||
|
|
||||||
assert str(float(self.mean_1_digit)) == state.state
|
assert str(float(MEAN_1_DIGIT)) == state.state
|
||||||
assert self.min == state.attributes.get("min_value")
|
assert MIN_VALUE == state.attributes.get("min_value")
|
||||||
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
||||||
assert self.max == state.attributes.get("max_value")
|
assert MAX_VALUE == state.attributes.get("max_value")
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
assert self.median == state.attributes.get("median")
|
assert MEDIAN == state.attributes.get("median")
|
||||||
|
|
||||||
def test_mean_4_digit_sensor(self):
|
|
||||||
|
async def test_mean_4_digit_sensor(hass):
|
||||||
"""Test the mean with 1-digit precision sensor."""
|
"""Test the mean with 1-digit precision sensor."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -164,24 +160,26 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
|
|
||||||
for entity_id, value in dict(zip(entity_ids, self.values)).items():
|
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
|
||||||
self.hass.states.set(entity_id, value)
|
hass.states.async_set(entity_id, value)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = hass.states.get("sensor.test_mean")
|
||||||
|
|
||||||
assert str(float(self.mean_4_digits)) == state.state
|
assert str(float(MEAN_4_DIGITS)) == state.state
|
||||||
assert self.min == state.attributes.get("min_value")
|
assert MIN_VALUE == state.attributes.get("min_value")
|
||||||
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
||||||
assert self.max == state.attributes.get("max_value")
|
assert MAX_VALUE == state.attributes.get("max_value")
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
assert self.median == state.attributes.get("median")
|
assert MEDIAN == state.attributes.get("median")
|
||||||
|
|
||||||
def test_median_sensor(self):
|
|
||||||
|
async def test_median_sensor(hass):
|
||||||
"""Test the median sensor."""
|
"""Test the median sensor."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -192,24 +190,26 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
|
|
||||||
for entity_id, value in dict(zip(entity_ids, self.values)).items():
|
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
|
||||||
self.hass.states.set(entity_id, value)
|
hass.states.async_set(entity_id, value)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_median")
|
state = hass.states.get("sensor.test_median")
|
||||||
|
|
||||||
assert str(float(self.median)) == state.state
|
assert str(float(MEDIAN)) == state.state
|
||||||
assert self.min == state.attributes.get("min_value")
|
assert MIN_VALUE == state.attributes.get("min_value")
|
||||||
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
assert entity_ids[2] == state.attributes.get("min_entity_id")
|
||||||
assert self.max == state.attributes.get("max_value")
|
assert MAX_VALUE == state.attributes.get("max_value")
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
assert self.mean == state.attributes.get("mean")
|
assert MEAN == state.attributes.get("mean")
|
||||||
|
|
||||||
def test_not_enough_sensor_value(self):
|
|
||||||
|
async def test_not_enough_sensor_value(hass):
|
||||||
"""Test that there is nothing done if not enough values available."""
|
"""Test that there is nothing done if not enough values available."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -220,14 +220,15 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
|
|
||||||
self.hass.states.set(entity_ids[0], STATE_UNKNOWN)
|
hass.states.async_set(entity_ids[0], STATE_UNKNOWN)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_max")
|
state = hass.states.get("sensor.test_max")
|
||||||
assert STATE_UNKNOWN == state.state
|
assert STATE_UNKNOWN == state.state
|
||||||
assert state.attributes.get("min_entity_id") is None
|
assert state.attributes.get("min_entity_id") is None
|
||||||
assert state.attributes.get("min_value") is None
|
assert state.attributes.get("min_value") is None
|
||||||
|
@ -235,37 +236,38 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
assert state.attributes.get("max_value") is None
|
assert state.attributes.get("max_value") is None
|
||||||
assert state.attributes.get("median") is None
|
assert state.attributes.get("median") is None
|
||||||
|
|
||||||
self.hass.states.set(entity_ids[1], self.values[1])
|
hass.states.async_set(entity_ids[1], VALUES[1])
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_max")
|
state = hass.states.get("sensor.test_max")
|
||||||
assert STATE_UNKNOWN != state.state
|
assert STATE_UNKNOWN != state.state
|
||||||
assert entity_ids[1] == state.attributes.get("min_entity_id")
|
assert entity_ids[1] == state.attributes.get("min_entity_id")
|
||||||
assert self.values[1] == state.attributes.get("min_value")
|
assert VALUES[1] == state.attributes.get("min_value")
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
assert self.values[1] == state.attributes.get("max_value")
|
assert VALUES[1] == state.attributes.get("max_value")
|
||||||
|
|
||||||
self.hass.states.set(entity_ids[2], STATE_UNKNOWN)
|
hass.states.async_set(entity_ids[2], STATE_UNKNOWN)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_max")
|
state = hass.states.get("sensor.test_max")
|
||||||
assert STATE_UNKNOWN != state.state
|
assert STATE_UNKNOWN != state.state
|
||||||
assert entity_ids[1] == state.attributes.get("min_entity_id")
|
assert entity_ids[1] == state.attributes.get("min_entity_id")
|
||||||
assert self.values[1] == state.attributes.get("min_value")
|
assert VALUES[1] == state.attributes.get("min_value")
|
||||||
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
assert entity_ids[1] == state.attributes.get("max_entity_id")
|
||||||
assert self.values[1] == state.attributes.get("max_value")
|
assert VALUES[1] == state.attributes.get("max_value")
|
||||||
|
|
||||||
self.hass.states.set(entity_ids[1], STATE_UNAVAILABLE)
|
hass.states.async_set(entity_ids[1], STATE_UNAVAILABLE)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_max")
|
state = hass.states.get("sensor.test_max")
|
||||||
assert STATE_UNKNOWN == state.state
|
assert STATE_UNKNOWN == state.state
|
||||||
assert state.attributes.get("min_entity_id") is None
|
assert state.attributes.get("min_entity_id") is None
|
||||||
assert state.attributes.get("min_value") is None
|
assert state.attributes.get("min_value") is None
|
||||||
assert state.attributes.get("max_entity_id") is None
|
assert state.attributes.get("max_entity_id") is None
|
||||||
assert state.attributes.get("max_value") is None
|
assert state.attributes.get("max_value") is None
|
||||||
|
|
||||||
def test_different_unit_of_measurement(self):
|
|
||||||
|
async def test_different_unit_of_measurement(hass):
|
||||||
"""Test for different unit of measurement."""
|
"""Test for different unit of measurement."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -276,41 +278,43 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
|
|
||||||
self.hass.states.set(
|
hass.states.async_set(
|
||||||
entity_ids[0], self.values[0], {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
entity_ids[0], VALUES[0], {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||||
)
|
)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test")
|
state = hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert str(float(self.values[0])) == state.state
|
assert str(float(VALUES[0])) == state.state
|
||||||
assert state.attributes.get("unit_of_measurement") == TEMP_CELSIUS
|
assert state.attributes.get("unit_of_measurement") == TEMP_CELSIUS
|
||||||
|
|
||||||
self.hass.states.set(
|
hass.states.async_set(
|
||||||
entity_ids[1], self.values[1], {ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT}
|
entity_ids[1], VALUES[1], {ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT}
|
||||||
)
|
)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test")
|
state = hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert STATE_UNKNOWN == state.state
|
assert STATE_UNKNOWN == state.state
|
||||||
assert state.attributes.get("unit_of_measurement") == "ERR"
|
assert state.attributes.get("unit_of_measurement") == "ERR"
|
||||||
|
|
||||||
self.hass.states.set(
|
hass.states.async_set(
|
||||||
entity_ids[2], self.values[2], {ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE}
|
entity_ids[2], VALUES[2], {ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE}
|
||||||
)
|
)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test")
|
state = hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert STATE_UNKNOWN == state.state
|
assert STATE_UNKNOWN == state.state
|
||||||
assert state.attributes.get("unit_of_measurement") == "ERR"
|
assert state.attributes.get("unit_of_measurement") == "ERR"
|
||||||
|
|
||||||
def test_last_sensor(self):
|
|
||||||
|
async def test_last_sensor(hass):
|
||||||
"""Test the last sensor."""
|
"""Test the last sensor."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -321,22 +325,22 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_ids = config["sensor"]["entity_ids"]
|
entity_ids = config["sensor"]["entity_ids"]
|
||||||
state = self.hass.states.get("sensor.test_last")
|
|
||||||
|
|
||||||
for entity_id, value in dict(zip(entity_ids, self.values)).items():
|
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
|
||||||
self.hass.states.set(entity_id, value)
|
hass.states.async_set(entity_id, value)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = self.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 self.min == state.attributes.get("min_value")
|
assert MIN_VALUE == state.attributes.get("min_value")
|
||||||
assert self.max == state.attributes.get("max_value")
|
assert MAX_VALUE == state.attributes.get("max_value")
|
||||||
assert self.mean == state.attributes.get("mean")
|
assert MEAN == state.attributes.get("mean")
|
||||||
assert self.median == state.attributes.get("median")
|
assert MEDIAN == state.attributes.get("median")
|
||||||
|
|
||||||
|
|
||||||
async def test_reload(hass):
|
async def test_reload(hass):
|
||||||
|
|
Loading…
Add table
Reference in a new issue