feat: add async_address_reachability_diagnostics for unreachable devices - #517
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #517 +/- ##
==========================================
+ Coverage 98.19% 98.24% +0.05%
==========================================
Files 15 15
Lines 2605 2682 +77
Branches 367 385 +18
==========================================
+ Hits 2558 2635 +77
Misses 21 21
Partials 26 26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
Comparing Footnotes
|
PR Review — feat: add async_address_reachability_diagnostics for unreachable devicesSolid, well-scoped diagnostics-first change in the spirit of the prior PR #416 learning. The new method is explicitly read-only, side-effect free, documented as cold-path-only, and the returned string is documented as unstable so callers don't grow a parsing habit. The 🟢 Suggestions1. Duplicate iteration / repeated get_allocations() in cold path (`src/habluetooth/manager.py`, L1080-1115)Minor: 2. `connecting_count` vs `connections_in_progress()` are easy to confuse (`src/habluetooth/base_scanner.py`, L270-281)These are two related-but-different counters now both exposed publicly with similar-looking names:
The docstrings call this out clearly, but the names alone don't, and a future caller is likely to grab whichever shows up first in autocomplete. Optional rename to something like Checklist
SummarySolid, well-scoped diagnostics-first change in the spirit of the prior PR #416 learning. The new method is explicitly read-only, side-effect free, documented as cold-path-only, and the returned string is documented as unstable so callers don't grow a parsing habit. The Automated review by Kōan80f6c1b |
When a device cannot be found, callers only get a bare "not found" with no way to tell why. This adds
BluetoothManager.async_address_reachability_diagnostics(address, intent), a read only, side effect free helper that returns a human readable summary tailored to what the caller needs.The intent comes from a new
BluetoothReachabilityIntentenum;PASSIVE_ADVERTISEMENTandACTIVE_ADVERTISEMENT(scan response, treated the same as passive for now) only report whether the device is being seen, whileCONNECTIONalso reports connectable history, whether a connectable path exists, per scanner failures, in progress connections and slot allocations.Every result includes a scanner availability summary; how many scanners are registered, scanning and connectable. It calls out the common failure where scanners pause scanning while connecting, so if they are all stuck retrying connections no advertisements can be received at all and the device vanishes; in that case it advises adding more adapters or proxies since the available ones are overloaded.
The wrappers "No backend with an available connection slot" BleakError now embeds the connection intent summary so the cause shows up in logs.
Meant to be surfaced by Home Assistant (switchbot reports "Could not find Switchbot ... with address X" with no reason today); see home-assistant/core#170232.