Fix fetching history include_start_time_state when timezone is not UTC (#85983)

This commit is contained in:
J. Nick Koston 2023-01-15 22:01:32 -10:00 committed by GitHub
parent 9709391b52
commit 233332c3a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -586,7 +586,7 @@ def _get_states_for_entites_stmt(
# We got an include-list of entities, accelerate the query by filtering already # We got an include-list of entities, accelerate the query by filtering already
# in the inner query. # in the inner query.
if schema_version >= 31: if schema_version >= 31:
run_start_ts = run_start.timestamp() run_start_ts = process_timestamp(run_start).timestamp()
utc_point_in_time_ts = dt_util.utc_to_timestamp(utc_point_in_time) utc_point_in_time_ts = dt_util.utc_to_timestamp(utc_point_in_time)
stmt += lambda q: q.where( stmt += lambda q: q.where(
States.state_id States.state_id
@ -629,7 +629,7 @@ def _generate_most_recent_states_by_date(
) -> Subquery: ) -> Subquery:
"""Generate the sub query for the most recent states by data.""" """Generate the sub query for the most recent states by data."""
if schema_version >= 31: if schema_version >= 31:
run_start_ts = run_start.timestamp() run_start_ts = process_timestamp(run_start).timestamp()
utc_point_in_time_ts = dt_util.utc_to_timestamp(utc_point_in_time) utc_point_in_time_ts = dt_util.utc_to_timestamp(utc_point_in_time)
return ( return (
select( select(

View File

@ -434,7 +434,8 @@ def test_get_significant_states_minimal_response(hass_recorder):
assert states == hist assert states == hist
def test_get_significant_states_with_initial(hass_recorder): @pytest.mark.parametrize("time_zone", ["Europe/Berlin", "US/Hawaii", "UTC"])
def test_get_significant_states_with_initial(time_zone, hass_recorder):
"""Test that only significant states are returned. """Test that only significant states are returned.
We should get back every thermostat change that We should get back every thermostat change that
@ -442,6 +443,7 @@ def test_get_significant_states_with_initial(hass_recorder):
media player (attribute changes are not significant and not returned). media player (attribute changes are not significant and not returned).
""" """
hass = hass_recorder() hass = hass_recorder()
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 = zero + timedelta(seconds=1)
one_and_half = zero + timedelta(seconds=1.5) one_and_half = zero + timedelta(seconds=1.5)