Multiple fixes for BLE subscriptions - #142
Conversation
BREAKING CHANGE: BleGattManager.subscribe and SensorHandler.subscribeToSensorData now return Future<Stream<...>> so callers can await notification readiness before issuing dependent writes.
Document the breaking BLE subscription API changes and the notification setup race fix in the unreleased changelog.
… allow retries on failure
…with notification support and fallback
|
Visit the preview URL for this PR (updated for commit 8113e33): https://open-earable-lib-web-example--pr142-subscriptions-fix-c1glxhf9.web.app (expires Fri, 21 Aug 2026 09:57:48 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 7f6db4d9d00b851ad49af109fa949061904b3151 |
There was a problem hiding this comment.
Pull request overview
This PR hardens BLE notification subscriptions and sensor-stream setup across the library to reduce subscription races, connection duplication, and improve OpenEarable V2 sensor-scheme reading reliability (including a notification→read fallback path).
Changes:
- Make
BleGattManager.subscribeandSensorHandler.subscribeToSensorDataasync (Future<Stream<...>>) so callers can await notification readiness before listening. - Rework several device streams to set up subscriptions in
onListen, add closed-controller guards, and improve cancellation behavior. - Improve OpenEarable V2 sensor-scheme loading by keeping a single notification subscription during scheme reads and adding synchronous-read/legacy fallbacks.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/src/utils/sensor_scheme_parser/v2_sensor_scheme_reader.dart | Adds buffered notification matching + read fallback for V2 sensor schemes. |
| lib/src/models/devices/polar_factory.dart | Awaits BLE subscription setup and guards stream controller usage. |
| lib/src/models/devices/open_ring.dart | Awaits BLE subscription setup and adds error-handling guards for battery/time sync. |
| lib/src/models/devices/open_earable_v2.dart | Moves subscribe/read setup into async onListen with closed-controller checks. |
| lib/src/models/devices/open_earable_v1.dart | Adds closed-controller guards + error propagation for battery/sensor streams. |
| lib/src/models/devices/open_earable_factory.dart | Awaits sensor subscription setup and guards controller writes. |
| lib/src/models/devices/esense_factory.dart | Awaits sensor subscription setup and adds cancellation + error guards. |
| lib/src/models/devices/cosinuss_one.dart | Awaits BLE subscription setup and adds controller lifecycle guards. |
| lib/src/models/devices/battery_gatt_reader/battery_level_status_service_gatt_reader.dart | Refactors polling via helper + unawaited, adds closed-controller guard. |
| lib/src/models/devices/battery_gatt_reader/battery_level_status_gatt_reader.dart | Refactors polling via helper + unawaited, adds closed-controller guard. |
| lib/src/models/devices/battery_gatt_reader/battery_health_status_gatt_reader.dart | Refactors polling via helper + unawaited, adds closed-controller guard. |
| lib/src/models/devices/battery_gatt_reader/battery_energy_status_gatt_reader.dart | Refactors polling via helper + unawaited, adds closed-controller guard. |
| lib/src/models/capabilities/sensor_specializations/open_ring/open_ring_sensor.dart | Makes OpenRing sensor subscription setup async and idempotent. |
| lib/src/managers/v2_sensor_handler.dart | Makes sensor subscription async and awaits BLE notification readiness. |
| lib/src/managers/sensor_handler.dart | Updates interface to Future<Stream<...>> for subscription readiness. |
| lib/src/managers/open_ring_sensor_handler.dart | Makes shared OpenRing data stream creation async and awaits BLE subscription. |
| lib/src/managers/open_earable_sensor_manager.dart | Makes sensor subscription async and awaits BLE notification readiness. |
| lib/src/managers/esense_sensor_handler.dart | Makes sensor subscription async and awaits BLE notification readiness. |
| lib/src/managers/ble_manager.dart | Adds pending connection reuse + async subscribe with setup/teardown tracking. |
| lib/src/managers/ble_gatt_manager.dart | Updates subscribe API contract to Future<Stream<...>>. |
| lib/open_earable_flutter.dart | Deduplicates wearable connection attempts by caching in-flight futures. |
| CHANGELOG.md | Documents breaking API changes and summarizes the BLE subscription fixes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…rData when device is not connected Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
|
Reduced data races, improved timeout for reading, reduced BLE overhead