Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Add info to ios getDeviceDataTypeWithoutConnecting limitation #15

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.0"
version: "1.1.1"
flutter_lints:
dependency: "direct dev"
description:
Expand Down
10 changes: 8 additions & 2 deletions lib/flutter_ftms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ export 'src/ftms/characteristic/machine/control_point/machine_control_point_opco
show MachineControlPointOpcode, MachineControlPointOpcodeType;

export 'package:flutter_blue_plus/flutter_blue_plus.dart'
show BluetoothAdapterState, BluetoothDevice, BluetoothConnectionState, ScanResult;
show
BluetoothAdapterState,
BluetoothDevice,
BluetoothConnectionState,
ScanResult;

class FTMS {
static Stream<BluetoothAdapterState> get bluetoothState => Bluetooth.stateStream;
static Stream<BluetoothAdapterState> get bluetoothState =>
Bluetooth.stateStream;
static Stream<bool> get isScanning => Bluetooth.isScanningStream;
static Stream<List<ScanResult>> get scanResults =>
Bluetooth.scanResultsStream;
Expand Down Expand Up @@ -150,6 +155,7 @@ class FTMS {
return FTMSBluetooth.getDeviceDataType(service);
}

/// @limitation: This function will not work on ios, because "For privacy, iOS & macOS use a randomly generated uuid." (https://github.com/Malte2036/flutter_ftms/issues/14).
static DeviceDataType? getDeviceDataTypeWithoutConnecting(
BluetoothDevice device) {
return FTMSBluetooth.getDeviceDataTypeByBluetoothId(device.remoteId.str);
Expand Down
5 changes: 5 additions & 0 deletions lib/src/ftms_bluetooth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ class FTMSBluetooth {
}

static DeviceDataType? getDeviceDataTypeByBluetoothId(String id) {
if (id.length != 17) {
// no valid mac address
return null;
}

var data = List<int>.from(id
.split(":")
.getRange(4, 6)
Expand Down
27 changes: 24 additions & 3 deletions test/ftms_bluetooth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,30 @@ import 'ftms_bluetooth_test.mocks.dart';
// generate mock files: dart run build_runner build
@GenerateMocks([BluetoothDevice, BluetoothService, BluetoothCharacteristic])
void main() {
test("test getDeviceDataTypeByBluetoothId", () {
var res = FTMSBluetooth.getDeviceDataTypeByBluetoothId("22:22:A4:A6:02:00");
expect(res, DeviceDataType.crossTrainer);
group("test getDeviceDataTypeByBluetoothId", () {
test("test getDeviceDataTypeByBluetoothId with treadmill mac address", () {
var res =
FTMSBluetooth.getDeviceDataTypeByBluetoothId("22:22:A4:A6:02:00");
expect(res, DeviceDataType.crossTrainer);
});

test("test getDeviceDataTypeByBluetoothId with unkown mac address", () {
var res =
FTMSBluetooth.getDeviceDataTypeByBluetoothId("22:22:A4:A6:00:00");
expect(res, null);
});

test("test getDeviceDataTypeByBluetoothId with invalid mac address", () {
var res = FTMSBluetooth.getDeviceDataTypeByBluetoothId("invalid");
expect(res, null);
});

// see https://github.com/Malte2036/flutter_ftms/issues/14
test("test getDeviceDataTypeByBluetoothId with anonymous ios uuid", () {
var res = FTMSBluetooth.getDeviceDataTypeByBluetoothId(
"6920a902-ba0e-4a13-a35f-6bc91161c517");
expect(res, null);
});
});

group("test getFTMSService", () {
Expand Down
Loading