Fix statistics startup error for None value states (#59199)
* Catch statistics startup error for None value states, fix #49254 * Add test for statistics None handling * Update tests/components/statistics/test_sensor.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * Switch test case logic to remove sensor last Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
20b93132dd
commit
2924f4605b
2 changed files with 8 additions and 1 deletions
|
@ -175,7 +175,7 @@ class StatisticsSensor(SensorEntity):
|
||||||
|
|
||||||
def _add_state_to_queue(self, new_state):
|
def _add_state_to_queue(self, new_state):
|
||||||
"""Add the state to the queue."""
|
"""Add the state to the queue."""
|
||||||
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE, None):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -135,6 +135,13 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||||
new_state = self.hass.states.get("sensor.test")
|
new_state = self.hass.states.get("sensor.test")
|
||||||
assert state == new_state
|
assert state == new_state
|
||||||
|
|
||||||
|
# Source sensor is removed, unit and state should not change
|
||||||
|
# This is equal to a None value being published
|
||||||
|
self.hass.states.remove("sensor.test_monitored")
|
||||||
|
self.hass.block_till_done()
|
||||||
|
new_state = self.hass.states.get("sensor.test")
|
||||||
|
assert state == new_state
|
||||||
|
|
||||||
def test_sampling_size(self):
|
def test_sampling_size(self):
|
||||||
"""Test rotation."""
|
"""Test rotation."""
|
||||||
assert setup_component(
|
assert setup_component(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue