From 0a2a166860fcc7e7fd5c693155ccc2af50ab11aa Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 4 Jun 2022 09:47:30 -1000 Subject: [PATCH] Fix history stats not comparing all times in UTC (#73040) --- homeassistant/components/history_stats/data.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/history_stats/data.py b/homeassistant/components/history_stats/data.py index 5466498fc32..3b17c715c97 100644 --- a/homeassistant/components/history_stats/data.py +++ b/homeassistant/components/history_stats/data.py @@ -67,9 +67,10 @@ class HistoryStats: current_period_end_timestamp = floored_timestamp(current_period_end) previous_period_start_timestamp = floored_timestamp(previous_period_start) previous_period_end_timestamp = floored_timestamp(previous_period_end) - now_timestamp = floored_timestamp(datetime.datetime.now()) + utc_now = dt_util.utcnow() + now_timestamp = floored_timestamp(utc_now) - if now_timestamp < current_period_start_timestamp: + if current_period_start > utc_now: # History cannot tell the future self._history_current_period = [] self._previous_run_before_start = True