diff --git a/homeassistant/components/recorder/models.py b/homeassistant/components/recorder/models.py index 6ed25e64eda..ef7181c9c03 100644 --- a/homeassistant/components/recorder/models.py +++ b/homeassistant/components/recorder/models.py @@ -207,11 +207,14 @@ class RecorderRuns(Base): # type: ignore def __repr__(self) -> str: """Return string representation of instance for debugging.""" + end = ( + f"'{self.end.isoformat(sep=' ', timespec='seconds')}'" if self.end else None + ) return ( f"" ) diff --git a/tests/components/recorder/test_purge.py b/tests/components/recorder/test_purge.py index db3906595db..e6bc3a99a97 100644 --- a/tests/components/recorder/test_purge.py +++ b/tests/components/recorder/test_purge.py @@ -105,6 +105,8 @@ async def test_purge_method( await _add_test_events(hass, instance) await _add_test_states(hass, instance) await _add_test_recorder_runs(hass, instance) + await hass.async_block_till_done() + await async_wait_recording_done(hass, instance) # make sure we start with 6 states with session_scope(hass=hass) as session: @@ -116,9 +118,7 @@ async def test_purge_method( recorder_runs = session.query(RecorderRuns) assert recorder_runs.count() == 7 - - await hass.async_block_till_done() - await async_wait_recording_done(hass, instance) + runs_before_purge = recorder_runs.all() # run purge method - no service data, use defaults await hass.services.async_call("recorder", "purge") @@ -145,7 +145,10 @@ async def test_purge_method( assert events.count() == 2 # now we should only have 3 recorder runs left - assert recorder_runs.count() == 3 + runs = recorder_runs.all() + assert runs[0] == runs_before_purge[0] + assert runs[1] == runs_before_purge[5] + assert runs[2] == runs_before_purge[6] assert not ("EVENT_TEST_PURGE" in (event.event_type for event in events.all()))