mirror of https://github.com/home-assistant/core
Only present history_stats state as unknown if the time is in the future (#72880)
This commit is contained in:
parent
1c38c20cac
commit
d3b1896a06
|
@ -73,7 +73,8 @@ class HistoryStats:
|
|||
# History cannot tell the future
|
||||
self._history_current_period = []
|
||||
self._previous_run_before_start = True
|
||||
|
||||
self._state = HistoryStatsState(None, None, self._period)
|
||||
return self._state
|
||||
#
|
||||
# We avoid querying the database if the below did NOT happen:
|
||||
#
|
||||
|
@ -82,7 +83,7 @@ class HistoryStats:
|
|||
# - The period shrank in size
|
||||
# - The previous period ended before now
|
||||
#
|
||||
elif (
|
||||
if (
|
||||
not self._previous_run_before_start
|
||||
and current_period_start_timestamp == previous_period_start_timestamp
|
||||
and (
|
||||
|
@ -117,10 +118,6 @@ class HistoryStats:
|
|||
)
|
||||
self._previous_run_before_start = False
|
||||
|
||||
if not self._history_current_period:
|
||||
self._state = HistoryStatsState(None, None, self._period)
|
||||
return self._state
|
||||
|
||||
hours_matched, match_count = self._async_compute_hours_and_changes(
|
||||
now_timestamp,
|
||||
current_period_start_timestamp,
|
||||
|
|
|
@ -357,7 +357,7 @@ async def test_measure_multiple(hass, recorder_mock):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("sensor.sensor1").state == "0.5"
|
||||
assert hass.states.get("sensor.sensor2").state == STATE_UNKNOWN
|
||||
assert hass.states.get("sensor.sensor2").state == "0.0"
|
||||
assert hass.states.get("sensor.sensor3").state == "2"
|
||||
assert hass.states.get("sensor.sensor4").state == "50.0"
|
||||
|
||||
|
|
Loading…
Reference in New Issue