mirror of
https://github.com/home-assistant/core.git
synced 2025-08-14 18:11:41 +02:00
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:
@@ -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(
|
||||||
|
@@ -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(
|
||||||
|
Reference in New Issue
Block a user