From ab576de4f62740479d605c4c5dda5b16b2ddf9cd Mon Sep 17 00:00:00 2001 From: Malte2036 Date: Wed, 29 May 2024 14:35:53 +0200 Subject: [PATCH 1/2] :memo: Add info to ios getDeviceDataTypeWithoutConnecting limitation --- example/pubspec.lock | 2 +- lib/flutter_ftms.dart | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index bd56b45..385139e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -76,7 +76,7 @@ packages: path: ".." relative: true source: path - version: "1.1.0" + version: "1.1.1" flutter_lints: dependency: "direct dev" description: diff --git a/lib/flutter_ftms.dart b/lib/flutter_ftms.dart index 8270268..9ed8ab5 100644 --- a/lib/flutter_ftms.dart +++ b/lib/flutter_ftms.dart @@ -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 get bluetoothState => Bluetooth.stateStream; + static Stream get bluetoothState => + Bluetooth.stateStream; static Stream get isScanning => Bluetooth.isScanningStream; static Stream> get scanResults => Bluetooth.scanResultsStream; @@ -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); From 0600c4cebc89aae5067514bf967eb2be46f0d2d0 Mon Sep 17 00:00:00 2001 From: Malte2036 Date: Wed, 29 May 2024 14:42:11 +0200 Subject: [PATCH 2/2] :white_check_mark: Add test for getDeviceDataTypeByBluetoothId with anonymous ios uuid --- lib/src/ftms_bluetooth.dart | 5 +++++ test/ftms_bluetooth_test.dart | 27 ++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/src/ftms_bluetooth.dart b/lib/src/ftms_bluetooth.dart index 4403497..8a3efcd 100644 --- a/lib/src/ftms_bluetooth.dart +++ b/lib/src/ftms_bluetooth.dart @@ -216,6 +216,11 @@ class FTMSBluetooth { } static DeviceDataType? getDeviceDataTypeByBluetoothId(String id) { + if (id.length != 17) { + // no valid mac address + return null; + } + var data = List.from(id .split(":") .getRange(4, 6) diff --git a/test/ftms_bluetooth_test.dart b/test/ftms_bluetooth_test.dart index 9ad7c72..019b52b 100644 --- a/test/ftms_bluetooth_test.dart +++ b/test/ftms_bluetooth_test.dart @@ -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", () {