[esp32_ble] Migrate the BLE count machinery to the shared slot counter factory - #18059
Conversation
|
@bluetoothbot review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #18059 +/- ##
=======================================
Coverage 87.11% 87.11%
=======================================
Files 63 63
Lines 14601 14601
Branches 2201 2201
=======================================
Hits 12720 12720
Misses 1574 1574
Partials 307 307 🚀 New features to boost your workflow:
|
5e62c66 to
b0ef638
Compare
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#18059
components: [bluetooth_proxy, esp32_ble, esp32_ble_tracker]
refresh: 1h(Added by the PR bot) |
|
@bluetoothbot review |
f7e717f to
c5a67be
Compare
|
|
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
b0ef638 to
1047b01
Compare
c5a67be to
bdc00c0
Compare
|
@bluetoothbot review |
1047b01 to
9b37520
Compare
bdc00c0 to
11dad94
Compare
|
@bluetoothbot review |
Re-reviewed at |
|
|
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
fixed in fdd2da3 |
|
@bluetoothbot review |
|
Confirmed. All three resolved.
One nit left, non-blocking: proxy test could also assert handler counts stay |
|
|
|
👋 Hi there! This PR modifies 8 file(s) with codeowners. @jesserockz, @Rapsssito, @esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
There was a problem hiding this comment.
Pull request overview
This PR migrates ESP32 BLE handler/listener slot counting to the shared cg.slot_counter() factory so slot counts are stored in CORE.data (reset between runs) instead of module-level state that can leak across compiles in long-lived processes. It also makes the ESP32 BLE tracker’s scanner-state listener storage codegen-sized (and fully compiled out when unused) while keeping existing define names stable for in-tree consumers.
Changes:
- Replaced esp32_ble handler registration counters and FINAL define-emission job with per-handler
cg.slot_counter()requests. - Migrated esp32_ble_tracker listener/client counts (and new scanner-state listener count) to
cg.slot_counter(), and switched scanner-state listeners fromstd::vectorto codegen-sizedStaticVectorguarded by a define. - Updated bluetooth_proxy to register as a scanner-state listener via a new
esp32_ble_tracker.register_scanner_state_listener()helper, and added component tests + configs to validate define emission and cross-compile count resets.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/component_tests/ble_device_base/test_slot_counter.py | Adds assertions for ESP32 BLE handler/listener defines and verifies counts reset between compiles. |
| tests/component_tests/ble_device_base/config/esp32_tracker_only.yaml | Adds a minimal ESP32 IDF tracker-only config for slot counter tests. |
| tests/component_tests/ble_device_base/config/esp32_bluetooth_proxy.yaml | Adds a proxy config to validate scanner-state/listener/client slot define emission. |
| esphome/core/defines.h | Adds the new scanner-state listener count define for static-analysis/IDE builds. |
| esphome/components/esp32_ble/init.py | Switches handler count machinery to cg.slot_counter() requests; removes module-level dataclass counters and FINAL job. |
| esphome/components/esp32_ble_tracker/esp32_ble_tracker.h | Guards scanner-state listener API/storage behind a define and uses StaticVector instead of std::vector. |
| esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp | Wraps scanner-state listener dispatch in the new compile-time guard. |
| esphome/components/esp32_ble_tracker/automation.h | Adds <vector> include (no longer inherited from the main tracker header). |
| esphome/components/esp32_ble_tracker/init.py | Migrates listener/client counting to cg.slot_counter() and adds register_scanner_state_listener() helper. |
| esphome/components/bluetooth_proxy/bluetooth_proxy.cpp | Removes direct runtime registration of the scanner-state listener from setup(). |
| esphome/components/bluetooth_proxy/init.py | Registers the proxy’s scanner-state listener via the new codegen helper. |
|
@bluetoothbot review |
4522f45 to
668792a
Compare
Understood. Dropped, not re-raised. Grep confirms |
|
|
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
… listeners in codegen
|
Thanks |
|
@bluetoothbot review |
668792a to
2855922
Compare
PR Review — [esp32_ble] Migrate the BLE count machinery to the shared slot counter factoryMerge-ready. Independently re-verified against the tree; no blocking issues, and nothing new since the last pass. What this PR gets right, specifically:
Checklist
Automated review by Kōan (Claude) |
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
What does this implement/fix?
Moves the esp32 BLE count machinery onto the shared slot counter factory from #18057. The five esp32_ble handler counters lived in a module level dataclass, which survives between compiles when the host process stays alive (device-builder, dashboard); they now live in CORE.data through the factory, which clears between runs. On the old code each compile in such a process grew every handler count by one, so later builds oversized the StaticCallbackManager storage; the counts now start from zero every compile. The esp32_ble_tracker listener and client counters move to factory instances as well, and its FINAL job now only handles the feature coupling.
The tracker's scanner state listeners also move from std::vector to the codegen sized StaticVector pattern; bluetooth_proxy is the only subscriber and now requests a slot from its to_code, so a build without it carries no scanner state listener storage at all.
All define names are unchanged; no in tree consumer components need changes. The tracker's add_scanner_state_listener method is now compiled only when a codegen registration requests a slot. That method has only ever served bluetooth_proxy (added for it in #8649, reshaped in #12156) and the proxy now registers through the new esp32_ble_tracker.register_scanner_state_listener codegen helper, which any future consumer should use as well.
Chained on #18057.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome.io with documentation (if applicable):
Pull request in developers.esphome.io with developer documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: