Fix HomeKit select accessories not marking the active option as on - #175603
Conversation
The state comparison in SelectSwitch.async_update_state ran the current state through cleanup_name_for_homekit() before comparing it against the raw option strings used as keys. Any option containing a character the cleanup translates (e.g. underscores) could therefore never match, so its outlet never showed as on. The cleanup is meant for display names only; a select state is by contract exactly one of its raw options. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Hey there @bdraco, 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 fixes a display-only bug in the HomeKit Bridge SelectSwitch accessory (which renders select/input_select entities as a power strip of outlets). async_update_state compared the entity's state after passing it through cleanup_name_for_homekit() against self.select_chars keys that are the raw option strings. Any option containing a character the cleanup translates (e.g. underscores), or longer than MAX_NAME_LENGTH, could never match, so its outlet never showed as on; colliding options could also light the wrong outlet. The fix removes the cleanup from the comparison so raw is compared against raw, which is correct since a select's state is by contract exactly one of its options. Name cleanup remains for the display-only CHAR_NAME/CHAR_CONFIGURED_NAME.
Changes:
- In
async_update_state, compare the rawnew_state.stateagainst the raw option keys instead of the cleaned-up name. - Add a parametrized test (
input_select/select) covering options altered by name cleanup, including a post-cleanup collision, and assertingCHAR_NAME/CHAR_CONFIGURED_NAMEcleanup is preserved and the HomeKit→HA setter still works.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| homeassistant/components/homekit/type_switches.py | Compares raw state against raw option keys in async_update_state, fixing outlets never lighting for cleaned/colliding options. |
| tests/components/homekit/test_type_switches.py | Adds a parametrized regression test for options needing name cleanup, verifying state sync, display-name cleanup, and setter behavior. |
PR Review — Fix HomeKit select accessories not marking the active option as onCorrect, minimal bugfix with strong regression coverage. Merge-ready. What's solid:
Checklist
Automated review by Kōan (Claude) |
|
Thanks @mattias-arrelid |
Breaking change
Proposed change
SelectSwitch.async_update_stateran the current state throughcleanup_name_for_homekit()before comparing it against the raw option strings that keyself.select_chars. Any option containing a character the cleanup translates (underscore being the common case, but also characters mapped to-and options longer thanMAX_NAME_LENGTH) could therefore never match, so its outlet never showed as on in the Home app — and when two options collide after cleanup (e.g.always_onandalways on), the wrong outlet lit up. Control in the HomeKit→HA direction was unaffected, since the setter closes over the raw option.The fix compares raw against raw: a select's state is by contract exactly one of its options, so the cleanup has no business in the comparison. Name cleanup is display-only and is kept for
CHAR_NAME/CHAR_CONFIGURED_NAME, which the new test also asserts.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: