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:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user