-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Add opt-in device auto cleanup to config entries #66209 8000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Config entries can now call entry.async_enable_device_auto_cleanup() This call controls how the system considers a device orphaned when considering to cleanup devices. Orphened devices are defined by not have any entities referenced and no config entries with auto cleanup disabled (default).
Related PR: #66188 |
Testing
Restarted, all the devices with no entities on august and unifi protect that have been hanging for years are gone 👍 |
In this case, shouldn't August and Unifi have cleaned up the devices when they removed the entities? Any device without config entries should be automatically removed. I commented something similar at #66188 (comment)
The challenge we have for things like Sonos, Wemo and Cast is that they don't know if a device is temporarily disconnected or gone. It might just be in a closet waiting to control the Christmas tree in December. |
August doesn't know if the unavailable lock is coming back or not, Unifi Protect doesn't know if the camera is temporary or permanently offline either. The entities are being deleted in the UI after the camera/lock was replaced but the device entry was left orphaned but since it still pointed to the config entry that set it up, it was not removed. |
I guess its pretty much the same case as Sonos, Wemo and Cast |
Ah yes, in that case it's all the same. What do you think of the idea of a user removing a config entry from a device if all it's entities are restored? That way a user can clean it up without an integration having to flag it. |
@balloob I think that would be great. It seems to be what everyone has been asking for and couldn't understand why it was being rejected. However, it must also cover the case where the user has first deleted all the restored entities so none are left. (BTW, adding a core flag like this PR does is much preferable to implementing the cleanup in each integration but if the flag is opt-in it will still take a long time before all integrations are updated. And someone will keep missing the flag in new integrations.) |
Devices can have things that are not entities tied to them, e.g. device triggers, tags, etc. |
That makes it a bit more complex since we can't really tell if a device is in use or not. For lutron caseta we register the pico remotes as devices but they have no linked entities. As I replace remotes I end up with extra devices lying around. Thinking about the removal implementation, I'd check if there had been a call to In this case maybe we could only remove devices for everything that wasn't freshened with |
We should be able to keep track of which config entries have touched the device recently here AKA fresh state I'm not sure this is race safe though as we would have to only do it for LOADED config entries but the device may be created later since we set LOADED before all platforms have finished loading : https://github.com/home-assistant/core/blob/dev/homeassistant/config_entries.py#L408 |
We might be able to add some type of done callback to async_setup_platforms to run a cleanup once it’s done if they flip it on |
|
Let's close this since we have |
Proposed change
Config entries can now call entry.async_enable_device_auto_cleanup()
This call controls how the system considers a device orphaned
when considering to cleanup devices.
Orphaned devices are defined by not have any entities
referenced and no config entries with auto cleanup
disabled (default).
Implements
https://community.home-assistant.io/t/delete-individual-device-and-entity-from-integration/157428
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: