Add a dynamic sensitivity slider for Matter sensors#167710
Conversation
|
Hey there @home-assistant/matter, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR replaces the previous vendor-specific sensitivity level select entities with a dynamic, generic number entity (slider) that works with any device having the BooleanStateConfiguration cluster with the SensitivityLevel feature. The new implementation converts device sensitivity levels (0-indexed) to user-friendly values (1-indexed) and supports an arbitrary number of sensitivity levels rather than being limited to 3.
Changes:
- Removed vendor-specific (Aqara and Heiman) select entity discovery schemas for sensitivity levels from
select.py - Added a generic number entity discovery schema in
number.pythat works with any device having BooleanStateConfiguration cluster with SensitivityLevel feature - Updated tests to validate the new number entity behavior and removed obsolete select entity tests
- User experience shifts from dropdown select ("10 mm", "20 mm", "30 mm") to a slider with numeric values (1, 2, 3)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| homeassistant/components/matter/select.py | Removed 3 vendor-specific select discovery schemas for Aqara contact sensor (P2), Aqara motion sensor (P2), and Heiman motion sensor |
| homeassistant/components/matter/number.py | Added 1 generic number discovery schema supporting any device with BooleanStateConfiguration cluster and SensitivityLevel feature |
| tests/components/matter/test_select.py | Removed test for Aqara door/window P2 select entity |
| tests/components/matter/test_number.py | Added test for the new generic sensitivity level number entity |
| tests/components/matter/snapshots/test_select.ambr | Removed snapshots for old select entities |
| tests/components/matter/snapshots/test_number.ambr | Added snapshots for new number entities on affected devices |
|
Shouldn't we first announce the withdrawal and then, in a second step, eliminate the old entities? |
Thanks for the comments. If we use both filters and the new generic slider, will there be unexpected behavior? |
| ), | ||
| MatterDiscoverySchema( | ||
| platform=Platform.SELECT, | ||
| entity_description=MatterSelectEntityDescription( |
There was a problem hiding this comment.
Yeah, let's deprecate the old select entities first by making them disabled by default.
If you add entity_registry_enabled_default=False to the MatterSelectEntityDescription, the old entities are disabled for newly paired devices, but still enabled on existing devices, since they might be used in automations there.
It should not cause any weird behavior. Both entities should update at the same time (if enabled). Though you need to add allow_multi=True to the number entity, so it doesn't "reserve" the CurrentSensitivityLevel attribute for itself, causing the old SELECT entities to not be discovered.
(I think due to how discovery works (first going through NUMBER, then SELECT schemas), it's enough to only add allow_multi=True to the number schemas, but let's also add it to the SELECT schemas as well to be a bit more consistent, and not depend on how the discovery order works.)
There was a problem hiding this comment.
Hi,
Thanks for the help!
The test won't pass with the entity_registry_enabled_default=False added, even the device aqara_door_window_p2 works in real life with this PR. Should I touch the test_select as well?
There was a problem hiding this comment.
It looks like you got everything figured out now, with tests passing.
It's fine to add entity_registry_enabled_by_default to the test_select test, so the old entities are enabled by default for that test.
| name="Sensitivity", | ||
| entity_category=EntityCategory.CONFIG, | ||
| translation_key="sensitivity_level", |
There was a problem hiding this comment.
We'll also need to add a translation for the sensitivity_level key to the number section of Matter strings here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/matter/strings.json
The existing translation is just for the SELECT platform, so it won't be used by this new NUMBER entity.
If that's done, we can also drop the name here:
| name="Sensitivity", | |
| entity_category=EntityCategory.CONFIG, | |
| translation_key="sensitivity_level", | |
| entity_category=EntityCategory.CONFIG, | |
| translation_key="sensitivity_level", |
(Do note you may need to run python3 -m script.translations develop locally after adding a new string to strings.json, before it's used by HA.)
You'll also need to regenerate test snapshots after having added the sensitivity_level to strings.json (`pytest tests/components/matter --snapshot-update).
There was a problem hiding this comment.
Hi, thanks for the suggested edits. I have made extra commits based on your suggestions.
|
Everything is looking good already. One more small thing: (If you need help with that, I can also help with that. It should be pretty similar to existing tests in |
Co-authored-by: TheJulianJES <TheJulianJES@users.noreply.github.com>
Co-authored-by: TheJulianJES <TheJulianJES@users.noreply.github.com>
|
Should we update the description to "Manufacturer-specific sensitivity select entities have been deprecated and will be removed in the future."? Otherwise users may thing they are gone already. |
Hi thanks for the inputs. I have added a line for clarification. |
I've added it to the "Breaking change" section too. |
Breaking change
Manufacturer-specific sensitivity select entities have been deprecated and will be removed in the future. A new number entity is added to all supporting Matter devices. This affects the following devices:
Proposed change
The PR deprecates previous PID/VID filtered select config entities for sensitivity levels to better support more sensors with more than 3 sensitivity levels, like the newly released Aqara P100 multi-propose sensor that has 10 sensitivity levels. Old select entities are disabled by default.
Screenshot showing the newly added entity (do note that the old select entity is now available again as well, though disabled by default):
Changes
Add new discovery entry in
number.pyand remove filters for the Matter sensors mentioned above. To align with Aqara app and other real life using experience. The added slider would start from1instead of0defined in Matter spec.Here's a comparison between HA and the Aqara app:
Manufacturer-specific sensitivity select entities have been deprecated and will be removed in six months.
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: