mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
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
@ -175,7 +175,7 @@ class StatisticsSensor(SensorEntity):
|
||||
|
||||
def _add_state_to_queue(self, new_state):
|
||||
"""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
|
||||
|
||||
try:
|
||||
|
@ -135,6 +135,13 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
new_state = self.hass.states.get("sensor.test")
|
||||
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):
|
||||
"""Test rotation."""
|
||||
assert setup_component(
|
||||
|
Loading…
x
Reference in New Issue
Block a user