Replace flag based cleanup in bluetooth_device_connect with per branch cleanup#1764
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1764 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 26
Lines 4183 4175 -8
=========================================
- Hits 4183 4175 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@esphbot review |
There was a problem hiding this comment.
Pull request overview
Refactors APIClient.bluetooth_device_connect cleanup logic to be handled explicitly within each exception branch, removing the prior flag-based bookkeeping and simplifying the finally block, in line with the cleanup contract pinned by the existing tests.
Changes:
- Removes
connect_ok/timeout_expired/unhandled_exceptionflags and associatedfinally-block conditionals. - Moves
unsub()and_bluetooth_disconnect_no_wait()cleanup into the relevantexceptbranches (timeout/cancel/base-exception). - Reduces
finallyto always cancel the timeout handle.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
LGTM. Walked the truth table for all four outcomes and the new per-branch cleanup is behaviour-equivalent to the old flag-based version:
Two small side effects of the refactor, both wins:
|
PR Review — Replace flag based cleanup in bluetooth_device_connect with per branch cleanupBehaviour-preserving refactor. Walked the truth table for the four reachable states (success, TimeoutError, CancelledError, BaseException) and the new per-branch cleanup matches the old flag-based cleanup exactly. Two minor observations, neither blocking: (1) Checklist
SummaryBehaviour-preserving refactor. Walked the truth table for the four reachable states (success, TimeoutError, CancelledError, BaseException) and the new per-branch cleanup matches the old flag-based cleanup exactly. Two minor observations, neither blocking: (1) Automated review by Kōane3d87b3 |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR refactors ChangesBluetooth Connection Cleanup Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What does this implement/fix?
Replaces the flag based cleanup in
bluetooth_device_connectwith explicit per branch cleanup; eachexcepthandler now releases its own resources, thefinallyclause is reduced totimeout_handle.cancel(), and the three booleans (connect_ok,timeout_expired,unhandled_exception) are gone. The behavior is pinned bytest_bluetooth_device_connect_cleanup_contract, which already landed in #1761.Types of changes
Related issue or feature (if applicable):
bluetooth_device_connectcoordinates cleanup via three boolean flags across a 122-line try/except/finally #1754Pull request in esphome (if applicable):
Checklist:
tests/folder).