fix: skip cached state override when plug/humidifier ignore command#503
Draft
bluetoothbot wants to merge 2 commits into
Draft
fix: skip cached state override when plug/humidifier ignore command#503bluetoothbot wants to merge 2 commits into
bluetoothbot wants to merge 2 commits into
Conversation
Extends the bot fix from sblibs#502 to SwitchbotPlugMini and SwitchbotHumidifier: both `turn_on`/`turn_off` (and humidifier's `set_level`) ran `_override_state` unconditionally, even when `_check_command_result` returned False. A rejected/garbled command response would still flip the cached state, making HA report a state the device never reached. Gate `_override_state` and `_fire_callbacks` on the result, matching the original intent of the existing `_check_command_result` calls. Tests added: tests/test_plug.py (4 cases), tests/test_humidifier.py (6 cases) covering accepted/rejected paths for turn_on, turn_off, and set_level. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Gate
_override_stateon the result of_check_command_resultinSwitchbotPlugMini.turn_on/turn_offandSwitchbotHumidifier._async_set_state/_set_level. Same shape as #502 (bot), extended to the other two device classes where the existing_check_command_resultcall was discarded.Why
Audit follow-up to #502 (which fixed the bot half of #213). The same anti-pattern lives in
plug.pyandhumidifier.py:If the device returns anything other than the expected ACK byte,
retisFalsebut the cached state still gets flipped, so the library lies about state to its caller. The bot version was observed in the wild (#213); the plug/humidifier versions are the same code shape and the existing_check_command_resultcalls show the original author already intended to validate — the gate was simply missing.How
Two-line gate in each method, matching #502:
Behaviour for the accepted path is unchanged.
Testing
tests/test_plug.py(4 tests): accepted/rejected × turn_on/turn_off.tests/test_humidifier.py(6 tests): accepted/rejected × turn_on/turn_off/set_level. Neither device had a test module before.1223 passed.🤖 Generated with Claude Code
Quality Report
Changes: 4 files changed, 201 insertions(+), 8 deletions(-)
Code scan: clean
Tests: passed (1223 passed)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline