Add include and exclude devices to device selector#165599
Add include and exclude devices to device selector#165599andrew-codechimp wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds optional include_devices / exclude_devices filtering support to the backend device selector, enabling callers (e.g., future “helper-style” flows) to constrain which device IDs are valid selections.
Changes:
- Extend
DeviceSelectorconfig schema/types to acceptinclude_devicesandexclude_devices. - Enforce include/exclude validation when a device selector value is submitted (single and multiple modes).
- Add unit tests covering include/exclude behavior for device selectors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
homeassistant/helpers/selector.py |
Adds include/exclude lists to device selector config and validates selections against them. |
tests/helpers/test_selector.py |
Adds test cases verifying include/exclude validation for single and multi device selection. |
|
I think this needs a more comprehensive PR description with example use cases and the motivation explained. This sentence doesn't explain it enough:
Potentially we'll need an architecture discussion. But please start with a more detailed explanation here. Thanks! |
|
Updated with a detailed use case, device selectors aren't used that frequently so use case refers to my custom component but hopefully gets the point across. |
|
Seems ok to me to proceed with this. I'm checking with the core team for a second opinion. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Would still like this to be merged. The failing test is not related to this change. |
Proposed change
Add optional include and exclude device id lists to the device selector.
The entity selector provides options to include or exclude existing entities, so that helpers/blueprints can reduce the list of displayed entities within the selector. The device selector does not provide this.
A use case, using the custom component Battery Notes as an example
Within Battery Notes you create a "helper" which adds additional entities to a device, it is not applicable to add a second set of entities to a device and will display an already added message. But with most users having a large number of devices, even using the existing filtering available, this is a large list to mentally navigate/track what has already been added, causing frustration with a select/submit/fail/try another approach.
The device selector does not have the ability to exclude devices, with this change the add note functionality within Battery Notes could obtain a list of existing device id's already added to Battery Notes and exclude these from the selector, making it easier for users to pick a device that they have not already added a battery note helper to.
The include filter is included for feature completeness to match the entity selector, I do not have a use case for this personally.
Type of change
Additional information
Checklist
ruff format 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.To help with the load of incoming pull requests: