mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Ensure the purge entities service cleans up the states_meta table (#109344)
This commit is contained in:
parent
2788576dc9
commit
67e6febde4
@ -794,4 +794,6 @@ def purge_entity_data(
|
|||||||
_LOGGER.debug("Purging entity data hasn't fully completed yet")
|
_LOGGER.debug("Purging entity data hasn't fully completed yet")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
_purge_old_entity_ids(instance, session)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -1424,6 +1424,18 @@ async def test_purge_entities(
|
|||||||
)
|
)
|
||||||
assert states_sensor_kept.count() == 10
|
assert states_sensor_kept.count() == 10
|
||||||
|
|
||||||
|
# sensor.keep should remain in the StatesMeta table
|
||||||
|
states_meta_remain = session.query(StatesMeta).filter(
|
||||||
|
StatesMeta.entity_id == "sensor.keep"
|
||||||
|
)
|
||||||
|
assert states_meta_remain.count() == 1
|
||||||
|
|
||||||
|
# sensor.purge_entity should be removed from the StatesMeta table
|
||||||
|
states_meta_remain = session.query(StatesMeta).filter(
|
||||||
|
StatesMeta.entity_id == "sensor.purge_entity"
|
||||||
|
)
|
||||||
|
assert states_meta_remain.count() == 0
|
||||||
|
|
||||||
_add_purge_records(hass)
|
_add_purge_records(hass)
|
||||||
|
|
||||||
# Confirm calling service without arguments matches all records (default filter behavior)
|
# Confirm calling service without arguments matches all records (default filter behavior)
|
||||||
@ -1437,6 +1449,10 @@ async def test_purge_entities(
|
|||||||
states = session.query(States)
|
states = session.query(States)
|
||||||
assert states.count() == 0
|
assert states.count() == 0
|
||||||
|
|
||||||
|
# The states_meta table should be empty
|
||||||
|
states_meta_remain = session.query(StatesMeta)
|
||||||
|
assert states_meta_remain.count() == 0
|
||||||
|
|
||||||
|
|
||||||
async def _add_test_states(hass: HomeAssistant, wait_recording_done: bool = True):
|
async def _add_test_states(hass: HomeAssistant, wait_recording_done: bool = True):
|
||||||
"""Add multiple states to the db for testing."""
|
"""Add multiple states to the db for testing."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user