feat(matter-switch): add generic ModeSelect (0x0050) cluster support
Hi!
This is going to be my first contribution here so any feedback is welcome and will be reflected upon.
I wanted to expose my central thermostat mode select from Home Assistant via Matter Hub bridge but found out there was no way of interacting with it and ended up forking and implementing it myself.
This PR implements embedded cluster definitions and dynamic profile assignment (mode-only & switch-binary-mode) for Matter devices utilizing the ModeSelect (0x0050) cluster.
Why the dynamic profile assignement - well, adding mode select capability to optional_component_capabilities did not result in mode dropdown being actually shown in app and for a start I thought I should not bloat this PR with many profile combinations for now.
Type of Change
- [ ] WWST Certification Request
- If this is your first time contributing code:
- [x] I have reviewed the README.md file
- [x] I have reviewed the CODE_OF_CONDUCT.md file
- [x] I have signed the CLA
- [ ] I plan on entering a WWST Certification Request or have entered a request through the WWST Certification console at developer.smartthings.com
- If this is your first time contributing code:
- [ ] Bug fix
- [x] New feature
- [ ] Refactor
Checklist
- [x] I have performed a self-review of my code
- [x] I have commented my code in hard-to-understand areas
- [x] I have verified my changes by testing with a device or have communicated a plan for testing
- [x] I am adding new behavior, such as adding a sub-driver, and have added and run new unit tests to cover the new behavior
Description of Change
This PR introduces support for endpoints utilizing the Matter ModeSelect (0x0050) cluster within the generic matter-switch driver. It provides a mode-only profile for endpoints that strictly use ModeSelect, and a switch-binary-mode profile for endpoints that combine an OnOff switch with ModeSelect.
Key Changes:
- Added missing
ModeSelectcluster definitions toembedded_clusters(SupportedModes,CurrentMode,ChangeToMode). - Implemented capability and attribute handlers to translate
mode.supportedArgumentsinto theSupportedModesstring-array, andsetModestring commands into Matter integer indexes. - Modified
match_profileto automatically upgrade toswitch-binary-mode.yml(if an OnOff cluster is present) ormode-only.yml(if it strictly uses the ModeSelect cluster). Other generic profiles are gracefully appended viaoptional_component_capabilities. - Utilizes
fields.luato safely persist the string-to-integer mode mapping locally.
Summary of Completed Tests
- Unit Tests: Added
test_matter_mode_select.luato validateSupportedModescaching, component-to-endpoint routing, andsetModecapability translations. - Physical Device Testing: End-to-end testing deployed on a physical Hub v3 with a Bridged Matter device utilizing exclusively the
ModeSelectcluster. Verified thatinfoChangedsuccessfully swaps the profile,SupportedModesdynamically populates the SmartThings app dropdown UI, andsetModeinvokes the correct endpoint successfully.