Skip to content

Commit 8e6af9c

Browse files
open_wearable/lib/view_models/wearable_provider.dart: automatically pair matching stereo devices
1 parent cb76857 commit 8e6af9c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

open_wearable/lib/view_models/wearables_provider.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ class WearablesProvider with ChangeNotifier {
99
List<Wearable> get wearables => _wearables;
1010
Map<Wearable, SensorConfigurationProvider> get sensorConfigurationProviders => _sensorConfigurationProviders;
1111

12-
void addWearable(Wearable wearable) {
12+
void addWearable(Wearable wearable) async {
1313
// ignore all wearables that are already added
1414
if (_wearables.any((w) => w.deviceId == wearable.deviceId)) {
1515
return;
1616
}
17+
1718
_wearables.add(wearable);
1819
if (wearable is SensorConfigurationManager) {
1920
if (!_sensorConfigurationProviders.containsKey(wearable)) {
@@ -33,6 +34,21 @@ class WearablesProvider with ChangeNotifier {
3334
removeWearable(wearable);
3435
notifyListeners();
3536
});
37+
38+
if (wearable is StereoDevice) {
39+
if (await (wearable as StereoDevice).pairedDevice == null) {
40+
List<StereoDevice> possiblePairs =
41+
await WearableManager().findValidPairsFor((wearable as StereoDevice), _wearables.whereType<StereoDevice>().toList());
42+
43+
logger.d("possible pairs: $possiblePairs");
44+
45+
if (possiblePairs.isNotEmpty) {
46+
(wearable as StereoDevice).pair(possiblePairs.first);
47+
logger.i("Paired ${wearable.name} with ${(wearable as StereoDevice).pairedDevice}");
48+
}
49+
}
50+
}
51+
3652
notifyListeners();
3753
}
3854

0 commit comments

Comments
 (0)