mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Statistics sensors repect given name (#26119)
This commit is contained in:
parent
f9e518d868
commit
12f964ca57
@ -82,10 +82,7 @@ class StatisticsSensor(Entity):
|
|||||||
"""Initialize the Statistics sensor."""
|
"""Initialize the Statistics sensor."""
|
||||||
self._entity_id = entity_id
|
self._entity_id = entity_id
|
||||||
self.is_binary = self._entity_id.split(".")[0] == "binary_sensor"
|
self.is_binary = self._entity_id.split(".")[0] == "binary_sensor"
|
||||||
if not self.is_binary:
|
self._name = name
|
||||||
self._name = "{} {}".format(name, ATTR_MEAN)
|
|
||||||
else:
|
|
||||||
self._name = "{} {}".format(name, ATTR_COUNT)
|
|
||||||
self._sampling_size = sampling_size
|
self._sampling_size = sampling_size
|
||||||
self._max_age = max_age
|
self._max_age = max_age
|
||||||
self._precision = precision
|
self._precision = precision
|
||||||
|
@ -60,7 +60,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||||||
self.hass.states.set("binary_sensor.test_monitored", value)
|
self.hass.states.set("binary_sensor.test_monitored", value)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_count")
|
state = self.hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert str(len(values)) == state.state
|
assert str(len(values)) == state.state
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = self.hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert str(self.mean) == state.state
|
assert str(self.mean) == state.state
|
||||||
assert self.min == state.attributes.get("min_value")
|
assert self.min == state.attributes.get("min_value")
|
||||||
@ -126,7 +126,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = self.hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert 3.8 == state.attributes.get("min_value")
|
assert 3.8 == state.attributes.get("min_value")
|
||||||
assert 14 == state.attributes.get("max_value")
|
assert 14 == state.attributes.get("max_value")
|
||||||
@ -155,7 +155,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = self.hass.states.get("sensor.test")
|
||||||
|
|
||||||
# require only one data point
|
# require only one data point
|
||||||
assert self.values[-1] == state.attributes.get("min_value")
|
assert self.values[-1] == state.attributes.get("min_value")
|
||||||
@ -206,7 +206,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||||||
# insert the next value one minute later
|
# insert the next value one minute later
|
||||||
mock_data["return_time"] += timedelta(minutes=1)
|
mock_data["return_time"] += timedelta(minutes=1)
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = self.hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert 6 == state.attributes.get("min_value")
|
assert 6 == state.attributes.get("min_value")
|
||||||
assert 14 == state.attributes.get("max_value")
|
assert 14 == state.attributes.get("max_value")
|
||||||
@ -248,7 +248,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||||||
# insert the next value one minute later
|
# insert the next value one minute later
|
||||||
mock_data["return_time"] += timedelta(minutes=1)
|
mock_data["return_time"] += timedelta(minutes=1)
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = self.hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert datetime(
|
assert datetime(
|
||||||
2017, 8, 2, 12, 23, 42, tzinfo=dt_util.UTC
|
2017, 8, 2, 12, 23, 42, tzinfo=dt_util.UTC
|
||||||
@ -290,7 +290,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
# check if the result is as in test_sensor_source()
|
# check if the result is as in test_sensor_source()
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = self.hass.states.get("sensor.test")
|
||||||
assert str(self.mean) == state.state
|
assert str(self.mean) == state.state
|
||||||
|
|
||||||
@pytest.mark.skip("Flaky in CI")
|
@pytest.mark.skip("Flaky in CI")
|
||||||
@ -355,7 +355,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
# check if the result is as in test_sensor_source()
|
# check if the result is as in test_sensor_source()
|
||||||
state = self.hass.states.get("sensor.test_mean")
|
state = self.hass.states.get("sensor.test")
|
||||||
|
|
||||||
assert expected_min_age == state.attributes.get("min_age")
|
assert expected_min_age == state.attributes.get("min_age")
|
||||||
# The max_age timestamp should be 1 hour before what we have right
|
# The max_age timestamp should be 1 hour before what we have right
|
||||||
|
Loading…
x
Reference in New Issue
Block a user