1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-17 15:44:52 +01:00

Remove stale devices at setup in Whisker (#165721)

This commit is contained in:
Nathan Spencer
2026-03-16 13:54:02 -06:00
committed by GitHub
parent e4345c72d9
commit 54745dc1f2
2 changed files with 22 additions and 0 deletions

View File

@@ -46,6 +46,16 @@ class LitterRobotDataUpdateCoordinator(DataUpdateCoordinator[None]):
self.account = Account(websession=async_get_clientsession(hass))
self.previous_members: set[str] = set()
# Initialize previous_members from the device registry so that
# stale devices can be detected on the first update after restart.
device_registry = dr.async_get(hass)
for device in dr.async_entries_for_config_entry(
device_registry, config_entry.entry_id
):
for domain, identifier in device.identifiers:
if domain == DOMAIN:
self.previous_members.add(identifier)
async def _async_update_data(self) -> None:
"""Update all device states from the Litter-Robot API."""
try:

View File

@@ -281,3 +281,15 @@ async def test_dynamic_devices(
# Third check -> removed 1 device
assert len(dr.async_entries_for_config_entry(device_registry, entry.entry_id)) == 1
mock_account.robots.pop(0)
with patch(
"homeassistant.components.litterrobot.coordinator.Account",
return_value=mock_account,
):
await hass.config_entries.async_reload(entry.entry_id)
await hass.async_block_till_done()
# Fourth check -> removed 1 device after reload
assert len(dr.async_entries_for_config_entry(device_registry, entry.entry_id)) == 0