From 78387ef7810890ad2745f4920892b037e43e1cc6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 10 Apr 2023 14:17:50 -1000 Subject: [PATCH] fix a bug where the first start was changed to the start time when there was no previous history recorded before --- tests/components/history/test_init.py | 7 +++++-- tests/components/recorder/test_history.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index a499c5bb0be..fa2332e71d7 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -130,13 +130,16 @@ def test_get_significant_states_with_initial(hass_history) -> None: """ hass = hass_history zero, four, states = record_states(hass) - one = zero + timedelta(seconds=1) one_and_half = zero + timedelta(seconds=1.5) for entity_id in states: if entity_id == "media_player.test": states[entity_id] = states[entity_id][1:] for state in states[entity_id]: - if state.last_changed == one: + # If the state is recorded before the start time + # start it will have its last_updated and last_changed + # set to the start time. + if state.last_updated < one_and_half: + state.last_updated = one_and_half state.last_changed = one_and_half hist = get_significant_states( diff --git a/tests/components/recorder/test_history.py b/tests/components/recorder/test_history.py index b59d82c2598..5cd77447f1c 100644 --- a/tests/components/recorder/test_history.py +++ b/tests/components/recorder/test_history.py @@ -548,13 +548,16 @@ def test_get_significant_states_with_initial( hass = hass_recorder() hass.config.set_time_zone(time_zone) zero, four, states = record_states(hass) - one = zero + timedelta(seconds=1) one_and_half = zero + timedelta(seconds=1.5) for entity_id in states: if entity_id == "media_player.test": states[entity_id] = states[entity_id][1:] for state in states[entity_id]: - if state.last_changed == one: + # If the state is recorded before the start time + # start it will have its last_updated and last_changed + # set to the start time. + if state.last_updated < one_and_half: + state.last_updated = one_and_half state.last_changed = one_and_half hist = history.get_significant_states(