mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
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
|
# History cannot tell the future
|
||||||
self._history_current_period = []
|
self._history_current_period = []
|
||||||
self._previous_run_before_start = True
|
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:
|
# We avoid querying the database if the below did NOT happen:
|
||||||
#
|
#
|
||||||
@ -82,7 +83,7 @@ class HistoryStats:
|
|||||||
# - The period shrank in size
|
# - The period shrank in size
|
||||||
# - The previous period ended before now
|
# - The previous period ended before now
|
||||||
#
|
#
|
||||||
elif (
|
if (
|
||||||
not self._previous_run_before_start
|
not self._previous_run_before_start
|
||||||
and current_period_start_timestamp == previous_period_start_timestamp
|
and current_period_start_timestamp == previous_period_start_timestamp
|
||||||
and (
|
and (
|
||||||
@ -117,10 +118,6 @@ class HistoryStats:
|
|||||||
)
|
)
|
||||||
self._previous_run_before_start = False
|
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(
|
hours_matched, match_count = self._async_compute_hours_and_changes(
|
||||||
now_timestamp,
|
now_timestamp,
|
||||||
current_period_start_timestamp,
|
current_period_start_timestamp,
|
||||||
|
@ -357,7 +357,7 @@ async def test_measure_multiple(hass, recorder_mock):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("sensor.sensor1").state == "0.5"
|
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.sensor3").state == "2"
|
||||||
assert hass.states.get("sensor.sensor4").state == "50.0"
|
assert hass.states.get("sensor.sensor4").state == "50.0"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user