Skip to content

Multiple fixes for BLE subscriptions - #142

Merged
DennisMoschina merged 11 commits into
mainfrom
subscriptions-fix
Jul 24, 2026
Merged

Multiple fixes for BLE subscriptions#142
DennisMoschina merged 11 commits into
mainfrom
subscriptions-fix

Conversation

@DennisMoschina

Copy link
Copy Markdown
Collaborator

Reduced data races, improved timeout for reading, reduced BLE overhead

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.
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.subscribe and SensorHandler.subscribeToSensorData async (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.

Comment thread lib/src/utils/sensor_scheme_parser/v2_sensor_scheme_reader.dart
Comment thread lib/src/managers/open_earable_sensor_manager.dart
Comment thread lib/src/managers/ble_manager.dart
DennisMoschina and others added 2 commits July 24, 2026 11:41
…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>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ DennisMoschina
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@DennisMoschina
DennisMoschina merged commit a9d8bd6 into main Jul 24, 2026
3 of 4 checks passed
@DennisMoschina
DennisMoschina deleted the subscriptions-fix branch July 24, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants