Fix get_significant_states_with_session query looking at legacy columns (#89558)
parent
8bd43760b6
commit
16b420d660
|
@ -282,9 +282,11 @@ def _significant_states_stmt(
|
|||
(States.last_changed_ts == States.last_updated_ts)
|
||||
| States.last_changed_ts.is_(None)
|
||||
)
|
||||
stmt += lambda q: q.filter(
|
||||
(States.last_changed == States.last_updated) | States.last_changed.is_(None)
|
||||
)
|
||||
else:
|
||||
stmt += lambda q: q.filter(
|
||||
(States.last_changed == States.last_updated)
|
||||
| States.last_changed.is_(None)
|
||||
)
|
||||
elif significant_changes_only:
|
||||
if schema_version >= 31:
|
||||
stmt += lambda q: q.filter(
|
||||
|
|
|
@ -209,6 +209,27 @@ def test_significant_states_with_session_entity_minimal_response_no_matches(
|
|||
)
|
||||
|
||||
|
||||
def test_significant_states_with_session_single_entity(
|
||||
hass_recorder: Callable[..., HomeAssistant],
|
||||
) -> None:
|
||||
"""Test get_significant_states_with_session with a single entity."""
|
||||
hass = hass_recorder()
|
||||
hass.states.set("demo.id", "any", {"attr": True})
|
||||
hass.states.set("demo.id", "any2", {"attr": True})
|
||||
wait_recording_done(hass)
|
||||
now = dt_util.utcnow()
|
||||
with session_scope(hass=hass) as session:
|
||||
states = history.get_significant_states_with_session(
|
||||
hass,
|
||||
session,
|
||||
now - timedelta(days=1),
|
||||
now,
|
||||
entity_ids=["demo.id"],
|
||||
minimal_response=False,
|
||||
)
|
||||
assert len(states["demo.id"]) == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("attributes", "no_attributes", "limit"),
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue