fix a bug where the first start was changed to the start time when there was no previous history recorded before

This commit is contained in:
J. Nick Koston
2023-04-10 14:17:50 -10:00
parent 410f149ddf
commit 78387ef781
2 changed files with 10 additions and 4 deletions

View File

@@ -130,13 +130,16 @@ def test_get_significant_states_with_initial(hass_history) -> None:
""" """
hass = hass_history hass = hass_history
zero, four, states = record_states(hass) zero, four, states = record_states(hass)
one = zero + timedelta(seconds=1)
one_and_half = zero + timedelta(seconds=1.5) one_and_half = zero + timedelta(seconds=1.5)
for entity_id in states: for entity_id in states:
if entity_id == "media_player.test": if entity_id == "media_player.test":
states[entity_id] = states[entity_id][1:] states[entity_id] = states[entity_id][1:]
for state in states[entity_id]: 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 state.last_changed = one_and_half
hist = get_significant_states( hist = get_significant_states(

View File

@@ -548,13 +548,16 @@ def test_get_significant_states_with_initial(
hass = hass_recorder() hass = hass_recorder()
hass.config.set_time_zone(time_zone) hass.config.set_time_zone(time_zone)
zero, four, states = record_states(hass) zero, four, states = record_states(hass)
one = zero + timedelta(seconds=1)
one_and_half = zero + timedelta(seconds=1.5) one_and_half = zero + timedelta(seconds=1.5)
for entity_id in states: for entity_id in states:
if entity_id == "media_player.test": if entity_id == "media_player.test":
states[entity_id] = states[entity_id][1:] states[entity_id] = states[entity_id][1:]
for state in states[entity_id]: 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 state.last_changed = one_and_half
hist = history.get_significant_states( hist = history.get_significant_states(