Fix get_significant_states_with_session query looking at legacy columns (#89558)
This commit is contained in:
parent
8bd43760b6
commit
16b420d660
2 changed files with 26 additions and 3 deletions
|
@ -282,9 +282,11 @@ def _significant_states_stmt(
|
||||||
(States.last_changed_ts == States.last_updated_ts)
|
(States.last_changed_ts == States.last_updated_ts)
|
||||||
| States.last_changed_ts.is_(None)
|
| States.last_changed_ts.is_(None)
|
||||||
)
|
)
|
||||||
stmt += lambda q: q.filter(
|
else:
|
||||||
(States.last_changed == States.last_updated) | States.last_changed.is_(None)
|
stmt += lambda q: q.filter(
|
||||||
)
|
(States.last_changed == States.last_updated)
|
||||||
|
| States.last_changed.is_(None)
|
||||||
|
)
|
||||||
elif significant_changes_only:
|
elif significant_changes_only:
|
||||||
if schema_version >= 31:
|
if schema_version >= 31:
|
||||||
stmt += lambda q: q.filter(
|
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(
|
@pytest.mark.parametrize(
|
||||||
("attributes", "no_attributes", "limit"),
|
("attributes", "no_attributes", "limit"),
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue