From 4870ffe5dc9b2882288c404a042b0e7885f04b4c Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 09:18:31 +0100 Subject: [PATCH 01/90] refactor: create platform interface package --- LICENSE | 4 +-- .../.gitignore | 29 +++++++++++++++++++ .../.metadata | 10 +++++++ .../LICENSE | 28 ++++++++++++++++++ .../README.md | 18 ++++++++++++ .../flutter_blue_plus_platform_interface.dart | 1 + .../lib/src/flutter_blue_plus_platform.dart | 24 +++++++++++++++ .../src/method_channel_flutter_blue_plus.dart | 4 +++ .../pubspec.yaml | 17 +++++++++++ ...ter_blue_plus_platform_interface_test.dart | 0 10 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/.gitignore create mode 100644 packages/flutter_blue_plus_platform_interface/.metadata create mode 100644 packages/flutter_blue_plus_platform_interface/LICENSE create mode 100644 packages/flutter_blue_plus_platform_interface/README.md create mode 100644 packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart create mode 100644 packages/flutter_blue_plus_platform_interface/pubspec.yaml create mode 100644 packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart diff --git a/LICENSE b/LICENSE index 1b371f05..5341ca7c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2017-2023, Paul DeMarco, Bosko Popovic, & Charles Weinberger. +Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger, Thomas Clark. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -25,4 +25,4 @@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_platform_interface/.gitignore b/packages/flutter_blue_plus_platform_interface/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/packages/flutter_blue_plus_platform_interface/.metadata b/packages/flutter_blue_plus_platform_interface/.metadata new file mode 100644 index 00000000..3bb479b8 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" + channel: "beta" + +project_type: package diff --git a/packages/flutter_blue_plus_platform_interface/LICENSE b/packages/flutter_blue_plus_platform_interface/LICENSE new file mode 100644 index 00000000..5341ca7c --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/LICENSE @@ -0,0 +1,28 @@ +Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger, Thomas Clark. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Buffalo PC Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_platform_interface/README.md b/packages/flutter_blue_plus_platform_interface/README.md new file mode 100644 index 00000000..1a9cac80 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/README.md @@ -0,0 +1,18 @@ +# flutter_blue_plus_platform_interface + +A common platform interface for the [`flutter_blue_plus`][1] plugin. + +This interface allows platform-specific implementations of the `flutter_blue_plus` +plugin, as well as the plugin itself, to ensure they are supporting the +same interface. + +# Usage + +To implement a new platform-specific implementation of `flutter_blue_plus`, extend +[`FlutterBluePlusPlatform`][2] with an implementation that performs the +platform-specific behavior, and when you register your plugin, set the default +`FlutterBluePlusPlatform` by calling +`FlutterBluePlusPlatform.instance = MyPlatformFlutterBluePlus()`. + +[1]: ../flutter_blue_plus +[2]: lib/flutter_blue_plus_platform_interface.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart new file mode 100644 index 00000000..ea67d9fa --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -0,0 +1 @@ +export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart new file mode 100644 index 00000000..73e2b21c --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -0,0 +1,24 @@ +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'method_channel_flutter_blue_plus.dart'; + +/// The interface that implementations of flutter_blue_plus must implement. +abstract class FlutterBluePlusPlatform extends PlatformInterface { + FlutterBluePlusPlatform() : super(token: _token); + + static final _token = Object(); + + static FlutterBluePlusPlatform _instance = MethodChannelFlutterBluePlus(); + + /// The default instance of [FlutterBluePlusPlatform] to use. + /// + /// Defaults to [MethodChannelFlutterBluePlus]. + static FlutterBluePlusPlatform get instance => _instance; + + /// Platform-specific plugins should set this with their own platform-specific + /// class that extends [FlutterBluePlusPlatform] when they register themselves. + static set instance(FlutterBluePlusPlatform instance) { + PlatformInterface.verify(instance, _token); + _instance = instance; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart new file mode 100644 index 00000000..a2b8fc02 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -0,0 +1,4 @@ +import 'flutter_blue_plus_platform.dart'; + +/// An implementation of [FlutterBluePlusPlatform] that uses method channels. +class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform {} diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml new file mode 100644 index 00000000..cd882ac9 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -0,0 +1,17 @@ +name: flutter_blue_plus_platform_interface +description: A common platform interface for the flutter_blue_plus plugin. +version: 0.0.0 +homepage: https://github.com/boskokg/flutter_blue_plus + +environment: + sdk: ">=2.12.0 <4.0.0" + flutter: ">=1.17.0" + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.0 + +dev_dependencies: + flutter_test: + sdk: flutter diff --git a/packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart b/packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart new file mode 100644 index 00000000..e69de29b From 9b94209be5eab430d4a60dd7d838c1ec9795b02f Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 12:38:32 +0100 Subject: [PATCH 02/90] chore: add analysis options --- .../flutter_blue_plus_platform_interface/analysis_options.yaml | 1 + packages/flutter_blue_plus_platform_interface/pubspec.yaml | 1 + 2 files changed, 2 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/analysis_options.yaml diff --git a/packages/flutter_blue_plus_platform_interface/analysis_options.yaml b/packages/flutter_blue_plus_platform_interface/analysis_options.yaml new file mode 100644 index 00000000..f9b30346 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index cd882ac9..7c1f2450 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -13,5 +13,6 @@ dependencies: plugin_platform_interface: ^2.0.0 dev_dependencies: + flutter_lints: ^4.0.0 flutter_test: sdk: flutter From 8990aa52311231d4b5eb63d1590c4920167d5c71 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 12:38:59 +0100 Subject: [PATCH 03/90] refactor: add common models --- .../src/common/models/device_identifier.dart | 25 +++++ .../lib/src/common/models/guid.dart | 97 +++++++++++++++++++ .../pubspec.yaml | 1 + 3 files changed, 123 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart new file mode 100644 index 00000000..0836671f --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart @@ -0,0 +1,25 @@ +class DeviceIdentifier { + final String str; + + DeviceIdentifier(this.str); + + @override + String toString() { + return str; + } + + @override + int get hashCode { + return str.toLowerCase().hashCode; + } + + @override + bool operator ==(other) { + return other is DeviceIdentifier && hashCode == other.hashCode; + } + + @Deprecated('Use str instead') + String get id { + return str; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart new file mode 100644 index 00000000..d0dd9aae --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart @@ -0,0 +1,97 @@ +import 'package:convert/convert.dart'; + +class Guid { + static const _suffix = '-0000-1000-8000-00805f9b34fb'; + + final List bytes; + + Guid.empty() : bytes = List.filled(16, 0); + + Guid.fromBytes(this.bytes) + : assert( + _checkLen(bytes.length), + 'GUID must be 16, 32, or 128 bit.', + ); + + Guid.fromString(String input) : bytes = _fromString(input); + + Guid(String input) : bytes = _fromString(input); + + static List _fromString(String input) { + if (input.isEmpty) { + return List.filled(16, 0); + } + + input = input.replaceAll('-', ''); + + List bytes; + try { + bytes = hex.decode(input); + } catch (e) { + throw FormatException('GUID not hex format: $input'); + } + + _checkLen(bytes.length); + + return bytes; + } + + static bool _checkLen(int len) { + if (!(len == 16 || len == 4 || len == 2)) { + throw FormatException( + 'GUID must be 16, 32, or 128 bit, yours: ${len * 8}-bit', + ); + } + return true; + } + + // 128-bit representation + String get str128 { + if (bytes.length == 2) { + // 16-bit uuid + return '0000${hex.encode(bytes)}$_suffix'.toLowerCase(); + } + if (bytes.length == 4) { + // 32-bit uuid + return '${hex.encode(bytes)}$_suffix'.toLowerCase(); + } + // 128-bit uuid + String one = hex.encode(bytes.sublist(0, 4)); + String two = hex.encode(bytes.sublist(4, 6)); + String three = hex.encode(bytes.sublist(6, 8)); + String four = hex.encode(bytes.sublist(8, 10)); + String five = hex.encode(bytes.sublist(10, 16)); + return '$one-$two-$three-$four-$five'.toLowerCase(); + } + + // shortest representation + String get str { + bool starts = str128.startsWith('0000'); + bool ends = str128.endsWith(_suffix); + if (starts && ends) { + // 16-bit + return str128.substring(4, 8); + } + if (ends) { + // 32-bit + return str128.substring(0, 8); + } + // 128-bit + return str128; + } + + @override + String toString() => str; + + @override + operator ==(other) => other is Guid && hashCode == other.hashCode; + + @override + int get hashCode => str128.hashCode; + + @Deprecated('use str128 instead') + String get uuid128 => str128; + + @Deprecated('use str instead') + String get uuid => str; +} diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index 7c1f2450..1804d08c 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -8,6 +8,7 @@ environment: flutter: ">=1.17.0" dependencies: + convert: ^3.0.0 flutter: sdk: flutter plugin_platform_interface: ^2.0.0 From 31ee2a33db232843a328c09b73496c02a0ccafc6 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 13:28:04 +0100 Subject: [PATCH 04/90] test: add common models --- .../flutter_blue_plus_platform_interface.dart | 2 + .../src/common/models/device_identifier.dart | 10 +- .../lib/src/common/models/guid.dart | 42 ++- .../test/device_identifier_test.dart | 79 +++++ ...ter_blue_plus_platform_interface_test.dart | 0 .../test/guid_test.dart | 289 ++++++++++++++++++ 6 files changed, 406 insertions(+), 16 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/guid_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index ea67d9fa..b4e9dad8 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -1 +1,3 @@ +export 'src/common/models/device_identifier.dart'; +export 'src/common/models/guid.dart'; export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart index 0836671f..2d090b93 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart @@ -13,13 +13,13 @@ class DeviceIdentifier { return str.toLowerCase().hashCode; } - @override - bool operator ==(other) { - return other is DeviceIdentifier && hashCode == other.hashCode; - } - @Deprecated('Use str instead') String get id { return str; } + + @override + bool operator ==(other) { + return other is DeviceIdentifier && hashCode == other.hashCode; + } } diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart index d0dd9aae..4a244914 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart @@ -13,9 +13,19 @@ class Guid { 'GUID must be 16, 32, or 128 bit.', ); - Guid.fromString(String input) : bytes = _fromString(input); + Guid.fromString(String input) + : bytes = _fromString(input), + assert( + _checkLen(hex.decode(input.replaceAll('-', '')).length), + 'GUID must be 16, 32, or 128 bit.', + ); - Guid(String input) : bytes = _fromString(input); + Guid(String input) + : bytes = _fromString(input), + assert( + _checkLen(hex.decode(input.replaceAll('-', '')).length), + 'GUID must be 16, 32, or 128 bit.', + ); static List _fromString(String input) { if (input.isEmpty) { @@ -81,17 +91,27 @@ class Guid { } @override - String toString() => str; - - @override - operator ==(other) => other is Guid && hashCode == other.hashCode; + int get hashCode { + return str128.hashCode; + } - @override - int get hashCode => str128.hashCode; + @Deprecated('use str instead') + String get uuid { + return str; + } @Deprecated('use str128 instead') - String get uuid128 => str128; + String get uuid128 { + return str128; + } - @Deprecated('use str instead') - String get uuid => str; + @override + operator ==(other) { + return other is Guid && hashCode == other.hashCode; + } + + @override + String toString() { + return str; + } } diff --git a/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart b/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart new file mode 100644 index 00000000..b08a090d --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart @@ -0,0 +1,79 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'DeviceIdentifier', + () { + group( + 'hashCode', + () { + test( + 'returns the hash code of a lower case identifier', + () { + expect( + DeviceIdentifier('str').hashCode, + equals('str'.hashCode), + ); + }, + ); + + test( + 'returns the hash code of a mixed case identifier', + () { + expect( + DeviceIdentifier('sTr').hashCode, + equals('str'.hashCode), + ); + }, + ); + + test( + 'returns the hash code of an upper case identifier', + () { + expect( + DeviceIdentifier('STR').hashCode, + equals('str'.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if the identifiers are not equal', + () { + expect( + DeviceIdentifier('str1') == DeviceIdentifier('str2'), + isFalse, + ); + }, + ); + + test( + 'returns true if the identifiers are equal', + () { + expect( + DeviceIdentifier('str') == DeviceIdentifier('str'), + isTrue, + ); + }, + ); + + test( + 'returns true if the identifiers are equal ignoring case', + () { + expect( + DeviceIdentifier('str') == DeviceIdentifier('STR'), + isTrue, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart b/packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart new file mode 100644 index 00000000..7c2708fa --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart @@ -0,0 +1,289 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'Guid', + () { + group( + 'fromBytes', + () { + test( + 'constructs an instance from a list of 2 bytes', + () { + expect( + Guid.fromBytes([ + 0x01, + 0x02, + ]).bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'constructs an instance from a list of 4 bytes', + () { + expect( + Guid.fromBytes([ + 0x01, + 0x02, + 0x03, + 0x04, + ]).bytes, + orderedEquals([ + 0x01, + 0x02, + 0x03, + 0x04, + ]), + ); + }, + ); + + test( + 'constructs an instance from a list of 16 bytes', + () { + expect( + Guid.fromBytes([ + 0x01, + 0x02, + 0x03, + 0x04, + 0x00, + 0x00, + 0x10, + 0x00, + 0x80, + 0x00, + 0x00, + 0x80, + 0x5F, + 0x9B, + 0x34, + 0xFB, + ]).bytes, + orderedEquals([ + 0x01, + 0x02, + 0x03, + 0x04, + 0x00, + 0x00, + 0x10, + 0x00, + 0x80, + 0x00, + 0x00, + 0x80, + 0x5F, + 0x9B, + 0x34, + 0xFB, + ]), + ); + }, + ); + + test( + 'throws an exception if the list is not 2 nor 4 nor 16 bytes in length', + () { + expect( + () { + Guid.fromBytes([ + 0x01, + 0x02, + 0x03, + ]); + }, + throwsFormatException, + ); + }, + ); + }, + ); + + group( + 'fromString', + () { + test( + 'constructs an instance from a string of 2 bytes', + () { + expect( + Guid.fromString('0102').bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'constructs an instance from a string of 4 bytes', + () { + expect( + Guid.fromString('01020304').bytes, + orderedEquals([ + 0x01, + 0x02, + 0x03, + 0x04, + ]), + ); + }, + ); + + test( + 'constructs an instance from a string of 16 bytes', + () { + expect( + Guid.fromString('0102030400001000800000805f9b34fb').bytes, + orderedEquals([ + 0x01, + 0x02, + 0x03, + 0x04, + 0x00, + 0x00, + 0x10, + 0x00, + 0x80, + 0x00, + 0x00, + 0x80, + 0x5F, + 0x9B, + 0x34, + 0xFB, + ]), + ); + }, + ); + + test( + 'constructs an instance from a uuid formatted string', + () { + expect( + Guid.fromString('01020304-0000-1000-8000-00805f9b34fb').bytes, + orderedEquals([ + 0x01, + 0x02, + 0x03, + 0x04, + 0x00, + 0x00, + 0x10, + 0x00, + 0x80, + 0x00, + 0x00, + 0x80, + 0x5F, + 0x9B, + 0x34, + 0xFB, + ]), + ); + }, + ); + + test( + 'throws an exception if the string is not 2 nor 4 nor 16 bytes in length', + () { + expect( + () { + Guid.fromString('010203'); + }, + throwsFormatException, + ); + }, + ); + }, + ); + }, + ); + + group( + 'str', + () { + test( + 'returns a string of 2 bytes if the list of bytes is 2 bytes in length', + () { + expect( + Guid('0102').str, + equals('0102'), + ); + }, + ); + + test( + 'returns a string of 4 bytes if the list of bytes is 4 bytes in length', + () { + expect( + Guid('01020304').str, + equals('01020304'), + ); + }, + ); + + test( + 'returns a string of 16 bytes if the list of bytes is 16 bytes in length and does not end with the suffix', + () { + expect( + Guid('01020304-0000-0000-0000-000000000000').str, + equals('01020304-0000-0000-0000-000000000000'), + ); + }, + ); + + test( + 'returns a string of 4 bytes if the list of bytes is 16 bytes in length and ends with the suffix', + () { + expect( + Guid('01020304-0000-1000-8000-00805f9b34fb').str, + equals('01020304'), + ); + }, + ); + }, + ); + + group( + 'str128', + () { + test( + 'returns a string of 16 bytes if the list of bytes is 2 bytes in length', + () { + expect( + Guid('0102').str128, + equals('00000102-0000-1000-8000-00805f9b34fb'), + ); + }, + ); + + test( + 'returns a string of 16 bytes if the list of bytes is 4 bytes in length', + () { + expect( + Guid('01020304').str128, + equals('01020304-0000-1000-8000-00805f9b34fb'), + ); + }, + ); + + test( + 'returns a string of 16 bytes if the list of bytes is 16 bytes in length', + () { + expect( + Guid('01020304-0000-1000-8000-00805f9b34fb').str128, + equals('01020304-0000-1000-8000-00805f9b34fb'), + ); + }, + ); + }, + ); +} From 67fcfd1f8664e180afc44ea4ec90e93a7e90bc34 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 13:31:02 +0100 Subject: [PATCH 05/90] refactor: add adapter enums and models --- .../adapter/enums/bm_adapter_state_enum.dart | 9 ++++++++ .../models/bm_bluetooth_adapter_state.dart | 23 +++++++++++++++++++ .../adapter/models/bm_turn_on_response.dart | 21 +++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart new file mode 100644 index 00000000..68ea06ab --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart @@ -0,0 +1,9 @@ +enum BmAdapterStateEnum { + unknown, // 0 + unavailable, // 1 + unauthorized, // 2 + turningOn, // 3 + on, // 4 + turningOff, // 5 + off, // 6 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart new file mode 100644 index 00000000..699b2a2d --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart @@ -0,0 +1,23 @@ +import '../enums/bm_adapter_state_enum.dart'; + +class BmBluetoothAdapterState { + BmAdapterStateEnum adapterState; + + BmBluetoothAdapterState({ + required this.adapterState, + }); + + factory BmBluetoothAdapterState.fromMap( + Map json, + ) { + return BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.values[json['adapter_state'] as int], + ); + } + + Map toMap() { + return { + 'adapter_state': adapterState.index, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart new file mode 100644 index 00000000..524d25b6 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart @@ -0,0 +1,21 @@ +class BmTurnOnResponse { + bool userAccepted; + + BmTurnOnResponse({ + required this.userAccepted, + }); + + factory BmTurnOnResponse.fromMap( + Map json, + ) { + return BmTurnOnResponse( + userAccepted: json['user_accepted'] ?? false, + ); + } + + Map toMap() { + return { + 'user_accepted': userAccepted, + }; + } +} From 514449b75143be45ef2dde404700cb6ea986df64 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 13:33:40 +0100 Subject: [PATCH 06/90] refactor: add service models --- .../service/models/bm_bluetooth_service.dart | 53 +++++++++++++++++++ .../models/bm_discover_services_result.dart | 46 ++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart new file mode 100644 index 00000000..bffa8440 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart @@ -0,0 +1,53 @@ +import '../../characteristic/models/bm_bluetooth_characteristic.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmBluetoothService { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + bool isPrimary; + List characteristics; + List includedServices; + + BmBluetoothService({ + required this.serviceUuid, + required this.remoteId, + required this.isPrimary, + required this.characteristics, + required this.includedServices, + }); + + factory BmBluetoothService.fromMap( + Map json, + ) { + return BmBluetoothService( + serviceUuid: Guid(json['service_uuid']), + remoteId: DeviceIdentifier(json['remote_id']), + isPrimary: json['is_primary'] == 1, + characteristics: (json['characteristics'] as List?) + ?.map((characteristic) => + BmBluetoothCharacteristic.fromMap(characteristic)) + .toList() ?? + [], + includedServices: (json['included_services'] as List?) + ?.map((includedService) => + BmBluetoothService.fromMap(includedService)) + .toList() ?? + [], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'is_primary': isPrimary ? 1 : 0, + 'characteristics': characteristics + .map((characteristic) => characteristic.toMap()) + .toList(), + 'included_services': includedServices + .map((includedService) => includedService.toMap()) + .toList(), + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart new file mode 100644 index 00000000..f4bf85be --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart @@ -0,0 +1,46 @@ +import '../../common/models/device_identifier.dart'; +import 'bm_bluetooth_service.dart'; + +class BmDiscoverServicesResult { + final DeviceIdentifier remoteId; + final List services; + final bool success; + final int errorCode; + final String errorString; + + BmDiscoverServicesResult({ + required this.remoteId, + required this.services, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmDiscoverServicesResult.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmDiscoverServicesResult( + remoteId: DeviceIdentifier(json['remote_id']), + services: (json['services'] as List?) + ?.map( + (e) => BmBluetoothService.fromMap(e as Map)) + .toList() ?? + [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'services': services.map((service) => service.toMap()).toList(), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} From 6e8b9a9e5ab585ffe2645b7228ec1d3ac589cffb Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 13:34:30 +0100 Subject: [PATCH 07/90] refactor: add scan models --- .../lib/src/scan/models/bm_msd_filter.dart | 31 ++++++++ .../scan/models/bm_scan_advertisement.dart | 71 +++++++++++++++++ .../lib/src/scan/models/bm_scan_response.dart | 42 ++++++++++ .../lib/src/scan/models/bm_scan_settings.dart | 76 +++++++++++++++++++ .../scan/models/bm_service_data_filter.dart | 33 ++++++++ 5 files changed, 253 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart new file mode 100644 index 00000000..ecd77a4f --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart @@ -0,0 +1,31 @@ +import 'package:convert/convert.dart'; + +class BmMsdFilter { + int manufacturerId; + List? data; + List? mask; + + BmMsdFilter( + this.manufacturerId, + this.data, + this.mask, + ); + + factory BmMsdFilter.fromMap( + Map json, + ) { + return BmMsdFilter( + json['manufacturer_id'], + json['data'] != null ? hex.decode(json['data']) : null, + json['mask'] != null ? hex.decode(json['mask']) : null, + ); + } + + Map toMap() { + return { + 'manufacturer_id': manufacturerId, + 'data': data != null ? hex.encode(data!) : null, + 'mask': mask != null ? hex.encode(mask!) : null, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart new file mode 100644 index 00000000..21a2af2d --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart @@ -0,0 +1,71 @@ +import 'package:convert/convert.dart'; + +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmScanAdvertisement { + final DeviceIdentifier remoteId; + final String? platformName; + final String? advName; + final bool connectable; + final int? txPowerLevel; + final int? appearance; // not supported on iOS / macOS + final Map> manufacturerData; + final Map> serviceData; + final List serviceUuids; + final int rssi; + + BmScanAdvertisement({ + required this.remoteId, + required this.platformName, + required this.advName, + required this.connectable, + required this.txPowerLevel, + required this.appearance, + required this.manufacturerData, + required this.serviceData, + required this.serviceUuids, + required this.rssi, + }); + + factory BmScanAdvertisement.fromMap( + Map json, + ) { + return BmScanAdvertisement( + remoteId: DeviceIdentifier(json['remote_id']), + platformName: json['platform_name'], + advName: json['adv_name'], + connectable: json['connectable'] == 1, + txPowerLevel: json['tx_power_level'], + appearance: json['appearance'], + manufacturerData: (json['manufacturer_data'] as Map?) + ?.map((key, value) => MapEntry(key, hex.decode(value))) ?? + {}, + serviceData: (json['service_data'] as Map?) + ?.map((key, value) => MapEntry(Guid(key), hex.decode(value))) ?? + {}, + serviceUuids: (json['service_uuids'] as List?) + ?.map((str) => Guid(str)) + .toList() ?? + [], + rssi: json['rssi'] ?? 0, + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'platform_name': platformName, + 'adv_name': advName, + 'connectable': connectable ? 1 : 0, + 'tx_power_level': txPowerLevel, + 'appearance': appearance, + 'manufacturer_data': manufacturerData + .map((key, value) => MapEntry(key, hex.encode(value))), + 'service_data': + serviceData.map((key, value) => MapEntry(key.str, hex.encode(value))), + 'service_uuids': serviceUuids.map((uuid) => uuid.str).toList(), + 'rssi': rssi, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart new file mode 100644 index 00000000..90ba85aa --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart @@ -0,0 +1,42 @@ +import 'bm_scan_advertisement.dart'; + +class BmScanResponse { + final List advertisements; + final bool success; + final int errorCode; + final String errorString; + + BmScanResponse({ + required this.advertisements, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmScanResponse.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmScanResponse( + advertisements: (json['advertisements'] as List?) + ?.map( + (advertisement) => BmScanAdvertisement.fromMap(advertisement)) + .toList() ?? + [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'advertisements': + advertisements.map((advertisement) => advertisement.toMap()), + 'success': success, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart new file mode 100644 index 00000000..a8d2cc4b --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart @@ -0,0 +1,76 @@ +import '../../common/models/guid.dart'; +import 'bm_msd_filter.dart'; +import 'bm_service_data_filter.dart'; + +class BmScanSettings { + final List withServices; + final List withRemoteIds; + final List withNames; + final List withKeywords; + final List withMsd; + final List withServiceData; + final bool continuousUpdates; + final int continuousDivisor; + final bool androidLegacy; + final int androidScanMode; + final bool androidUsesFineLocation; + + BmScanSettings({ + required this.withServices, + required this.withRemoteIds, + required this.withNames, + required this.withKeywords, + required this.withMsd, + required this.withServiceData, + required this.continuousUpdates, + required this.continuousDivisor, + required this.androidLegacy, + required this.androidScanMode, + required this.androidUsesFineLocation, + }); + + factory BmScanSettings.fromMap( + Map json, + ) { + return BmScanSettings( + withServices: (json['with_services'] as List?) + ?.map((str) => Guid(str)) + .toList() ?? + [], + withRemoteIds: json['with_remote_ids'], + withNames: json['with_names'], + withKeywords: json['with_keywords'], + withMsd: (json['with_msd'] as List?) + ?.map((manufacturerData) => BmMsdFilter.fromMap(manufacturerData)) + .toList() ?? + [], + withServiceData: (json['with_service_data'] as List?) + ?.map((serviceData) => BmServiceDataFilter.fromMap(serviceData)) + .toList() ?? + [], + continuousUpdates: json['continuous_updates'], + continuousDivisor: json['continuous_divisor'], + androidLegacy: json['android_legacy'], + androidScanMode: json['android_scan_mode'], + androidUsesFineLocation: json['android_uses_fine_location'], + ); + } + + Map toMap() { + return { + 'with_services': withServices.map((uuid) => uuid.str).toList(), + 'with_remote_ids': withRemoteIds, + 'with_names': withNames, + 'with_keywords': withKeywords, + 'with_msd': + withMsd.map((manufacturerData) => manufacturerData.toMap()).toList(), + 'with_service_data': + withServiceData.map((serviceData) => serviceData.toMap()).toList(), + 'continuous_updates': continuousUpdates, + 'continuous_divisor': continuousDivisor, + 'android_legacy': androidLegacy, + 'android_scan_mode': androidScanMode, + 'android_uses_fine_location': androidUsesFineLocation, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart new file mode 100644 index 00000000..4f3a9d60 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart @@ -0,0 +1,33 @@ +import 'package:convert/convert.dart'; + +import '../../common/models/guid.dart'; + +class BmServiceDataFilter { + Guid service; + List data; + List mask; + + BmServiceDataFilter( + this.service, + this.data, + this.mask, + ); + + factory BmServiceDataFilter.fromMap( + Map json, + ) { + return BmServiceDataFilter( + Guid(json['service']), + json['data'] != null ? hex.decode(json['data']) : [], + json['mask'] != null ? hex.decode(json['mask']) : [], + ); + } + + Map toMap() { + return { + 'service': service.str, + 'data': hex.encode(data), + 'mask': hex.encode(mask), + }; + } +} From d7f41b4eb881b4d0bbc12232f97c7986bd33659e Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 13:34:39 +0100 Subject: [PATCH 08/90] refactor: add device enums and models --- .../src/device/enums/bm_bond_state_enum.dart | 5 ++ .../enums/bm_connection_priority_enum.dart | 5 ++ .../enums/bm_connection_state_enum.dart | 4 ++ .../device/models/bm_bluetooth_device.dart | 27 +++++++++++ .../device/models/bm_bond_state_response.dart | 34 +++++++++++++ .../src/device/models/bm_connect_request.dart | 27 +++++++++++ .../bm_connection_priority_request.dart | 29 +++++++++++ .../models/bm_connection_state_response.dart | 37 ++++++++++++++ .../src/device/models/bm_devices_list.dart | 48 +++++++++++++++++++ .../device/models/bm_mtu_change_request.dart | 27 +++++++++++ .../models/bm_mtu_changed_response.dart | 41 ++++++++++++++++ .../src/device/models/bm_name_changed.dart | 27 +++++++++++ .../src/device/models/bm_preferred_phy.dart | 35 ++++++++++++++ .../device/models/bm_read_rssi_result.dart | 41 ++++++++++++++++ 14 files changed, 387 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart new file mode 100644 index 00000000..4e9756b1 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart @@ -0,0 +1,5 @@ +enum BmBondStateEnum { + none, // 0 + bonding, // 1 + bonded, // 2 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart new file mode 100644 index 00000000..e205abcb --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart @@ -0,0 +1,5 @@ +enum BmConnectionPriorityEnum { + balanced, // 0 + high, // 1 + lowPower, // 2 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart new file mode 100644 index 00000000..e254b9e9 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart @@ -0,0 +1,4 @@ +enum BmConnectionStateEnum { + disconnected, // 0 + connected, // 1 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart new file mode 100644 index 00000000..dd2bb684 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart @@ -0,0 +1,27 @@ +import '../../common/models/device_identifier.dart'; + +class BmBluetoothDevice { + DeviceIdentifier remoteId; + String? platformName; + + BmBluetoothDevice({ + required this.remoteId, + required this.platformName, + }); + + factory BmBluetoothDevice.fromMap( + Map json, + ) { + return BmBluetoothDevice( + remoteId: DeviceIdentifier(json['remote_id']), + platformName: json['platform_name'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'platform_name': platformName, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart new file mode 100644 index 00000000..c2258855 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart @@ -0,0 +1,34 @@ +import '../../common/models/device_identifier.dart'; +import '../enums/bm_bond_state_enum.dart'; + +class BmBondStateResponse { + final DeviceIdentifier remoteId; + final BmBondStateEnum bondState; + final BmBondStateEnum? prevState; + + BmBondStateResponse({ + required this.remoteId, + required this.bondState, + this.prevState, + }); + + factory BmBondStateResponse.fromMap( + Map json, + ) { + return BmBondStateResponse( + remoteId: DeviceIdentifier(json['remote_id']), + bondState: BmBondStateEnum.values[json['bond_state'] as int], + prevState: json['prev_state'] != null + ? BmBondStateEnum.values[json['prev_state'] as int] + : null, + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'bond_state': bondState.index, + 'prev_state': prevState?.index, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart new file mode 100644 index 00000000..ad0407d8 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart @@ -0,0 +1,27 @@ +import '../../common/models/device_identifier.dart'; + +class BmConnectRequest { + DeviceIdentifier remoteId; + bool autoConnect; + + BmConnectRequest({ + required this.remoteId, + required this.autoConnect, + }); + + factory BmConnectRequest.fromMap( + Map json, + ) { + return BmConnectRequest( + remoteId: DeviceIdentifier(json['remote_id']), + autoConnect: json['auto_connect'] == 1, + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'auto_connect': autoConnect ? 1 : 0, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart new file mode 100644 index 00000000..d9d0c1da --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart @@ -0,0 +1,29 @@ +import '../../common/models/device_identifier.dart'; +import '../enums/bm_connection_priority_enum.dart'; + +class BmConnectionPriorityRequest { + final DeviceIdentifier remoteId; + final BmConnectionPriorityEnum connectionPriority; + + BmConnectionPriorityRequest({ + required this.remoteId, + required this.connectionPriority, + }); + + factory BmConnectionPriorityRequest.fromMap( + Map json, + ) { + return BmConnectionPriorityRequest( + remoteId: DeviceIdentifier(json['remote_id']), + connectionPriority: + BmConnectionPriorityEnum.values[json['connection_priority'] as int], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'connection_priority': connectionPriority.index, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart new file mode 100644 index 00000000..084deb10 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart @@ -0,0 +1,37 @@ +import '../../common/models/device_identifier.dart'; +import '../enums/bm_connection_state_enum.dart'; + +class BmConnectionStateResponse { + final DeviceIdentifier remoteId; + final BmConnectionStateEnum connectionState; + final int? disconnectReasonCode; + final String? disconnectReasonString; + + BmConnectionStateResponse({ + required this.remoteId, + required this.connectionState, + this.disconnectReasonCode, + this.disconnectReasonString, + }); + + factory BmConnectionStateResponse.fromMap( + Map json, + ) { + return BmConnectionStateResponse( + remoteId: DeviceIdentifier(json['remote_id']), + connectionState: + BmConnectionStateEnum.values[json['connection_state'] as int], + disconnectReasonCode: json['disconnect_reason_code'], + disconnectReasonString: json['disconnect_reason_string'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'connection_state': connectionState.index, + 'disconnectReasonCode': disconnectReasonCode, + 'disconnectReasonString': disconnectReasonString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart new file mode 100644 index 00000000..4fa7460e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart @@ -0,0 +1,48 @@ +import 'dart:collection'; + +import 'bm_bluetooth_device.dart'; + +class BmDevicesList extends ListBase { + final List devices; + + BmDevicesList({ + required this.devices, + }); + + factory BmDevicesList.fromMap( + Map json, + ) { + return BmDevicesList( + devices: (json['devices'] as List?) + ?.map((device) => BmBluetoothDevice.fromMap(device)) + .toList() ?? + [], + ); + } + + Map toMap() { + return { + 'devices': devices.map((device) => device.toMap()).toList(), + }; + } + + @override + int get length { + return devices.length; + } + + @override + set length(int newLength) { + devices.length = newLength; + } + + @override + BmBluetoothDevice operator [](int index) { + return devices[index]; + } + + @override + void operator []=(int index, BmBluetoothDevice value) { + devices[index] = value; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart new file mode 100644 index 00000000..86138397 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart @@ -0,0 +1,27 @@ +import '../../common/models/device_identifier.dart'; + +class BmMtuChangeRequest { + final DeviceIdentifier remoteId; + final int mtu; + + BmMtuChangeRequest({ + required this.remoteId, + required this.mtu, + }); + + factory BmMtuChangeRequest.fromMap( + Map json, + ) { + return BmMtuChangeRequest( + remoteId: DeviceIdentifier(json['remote_id']), + mtu: json['mtu'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'mtu': mtu, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart new file mode 100644 index 00000000..ccd1c2ff --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart @@ -0,0 +1,41 @@ +import '../../common/models/device_identifier.dart'; + +class BmMtuChangedResponse { + final DeviceIdentifier remoteId; + final int mtu; + final bool success; + final int errorCode; + final String errorString; + + BmMtuChangedResponse({ + required this.remoteId, + required this.mtu, + this.success = true, + this.errorCode = 0, + this.errorString = '', + }); + + factory BmMtuChangedResponse.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmMtuChangedResponse( + remoteId: DeviceIdentifier(json['remote_id']), + mtu: json['mtu'], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'mtu': mtu, + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart new file mode 100644 index 00000000..75fe4d8b --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart @@ -0,0 +1,27 @@ +import '../../common/models/device_identifier.dart'; + +class BmNameChanged { + DeviceIdentifier remoteId; + String name; + + BmNameChanged({ + required this.remoteId, + required this.name, + }); + + factory BmNameChanged.fromMap( + Map json, + ) { + return BmNameChanged( + remoteId: DeviceIdentifier(json['remote_id']), + name: json['name'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'name': name, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart new file mode 100644 index 00000000..d2c0b630 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart @@ -0,0 +1,35 @@ +import '../../common/models/device_identifier.dart'; + +class BmPreferredPhy { + final DeviceIdentifier remoteId; + final int txPhy; + final int rxPhy; + final int phyOptions; + + BmPreferredPhy({ + required this.remoteId, + required this.txPhy, + required this.rxPhy, + required this.phyOptions, + }); + + factory BmPreferredPhy.fromMap( + Map json, + ) { + return BmPreferredPhy( + remoteId: DeviceIdentifier(json['remote_id']), + txPhy: json['tx_phy'], + rxPhy: json['rx_phy'], + phyOptions: json['phy_options'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'tx_phy': txPhy, + 'rx_phy': rxPhy, + 'phy_options': phyOptions, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart new file mode 100644 index 00000000..81aa5822 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart @@ -0,0 +1,41 @@ +import '../../common/models/device_identifier.dart'; + +class BmReadRssiResult { + final DeviceIdentifier remoteId; + final int rssi; + final bool success; + final int errorCode; + final String errorString; + + BmReadRssiResult({ + required this.remoteId, + required this.rssi, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmReadRssiResult.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmReadRssiResult( + remoteId: DeviceIdentifier(json['remote_id']), + rssi: json['rssi'], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'rssi': rssi, + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} From f99870647bcc5df7d6cf22cbb8a211699331e582 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 13:34:49 +0100 Subject: [PATCH 09/90] refactor: add descriptor models --- .../models/bm_bluetooth_descriptor.dart | 36 +++++++++++ .../descriptor/models/bm_descriptor_data.dart | 62 +++++++++++++++++++ .../models/bm_read_descriptor_request.dart | 42 +++++++++++++ .../models/bm_write_descriptor_request.dart | 48 ++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart new file mode 100644 index 00000000..344124b5 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart @@ -0,0 +1,36 @@ +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmBluetoothDescriptor { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + + BmBluetoothDescriptor({ + required this.remoteId, + required this.serviceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + }); + + factory BmBluetoothDescriptor.fromMap( + Map json, + ) { + return BmBluetoothDescriptor( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart new file mode 100644 index 00000000..7eb0a236 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart @@ -0,0 +1,62 @@ +import 'package:convert/convert.dart'; + +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmDescriptorData { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + final List value; + final bool success; + final int errorCode; + final String errorString; + + BmDescriptorData({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + required this.value, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmDescriptorData.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmDescriptorData( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + 'value': hex.encode(value), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart new file mode 100644 index 00000000..b6ec526e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart @@ -0,0 +1,42 @@ +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmReadDescriptorRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + + BmReadDescriptorRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + }); + + factory BmReadDescriptorRequest.fromMap( + Map json, + ) { + return BmReadDescriptorRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart new file mode 100644 index 00000000..b5449818 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart @@ -0,0 +1,48 @@ +import 'package:convert/convert.dart'; + +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmWriteDescriptorRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + final List value; + + BmWriteDescriptorRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + required this.value, + }); + + factory BmWriteDescriptorRequest.fromMap( + Map json, + ) { + return BmWriteDescriptorRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + 'value': hex.encode(value), + }; + } +} From 7c1d7fc153c9f090e11b19ec8114447e5bd98533 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 13:35:07 +0100 Subject: [PATCH 10/90] refactor: add characteristic enums nd models --- .../characteristic/enums/bm_write_type.dart | 4 ++ .../models/bm_bluetooth_characteristic.dart | 65 +++++++++++++++++++ .../models/bm_characteristic_data.dart | 56 ++++++++++++++++ .../models/bm_characteristic_properties.dart | 57 ++++++++++++++++ .../bm_read_characteristic_request.dart | 38 +++++++++++ .../models/bm_set_notify_value_request.dart | 46 +++++++++++++ .../bm_write_characteristic_request.dart | 53 +++++++++++++++ 7 files changed, 319 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart new file mode 100644 index 00000000..2ffb5318 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart @@ -0,0 +1,4 @@ +enum BmWriteType { + withResponse, // 0 + withoutResponse, // 1 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart new file mode 100644 index 00000000..a1cbb6e5 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart @@ -0,0 +1,65 @@ +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; +import '../../descriptor/models/bm_bluetooth_descriptor.dart'; +import 'bm_characteristic_properties.dart'; + +class BmBluetoothCharacteristic { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + List descriptors; + BmCharacteristicProperties properties; + + BmBluetoothCharacteristic({ + required this.remoteId, + required this.serviceUuid, + required this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptors, + required this.properties, + }); + + factory BmBluetoothCharacteristic.fromMap( + Map json, + ) { + return BmBluetoothCharacteristic( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptors: (json['descriptors'] as List?) + ?.map((descriptor) => BmBluetoothDescriptor.fromMap(descriptor)) + .toList() ?? + [], + properties: json['properties'] != null + ? BmCharacteristicProperties.fromMap(json['properties']) + : BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptors': + descriptors.map((descriptor) => descriptor.toMap()).toList(), + 'properties': properties.toMap(), + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart new file mode 100644 index 00000000..2b887108 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart @@ -0,0 +1,56 @@ +import 'package:convert/convert.dart'; + +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmCharacteristicData { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final List value; + final bool success; + final int errorCode; + final String errorString; + + BmCharacteristicData({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.value, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmCharacteristicData.fromMap( + Map json, + ) { + return BmCharacteristicData( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + success: json['success'] != 0, + errorCode: json['error_code'], + errorString: json['error_string'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'value': hex.encode(value), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart new file mode 100644 index 00000000..0204ab0f --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart @@ -0,0 +1,57 @@ +class BmCharacteristicProperties { + bool broadcast; + bool read; + bool writeWithoutResponse; + bool write; + bool notify; + bool indicate; + bool authenticatedSignedWrites; + bool extendedProperties; + bool notifyEncryptionRequired; + bool indicateEncryptionRequired; + + BmCharacteristicProperties({ + required this.broadcast, + required this.read, + required this.writeWithoutResponse, + required this.write, + required this.notify, + required this.indicate, + required this.authenticatedSignedWrites, + required this.extendedProperties, + required this.notifyEncryptionRequired, + required this.indicateEncryptionRequired, + }); + + factory BmCharacteristicProperties.fromMap( + Map json, + ) { + return BmCharacteristicProperties( + broadcast: json['broadcast'] == 1, + read: json['read'] == 1, + writeWithoutResponse: json['write_without_response'] == 1, + write: json['write'] == 1, + notify: json['notify'] == 1, + indicate: json['indicate'] == 1, + authenticatedSignedWrites: json['authenticated_signed_writes'] == 1, + extendedProperties: json['extended_properties'] == 1, + notifyEncryptionRequired: json['notify_encryption_required'] == 1, + indicateEncryptionRequired: json['indicate_encryption_required'] == 1, + ); + } + + Map toMap() { + return { + 'broadcast': broadcast ? 1 : 0, + 'read': read ? 1 : 0, + 'write_without_response': writeWithoutResponse ? 1 : 0, + 'write': write ? 1 : 0, + 'notify': notify ? 1 : 0, + 'indicate': indicate ? 1 : 0, + 'authenticated_signed_writes': authenticatedSignedWrites ? 1 : 0, + 'extended_properties': extendedProperties ? 1 : 0, + 'notify_encryption_required': notifyEncryptionRequired ? 1 : 0, + 'indicate_encryption_required': indicateEncryptionRequired ? 1 : 0, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart new file mode 100644 index 00000000..3638432a --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart @@ -0,0 +1,38 @@ +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmReadCharacteristicRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + + BmReadCharacteristicRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + }); + + factory BmReadCharacteristicRequest.fromMap( + Map json, + ) { + return BmReadCharacteristicRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart new file mode 100644 index 00000000..6bc2315e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart @@ -0,0 +1,46 @@ +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; + +class BmSetNotifyValueRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final bool forceIndications; + final bool enable; + + BmSetNotifyValueRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.forceIndications, + required this.enable, + }); + + factory BmSetNotifyValueRequest.fromMap( + Map json, + ) { + return BmSetNotifyValueRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + forceIndications: json['force_indications'], + enable: json['enable'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'force_indications': forceIndications, + 'enable': enable, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart new file mode 100644 index 00000000..e516eb13 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart @@ -0,0 +1,53 @@ +import 'package:convert/convert.dart'; + +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; +import '../enums/bm_write_type.dart'; + +class BmWriteCharacteristicRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final BmWriteType writeType; + final bool allowLongWrite; + final List value; + + BmWriteCharacteristicRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.writeType, + required this.allowLongWrite, + required this.value, + }); + + factory BmWriteCharacteristicRequest.fromMap( + Map json, + ) { + return BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + writeType: BmWriteType.values[json['write_type'] as int], + allowLongWrite: json['allow_long_write'] != 0, + value: json['value'] != null ? hex.decode(json['value']) : [], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'write_type': writeType.index, + 'allow_long_write': allowLongWrite ? 1 : 0, + 'value': hex.encode(value), + }; + } +} From f11da6113eefdfa721f49ee8eb98e84987135976 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 13:58:54 +0100 Subject: [PATCH 11/90] test: add adapter models --- .../flutter_blue_plus_platform_interface.dart | 3 + .../test/bm_bluetooth_adapter_state_test.dart | 57 +++++++++++++++++++ .../test/bm_turn_on_response_test.dart | 26 +++++++++ .../test/guid_test.dart | 4 +- 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index b4e9dad8..12ae90d8 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -1,3 +1,6 @@ +export 'src/adapter/enums/bm_adapter_state_enum.dart'; +export 'src/adapter/models/bm_bluetooth_adapter_state.dart'; +export 'src/adapter/models/bm_turn_on_response.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart new file mode 100644 index 00000000..eeca9a52 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart @@ -0,0 +1,57 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBluetoothAdapterState', + () { + group( + 'fromMap', + () { + test( + 'deserializes the adapter state property', + () { + expect( + BmBluetoothAdapterState.fromMap({ + 'adapter_state': 0, + }).adapterState, + equals(BmAdapterStateEnum.unknown), + ); + }, + ); + + test( + 'throws a range error if the adapter state property index is out of range', + () { + expect( + () { + BmBluetoothAdapterState.fromMap({ + 'adapter_state': 7, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the adapter state property', + () { + expect( + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ).toMap(), + containsPair('adapter_state', 0), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart new file mode 100644 index 00000000..718ed80f --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart @@ -0,0 +1,26 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmTurnOnResponse', + () { + group( + 'fromMap', + () { + test( + 'initializes the user accepted property as false if the user accepted property is null', + () { + expect( + BmTurnOnResponse.fromMap({ + 'user_accepted': null, + }).userAccepted, + isFalse, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart index 7c2708fa..14af0716 100644 --- a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart @@ -89,7 +89,7 @@ void main() { ); test( - 'throws an exception if the list is not 2 nor 4 nor 16 bytes in length', + 'throws a format exception if the list is not 2 nor 4 nor 16 bytes in length', () { expect( () { @@ -192,7 +192,7 @@ void main() { ); test( - 'throws an exception if the string is not 2 nor 4 nor 16 bytes in length', + 'throws a format exception if the string is not 2 nor 4 nor 16 bytes in length', () { expect( () { From 52ada10f2c164d715dc771c19d99fafc30d3b8e1 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 14:45:51 +0100 Subject: [PATCH 12/90] test: add characteristic models --- .../flutter_blue_plus_platform_interface.dart | 7 + .../models/bm_bluetooth_characteristic.dart | 2 +- .../models/bm_characteristic_data.dart | 8 +- .../bm_bluetooth_characteristic_test.dart | 72 +++++ .../test/bm_characteristic_data_test.dart | 147 ++++++++++ .../bm_characteristic_properties_test.dart | 255 ++++++++++++++++++ .../bm_read_characteristic_request_test.dart | 47 ++++ .../bm_set_notify_value_request_test.dart | 51 ++++ .../test/bm_turn_on_response_test.dart | 14 +- .../bm_write_characteristic_request_test.dart | 146 ++++++++++ 10 files changed, 744 insertions(+), 5 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 12ae90d8..39302ccf 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -1,6 +1,13 @@ export 'src/adapter/enums/bm_adapter_state_enum.dart'; export 'src/adapter/models/bm_bluetooth_adapter_state.dart'; export 'src/adapter/models/bm_turn_on_response.dart'; +export 'src/characteristic/enums/bm_write_type.dart'; +export 'src/characteristic/models/bm_bluetooth_characteristic.dart'; +export 'src/characteristic/models/bm_characteristic_data.dart'; +export 'src/characteristic/models/bm_characteristic_properties.dart'; +export 'src/characteristic/models/bm_read_characteristic_request.dart'; +export 'src/characteristic/models/bm_set_notify_value_request.dart'; +export 'src/characteristic/models/bm_write_characteristic_request.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart index a1cbb6e5..1fec7092 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart @@ -14,7 +14,7 @@ class BmBluetoothCharacteristic { BmBluetoothCharacteristic({ required this.remoteId, required this.serviceUuid, - required this.secondaryServiceUuid, + this.secondaryServiceUuid, required this.characteristicUuid, required this.descriptors, required this.properties, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart index 2b887108..3e2a97e4 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart @@ -27,6 +27,8 @@ class BmCharacteristicData { factory BmCharacteristicData.fromMap( Map json, ) { + final success = json['success'] == null || json['success'] != 0; + return BmCharacteristicData( remoteId: DeviceIdentifier(json['remote_id']), serviceUuid: Guid(json['service_uuid']), @@ -35,9 +37,9 @@ class BmCharacteristicData { : null, characteristicUuid: Guid(json['characteristic_uuid']), value: json['value'] != null ? hex.decode(json['value']) : [], - success: json['success'] != 0, - errorCode: json['error_code'], - errorString: json['error_string'], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', ); } diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart new file mode 100644 index 00000000..3092b3b8 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart @@ -0,0 +1,72 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBluetoothCharacteristic', + () { + group( + 'fromMap', + () { + test( + 'deserializes the properties property properties as false if it is null', + () { + final properties = BmBluetoothCharacteristic.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'properties': null, + }).properties; + + expect(properties.broadcast, isFalse); + expect(properties.read, isFalse); + expect(properties.writeWithoutResponse, isFalse); + expect(properties.write, isFalse); + expect(properties.notify, isFalse); + expect(properties.indicate, isFalse); + expect(properties.authenticatedSignedWrites, isFalse); + expect(properties.extendedProperties, isFalse); + expect(properties.notifyEncryptionRequired, isFalse); + expect(properties.indicateEncryptionRequired, isFalse); + }, + ); + + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'properties': {}, + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'properties': {}, + }).secondaryServiceUuid, + isNull, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart new file mode 100644 index 00000000..36c255e7 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -0,0 +1,147 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmCharacteristicData', + () { + group( + 'fromMap', + () { + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'value': '', + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'value': '', + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the value property as [0x01,0x02] if it is 0102', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'value': '0102', + }).value, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the value property as [] if it is null', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'value': null, + }).value, + orderedEquals([]), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart new file mode 100644 index 00000000..4ede2c27 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart @@ -0,0 +1,255 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmCharacteristicProperties', + () { + group( + 'fromMap', + () { + test( + 'deserializes the properties as false if they are not 1', + () { + final properties = BmCharacteristicProperties.fromMap({ + 'broadcast': 0, + 'read': 0, + 'write_without_response': 0, + 'write': 0, + 'notify': 0, + 'indicate': 0, + 'authenticated_signed_writes': 0, + 'extended_properties': 0, + 'notify_encryption_required': 0, + 'indicate_encryption_required': 0, + }); + + expect( + properties.broadcast, + isFalse, + ); + expect( + properties.read, + isFalse, + ); + expect( + properties.writeWithoutResponse, + isFalse, + ); + expect( + properties.write, + isFalse, + ); + expect( + properties.notify, + isFalse, + ); + expect( + properties.indicate, + isFalse, + ); + expect( + properties.authenticatedSignedWrites, + isFalse, + ); + expect( + properties.extendedProperties, + isFalse, + ); + expect( + properties.notifyEncryptionRequired, + isFalse, + ); + expect( + properties.indicateEncryptionRequired, + isFalse, + ); + }, + ); + + test( + 'deserializes the properties as true if they are 1', + () { + final properties = BmCharacteristicProperties.fromMap({ + 'broadcast': 1, + 'read': 1, + 'write_without_response': 1, + 'write': 1, + 'notify': 1, + 'indicate': 1, + 'authenticated_signed_writes': 1, + 'extended_properties': 1, + 'notify_encryption_required': 1, + 'indicate_encryption_required': 1, + }); + + expect( + properties.broadcast, + isTrue, + ); + expect( + properties.read, + isTrue, + ); + expect( + properties.writeWithoutResponse, + isTrue, + ); + expect( + properties.write, + isTrue, + ); + expect( + properties.notify, + isTrue, + ); + expect( + properties.indicate, + isTrue, + ); + expect( + properties.authenticatedSignedWrites, + isTrue, + ); + expect( + properties.extendedProperties, + isTrue, + ); + expect( + properties.notifyEncryptionRequired, + isTrue, + ); + expect( + properties.indicateEncryptionRequired, + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the properties as 0 if they are false', + () { + final map = BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ).toMap(); + + expect( + map, + containsPair('broadcast', equals(0)), + ); + expect( + map, + containsPair('read', equals(0)), + ); + expect( + map, + containsPair('write_without_response', equals(0)), + ); + expect( + map, + containsPair('write', equals(0)), + ); + expect( + map, + containsPair('notify', equals(0)), + ); + expect( + map, + containsPair('indicate', equals(0)), + ); + expect( + map, + containsPair('authenticated_signed_writes', equals(0)), + ); + expect( + map, + containsPair('extended_properties', equals(0)), + ); + expect( + map, + containsPair('notify_encryption_required', equals(0)), + ); + expect( + map, + containsPair('indicate_encryption_required', equals(0)), + ); + }, + ); + + test( + 'serializes the properties as 1 if they are true', + () { + final map = BmCharacteristicProperties( + broadcast: true, + read: true, + writeWithoutResponse: true, + write: true, + notify: true, + indicate: true, + authenticatedSignedWrites: true, + extendedProperties: true, + notifyEncryptionRequired: true, + indicateEncryptionRequired: true, + ).toMap(); + + expect( + map, + containsPair('broadcast', equals(1)), + ); + expect( + map, + containsPair('read', equals(1)), + ); + expect( + map, + containsPair('write_without_response', equals(1)), + ); + expect( + map, + containsPair('write', equals(1)), + ); + expect( + map, + containsPair('notify', equals(1)), + ); + expect( + map, + containsPair('indicate', equals(1)), + ); + expect( + map, + containsPair('authenticated_signed_writes', equals(1)), + ); + expect( + map, + containsPair('extended_properties', equals(1)), + ); + expect( + map, + containsPair('notify_encryption_required', equals(1)), + ); + expect( + map, + containsPair('indicate_encryption_required', equals(1)), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart new file mode 100644 index 00000000..f3f06fb6 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart @@ -0,0 +1,47 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmReadCharacteristicRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmReadCharacteristicRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmReadCharacteristicRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart new file mode 100644 index 00000000..2dcb0ae7 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart @@ -0,0 +1,51 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmSetNotifyValueRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).secondaryServiceUuid, + isNull, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart index 718ed80f..1a7065bb 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart @@ -9,7 +9,7 @@ void main() { 'fromMap', () { test( - 'initializes the user accepted property as false if the user accepted property is null', + 'deserializes the user accepted property as false if the user accepted property is null', () { expect( BmTurnOnResponse.fromMap({ @@ -19,6 +19,18 @@ void main() { ); }, ); + + test( + 'deserializes the user accepted property as true if the user accepted property is true', + () { + expect( + BmTurnOnResponse.fromMap({ + 'user_accepted': true, + }).userAccepted, + isTrue, + ); + }, + ); }, ); }, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart new file mode 100644 index 00000000..eafa787d --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart @@ -0,0 +1,146 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmWriteCharacteristicRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 0, + 'value': '', + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'write_type': 0, + 'value': '', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the value property as [0x01,0x02] if it is 0102', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 0, + 'value': '0102', + }).value, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the value property as [] if it is null', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'write_type': 0, + 'value': null, + }).value, + orderedEquals([]), + ); + }, + ); + + test( + 'deserializes the write type property', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'write_type': 0, + 'value': null, + }).writeType, + equals(BmWriteType.withResponse), + ); + }, + ); + + test( + 'throws a range error if the write type property index is out of range', + () { + expect( + () { + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'write_type': 2, + 'value': null, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the write type property', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair('write_type', 0), + ); + }, + ); + }, + ); + }, + ); +} From 2c4f92a3b2eb16293c6eab7fecdfc833e78a67b1 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 14:52:24 +0100 Subject: [PATCH 13/90] test: add descriptor models --- .../flutter_blue_plus_platform_interface.dart | 4 + .../test/bm_characteristic_data_test.dart | 6 + .../test/bm_descriptor_data_test.dart | 160 ++++++++++++++++++ .../test/bm_read_descriptor_request_test.dart | 49 ++++++ .../bm_write_descriptor_request_test.dart | 88 ++++++++++ 5 files changed, 307 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 39302ccf..2d98f842 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -10,4 +10,8 @@ export 'src/characteristic/models/bm_set_notify_value_request.dart'; export 'src/characteristic/models/bm_write_characteristic_request.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; +export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; +export 'src/descriptor/models/bm_descriptor_data.dart'; +export 'src/descriptor/models/bm_read_descriptor_request.dart'; +export 'src/descriptor/models/bm_write_descriptor_request.dart'; export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart index 36c255e7..818c056e 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -116,6 +116,9 @@ void main() { 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'value': '0102', + 'success': 1, + 'error_code': 0, + 'error_string': '', }).value, orderedEquals([ 0x01, @@ -135,6 +138,9 @@ void main() { 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': null, + 'success': 1, + 'error_code': 0, + 'error_string': '', }).value, orderedEquals([]), ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart new file mode 100644 index 00000000..fffab80d --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart @@ -0,0 +1,160 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmCharacteristicData', + () { + group( + 'fromMap', + () { + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the value property as [0x01,0x02] if it is 0102', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '0102', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).value, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the value property as [] if it is null', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': null, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).value, + orderedEquals([]), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart new file mode 100644 index 00000000..1d600b87 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart @@ -0,0 +1,49 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmReadDescriptorRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart new file mode 100644 index 00000000..5b8fac03 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart @@ -0,0 +1,88 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmWriteDescriptorRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the value property as [0x01,0x02] if it is 0102', + () { + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '0102', + }).value, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the value property as [] if it is null', + () { + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': null, + }).value, + orderedEquals([]), + ); + }, + ); + }, + ); + }, + ); +} From 2085e10c3cdafd84c8cca301f877c1e861547d50 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 15:38:59 +0100 Subject: [PATCH 14/90] test: add scan models --- .../flutter_blue_plus_platform_interface.dart | 5 + .../scan/models/bm_scan_advertisement.dart | 8 +- .../lib/src/scan/models/bm_scan_settings.dart | 8 +- .../models/bm_discover_services_result.dart | 4 +- .../test/bm_characteristic_data_test.dart | 7 +- .../test/bm_descriptor_data_test.dart | 7 +- .../test/bm_msd_filter_test.dart | 78 ++++++++++ .../test/bm_scan_advertisement_test.dart | 132 ++++++++++++++++ .../test/bm_scan_response_test.dart | 74 +++++++++ .../test/bm_scan_settings_test.dart | 146 ++++++++++++++++++ .../test/bm_service_data_filter_test.dart | 78 ++++++++++ .../bm_write_characteristic_request_test.dart | 7 +- .../bm_write_descriptor_request_test.dart | 7 +- 13 files changed, 540 insertions(+), 21 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 2d98f842..3ba94ab5 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -15,3 +15,8 @@ export 'src/descriptor/models/bm_descriptor_data.dart'; export 'src/descriptor/models/bm_read_descriptor_request.dart'; export 'src/descriptor/models/bm_write_descriptor_request.dart'; export 'src/flutter_blue_plus_platform.dart'; +export 'src/scan/models/bm_msd_filter.dart'; +export 'src/scan/models/bm_scan_advertisement.dart'; +export 'src/scan/models/bm_scan_response.dart'; +export 'src/scan/models/bm_scan_settings.dart'; +export 'src/scan/models/bm_service_data_filter.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart index 21a2af2d..5d0e3d89 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart @@ -17,11 +17,11 @@ class BmScanAdvertisement { BmScanAdvertisement({ required this.remoteId, - required this.platformName, - required this.advName, + this.platformName, + this.advName, required this.connectable, - required this.txPowerLevel, - required this.appearance, + this.txPowerLevel, + this.appearance, required this.manufacturerData, required this.serviceData, required this.serviceUuids, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart index a8d2cc4b..0f18f305 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart @@ -37,9 +37,11 @@ class BmScanSettings { ?.map((str) => Guid(str)) .toList() ?? [], - withRemoteIds: json['with_remote_ids'], - withNames: json['with_names'], - withKeywords: json['with_keywords'], + withRemoteIds: + (json['with_remote_ids'] as List?)?.cast() ?? [], + withNames: (json['with_names'] as List?)?.cast() ?? [], + withKeywords: + (json['with_keywords'] as List?)?.cast() ?? [], withMsd: (json['with_msd'] as List?) ?.map((manufacturerData) => BmMsdFilter.fromMap(manufacturerData)) .toList() ?? diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart index f4bf85be..5979e00c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart @@ -24,8 +24,8 @@ class BmDiscoverServicesResult { return BmDiscoverServicesResult( remoteId: DeviceIdentifier(json['remote_id']), services: (json['services'] as List?) - ?.map( - (e) => BmBluetoothService.fromMap(e as Map)) + ?.map((service) => + BmBluetoothService.fromMap(service as Map)) .toList() ?? [], success: success, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart index 818c056e..97da4cf2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -107,7 +107,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02] if it is 0102', + 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', () { expect( BmCharacteristicData.fromMap({ @@ -115,7 +115,7 @@ void main() { 'service_uuid': '0102', 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', - 'value': '0102', + 'value': '010203', 'success': 1, 'error_code': 0, 'error_string': '', @@ -123,6 +123,7 @@ void main() { orderedEquals([ 0x01, 0x02, + 0x03, ]), ); }, @@ -142,7 +143,7 @@ void main() { 'error_code': 0, 'error_string': '', }).value, - orderedEquals([]), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart index fffab80d..e069df29 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart @@ -112,7 +112,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02] if it is 0102', + 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', () { expect( BmDescriptorData.fromMap({ @@ -121,7 +121,7 @@ void main() { 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - 'value': '0102', + 'value': '010203', 'success': 1, 'error_code': 0, 'error_string': '', @@ -129,6 +129,7 @@ void main() { orderedEquals([ 0x01, 0x02, + 0x03, ]), ); }, @@ -149,7 +150,7 @@ void main() { 'error_code': 0, 'error_string': '', }).value, - orderedEquals([]), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart new file mode 100644 index 00000000..66fbd1f9 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart @@ -0,0 +1,78 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmMsdFilter', + () { + group( + 'fromMap', + () { + test( + 'deserializes the data property as null if it is null', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': null, + 'mask': null, + }).data, + isNull, + ); + }, + ); + + test( + 'deserializes the data property as [0x01,0x02,0x03] if it is 010203', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': '010203', + 'mask': null, + }).data, + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + + test( + 'deserializes the mask property as null if it is null', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': null, + 'mask': null, + }).mask, + isNull, + ); + }, + ); + + test( + 'deserializes the mask property as [0x01,0x02,0x03] if it is 010203', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': null, + 'mask': '010203', + }).mask, + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart new file mode 100644 index 00000000..2a55567b --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart @@ -0,0 +1,132 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmScanAdvertisement', + () { + group( + 'fromMap', + () { + test( + 'deserializes the manufacturer data property', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': '', + 'connectable': 1, + 'manufacturer_data': { + 1: '010203', + }, + 'service_data': {}, + 'service_uuids': [], + }).manufacturerData, + containsPair( + 1, + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), + ), + ); + }, + ); + + test( + 'deserializes the manufacturer data property as {} if it is null', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': '', + 'connectable': 1, + 'manufacturer_data': null, + 'service_data': {}, + 'service_uuids': [], + }).manufacturerData, + isEmpty, + ); + }, + ); + + test( + 'deserializes the service data property', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': '', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': { + '0102': '010203', + }, + 'service_uuids': [], + }).serviceData, + containsPair( + Guid('0102'), + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), + ), + ); + }, + ); + + test( + 'deserializes the service data property as {} if it is null', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': '', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': null, + 'service_uuids': [], + }).serviceData, + isEmpty, + ); + }, + ); + + test( + 'deserializes the service uuids property', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': '', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [ + '0102', + ], + }).serviceUuids, + orderedEquals([ + Guid('0102'), + ]), + ); + }, + ); + + test( + 'deserializes the service uuids property as [] if it is null', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': '', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': null, + }).serviceUuids, + isEmpty, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart new file mode 100644 index 00000000..8636986b --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart @@ -0,0 +1,74 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmScanResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the advertisements property as [] if it is null', + () { + expect( + BmScanResponse.fromMap({ + 'advertisements': null, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).advertisements, + isEmpty, + ); + }, + ); + + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmScanResponse.fromMap({ + 'advertisements': [], + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmScanResponse.fromMap({ + 'advertisements': [], + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmScanResponse.fromMap({ + 'advertisements': [], + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart new file mode 100644 index 00000000..c89ab2fe --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart @@ -0,0 +1,146 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmScanSettings', + () { + group( + 'fromMap', + () { + test( + 'deserializes the with services property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': null, + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 0, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServices, + isEmpty, + ); + }, + ); + + test( + 'deserializes the with remote ids property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': null, + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 0, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withRemoteIds, + isEmpty, + ); + }, + ); + + test( + 'deserializes the with names property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': null, + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 0, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withNames, + isEmpty, + ); + }, + ); + + test( + 'deserializes the with keywords property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': null, + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 0, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withKeywords, + isEmpty, + ); + }, + ); + + test( + 'deserializes the with msd property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': null, + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 0, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withMsd, + isEmpty, + ); + }, + ); + + test( + 'deserializes the with service data property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': null, + 'continuous_updates': false, + 'continuous_divisor': 0, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServiceData, + isEmpty, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart new file mode 100644 index 00000000..d64f6261 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart @@ -0,0 +1,78 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmServiceDataFilter', + () { + group( + 'fromMap', + () { + test( + 'deserializes the data property as [] if it is null', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': null, + 'mask': null, + }).data, + isEmpty, + ); + }, + ); + + test( + 'deserializes the data property as [0x01,0x02,0x03] if it is 010203', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': '010203', + 'mask': null, + }).data, + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + + test( + 'deserializes the mask property as [] if it is null', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': null, + 'mask': null, + }).mask, + isEmpty, + ); + }, + ); + + test( + 'deserializes the mask property as [0x01,0x02,0x03] if it is 010203', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': null, + 'mask': '010203', + }).mask, + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart index eafa787d..522dece4 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart @@ -46,7 +46,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02] if it is 0102', + 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', () { expect( BmWriteCharacteristicRequest.fromMap({ @@ -55,11 +55,12 @@ void main() { 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'write_type': 0, - 'value': '0102', + 'value': '010203', }).value, orderedEquals([ 0x01, 0x02, + 0x03, ]), ); }, @@ -77,7 +78,7 @@ void main() { 'write_type': 0, 'value': null, }).value, - orderedEquals([]), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart index 5b8fac03..2b8726fc 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart @@ -46,7 +46,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02] if it is 0102', + 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', () { expect( BmWriteDescriptorRequest.fromMap({ @@ -55,11 +55,12 @@ void main() { 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - 'value': '0102', + 'value': '010203', }).value, orderedEquals([ 0x01, 0x02, + 0x03, ]), ); }, @@ -77,7 +78,7 @@ void main() { 'descriptor_uuid': '0102', 'value': null, }).value, - orderedEquals([]), + isEmpty, ); }, ); From d8b40d25fcbd9d6aa8c94fa924b2ddc4b066a85d Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 16:04:09 +0100 Subject: [PATCH 15/90] test: add service models --- .../flutter_blue_plus_platform_interface.dart | 2 + .../service/models/bm_bluetooth_service.dart | 2 +- .../test/bm_bluetooth_service_test.dart | 46 +++++++++++ .../test/bm_characteristic_data_test.dart | 2 +- .../test/bm_descriptor_data_test.dart | 2 +- .../bm_discover_services_result_test.dart | 78 +++++++++++++++++++ .../test/bm_msd_filter_test.dart | 4 +- .../test/bm_service_data_filter_test.dart | 4 +- .../bm_write_characteristic_request_test.dart | 2 +- .../bm_write_descriptor_request_test.dart | 2 +- 10 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 3ba94ab5..9c51b49d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -20,3 +20,5 @@ export 'src/scan/models/bm_scan_advertisement.dart'; export 'src/scan/models/bm_scan_response.dart'; export 'src/scan/models/bm_scan_settings.dart'; export 'src/scan/models/bm_service_data_filter.dart'; +export 'src/service/models/bm_bluetooth_service.dart'; +export 'src/service/models/bm_discover_services_result.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart index bffa8440..29aa7214 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart @@ -21,8 +21,8 @@ class BmBluetoothService { Map json, ) { return BmBluetoothService( - serviceUuid: Guid(json['service_uuid']), remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), isPrimary: json['is_primary'] == 1, characteristics: (json['characteristics'] as List?) ?.map((characteristic) => diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart new file mode 100644 index 00000000..6f1da7da --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart @@ -0,0 +1,46 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBluetoothService', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristics property as [] if it is null', + () { + expect( + BmBluetoothService.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': null, + 'included_services': [], + }).characteristics, + isEmpty, + ); + }, + ); + + test( + 'deserializes the included services property as [] if it is null', + () { + expect( + BmBluetoothService.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': null, + }).includedServices, + isEmpty, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart index 97da4cf2..eadc64fe 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -107,7 +107,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the value property', () { expect( BmCharacteristicData.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart index e069df29..183f5a2f 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart @@ -112,7 +112,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the value property', () { expect( BmDescriptorData.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart new file mode 100644 index 00000000..7cf5894f --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart @@ -0,0 +1,78 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmDiscoverServicesResult', + () { + group( + 'fromMap', + () { + test( + 'deserializes the services property as [] if it is null', + () { + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': '', + 'services': null, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).services, + isEmpty, + ); + }, + ); + + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': '', + 'services': [], + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': '', + 'services': [], + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': '', + 'services': [], + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart index 66fbd1f9..de385abc 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart @@ -23,7 +23,7 @@ void main() { ); test( - 'deserializes the data property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the data property', () { expect( BmMsdFilter.fromMap({ @@ -55,7 +55,7 @@ void main() { ); test( - 'deserializes the mask property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the mask property', () { expect( BmMsdFilter.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart index d64f6261..1eac1ef9 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart @@ -23,7 +23,7 @@ void main() { ); test( - 'deserializes the data property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the data property', () { expect( BmServiceDataFilter.fromMap({ @@ -55,7 +55,7 @@ void main() { ); test( - 'deserializes the mask property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the mask property', () { expect( BmServiceDataFilter.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart index 522dece4..417274e2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart @@ -46,7 +46,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the value property', () { expect( BmWriteCharacteristicRequest.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart index 2b8726fc..d398ab6d 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart @@ -46,7 +46,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the value property', () { expect( BmWriteDescriptorRequest.fromMap({ From 1f2dd10d8e097e0b309dc303fe431a1e6fadc0c5 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 16:24:19 +0100 Subject: [PATCH 16/90] test: add device models --- .../flutter_blue_plus_platform_interface.dart | 14 +++ .../device/models/bm_bluetooth_device.dart | 2 +- .../test/bm_bond_state_response_test.dart | 104 ++++++++++++++++++ .../bm_connection_priority_request_test.dart | 60 ++++++++++ .../bm_connection_state_response_test.dart | 60 ++++++++++ .../test/bm_devices_list_test.dart | 26 +++++ .../test/bm_mtu_changed_response_test.dart | 62 +++++++++++ .../test/bm_read_rssi_result_test.dart | 62 +++++++++++ 8 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 9c51b49d..0c92b73d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -14,6 +14,20 @@ export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; export 'src/descriptor/models/bm_descriptor_data.dart'; export 'src/descriptor/models/bm_read_descriptor_request.dart'; export 'src/descriptor/models/bm_write_descriptor_request.dart'; +export 'src/device/enums/bm_bond_state_enum.dart'; +export 'src/device/enums/bm_connection_priority_enum.dart'; +export 'src/device/enums/bm_connection_state_enum.dart'; +export 'src/device/models/bm_bluetooth_device.dart'; +export 'src/device/models/bm_bond_state_response.dart'; +export 'src/device/models/bm_connect_request.dart'; +export 'src/device/models/bm_connection_priority_request.dart'; +export 'src/device/models/bm_connection_state_response.dart'; +export 'src/device/models/bm_devices_list.dart'; +export 'src/device/models/bm_mtu_change_request.dart'; +export 'src/device/models/bm_mtu_changed_response.dart'; +export 'src/device/models/bm_name_changed.dart'; +export 'src/device/models/bm_preferred_phy.dart'; +export 'src/device/models/bm_read_rssi_result.dart'; export 'src/flutter_blue_plus_platform.dart'; export 'src/scan/models/bm_msd_filter.dart'; export 'src/scan/models/bm_scan_advertisement.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart index dd2bb684..73ccb88b 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart @@ -6,7 +6,7 @@ class BmBluetoothDevice { BmBluetoothDevice({ required this.remoteId, - required this.platformName, + this.platformName, }); factory BmBluetoothDevice.fromMap( diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart new file mode 100644 index 00000000..e03e9c5a --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart @@ -0,0 +1,104 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBondStateResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the bond state property', + () { + expect( + BmBondStateResponse.fromMap({ + 'remote_id': '', + 'bond_state': 0, + }).bondState, + equals(BmBondStateEnum.none), + ); + }, + ); + + test( + 'deserializes the prev state property', + () { + expect( + BmBondStateResponse.fromMap({ + 'remote_id': '', + 'bond_state': 0, + 'prev_state': 0, + }).prevState, + equals(BmBondStateEnum.none), + ); + }, + ); + + test( + 'throws a range error if the bond state property index is out of range', + () { + expect( + () { + BmBondStateResponse.fromMap({ + 'remote_id': '', + 'bond_state': 3, + }); + }, + throwsRangeError, + ); + }, + ); + + test( + 'throws a range error if the prev state property index is out of range', + () { + expect( + () { + BmBondStateResponse.fromMap({ + 'remote_id': '', + 'bond_state': 0, + 'prev_state': 3, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the bond state property', + () { + expect( + BmBondStateResponse( + remoteId: DeviceIdentifier(''), + bondState: BmBondStateEnum.none, + ).toMap(), + containsPair('bond_state', 0), + ); + }, + ); + + test( + 'serializes the prev state property', + () { + expect( + BmBondStateResponse( + remoteId: DeviceIdentifier(''), + bondState: BmBondStateEnum.none, + prevState: BmBondStateEnum.none, + ).toMap(), + containsPair('prev_state', 0), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart new file mode 100644 index 00000000..03ed371f --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart @@ -0,0 +1,60 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmConnectionPriorityRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the connection priority property', + () { + expect( + BmConnectionPriorityRequest.fromMap({ + 'remote_id': '', + 'connection_priority': 0, + }).connectionPriority, + equals(BmConnectionPriorityEnum.balanced), + ); + }, + ); + + test( + 'throws a range error if the connection priority property index is out of range', + () { + expect( + () { + BmConnectionPriorityRequest.fromMap({ + 'remote_id': '', + 'connection_priority': 3, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the connection priority property', + () { + expect( + BmConnectionPriorityRequest( + remoteId: DeviceIdentifier(''), + connectionPriority: BmConnectionPriorityEnum.balanced, + ).toMap(), + containsPair('connection_priority', 0), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart new file mode 100644 index 00000000..c9425121 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart @@ -0,0 +1,60 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmConnectionStateResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the connection state property', + () { + expect( + BmConnectionStateResponse.fromMap({ + 'remote_id': '', + 'connection_state': 0, + }).connectionState, + equals(BmConnectionStateEnum.disconnected), + ); + }, + ); + + test( + 'throws a range error if the connection state property index is out of range', + () { + expect( + () { + BmConnectionStateResponse.fromMap({ + 'remote_id': '', + 'connection_state': 2, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the connection state property', + () { + expect( + BmConnectionStateResponse( + remoteId: DeviceIdentifier(''), + connectionState: BmConnectionStateEnum.disconnected, + ).toMap(), + containsPair('connection_state', 0), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart new file mode 100644 index 00000000..e1edfa34 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart @@ -0,0 +1,26 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmDevicesList', + () { + group( + 'fromMap', + () { + test( + 'deserializes the devices property as [] if it is null', + () { + expect( + BmDevicesList.fromMap({ + 'devices': null, + }).devices, + isEmpty, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart new file mode 100644 index 00000000..4b92659e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart @@ -0,0 +1,62 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmMtuChangedResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmMtuChangedResponse.fromMap({ + 'remote_id': '', + 'mtu': 0, + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmMtuChangedResponse.fromMap({ + 'remote_id': '', + 'mtu': 0, + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmMtuChangedResponse.fromMap({ + 'remote_id': '', + 'mtu': 0, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart new file mode 100644 index 00000000..851a4c10 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart @@ -0,0 +1,62 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmReadRssiResult', + () { + group( + 'fromMap', + () { + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmReadRssiResult.fromMap({ + 'remote_id': '', + 'rssi': 0, + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmReadRssiResult.fromMap({ + 'remote_id': '', + 'rssi': 0, + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmReadRssiResult.fromMap({ + 'remote_id': '', + 'rssi': 0, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + }, + ); + }, + ); +} From 8fddb267cc8ba8936c96d108f5ffee6407ad671d Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 17:40:49 +0100 Subject: [PATCH 17/90] refactor: add method channel methods --- .../flutter_blue_plus_platform_interface.dart | 1 + .../lib/src/common/models/phy_support.dart | 28 ++ .../lib/src/flutter_blue_plus_platform.dart | 242 ++++++++++++++++++ .../test/bm_scan_settings_test.dart | 12 +- 4 files changed, 277 insertions(+), 6 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 0c92b73d..34e51c9a 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -10,6 +10,7 @@ export 'src/characteristic/models/bm_set_notify_value_request.dart'; export 'src/characteristic/models/bm_write_characteristic_request.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; +export 'src/common/models/phy_support.dart'; export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; export 'src/descriptor/models/bm_descriptor_data.dart'; export 'src/descriptor/models/bm_read_descriptor_request.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart new file mode 100644 index 00000000..dc779840 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart @@ -0,0 +1,28 @@ +class PhySupport { + /// High speed (PHY 2M) + final bool le2M; + + /// Long range (PHY codec) + final bool leCoded; + + PhySupport({ + required this.le2M, + required this.leCoded, + }); + + factory PhySupport.fromMap( + Map json, + ) { + return PhySupport( + le2M: json['le_2M'], + leCoded: json['le_coded'], + ); + } + + Map toMap() { + return { + 'le_2M': le2M, + 'le_coded': leCoded, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index 73e2b21c..e95d8317 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -1,6 +1,20 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; +import 'adapter/models/bm_bluetooth_adapter_state.dart'; +import 'characteristic/models/bm_read_characteristic_request.dart'; +import 'characteristic/models/bm_set_notify_value_request.dart'; +import 'characteristic/models/bm_write_characteristic_request.dart'; +import 'common/models/phy_support.dart'; +import 'descriptor/models/bm_read_descriptor_request.dart'; +import 'descriptor/models/bm_write_descriptor_request.dart'; +import 'device/models/bm_bond_state_response.dart'; +import 'device/models/bm_connect_request.dart'; +import 'device/models/bm_connection_priority_request.dart'; +import 'device/models/bm_devices_list.dart'; +import 'device/models/bm_mtu_change_request.dart'; +import 'device/models/bm_preferred_phy.dart'; import 'method_channel_flutter_blue_plus.dart'; +import 'scan/models/bm_scan_settings.dart'; /// The interface that implementations of flutter_blue_plus must implement. abstract class FlutterBluePlusPlatform extends PlatformInterface { @@ -21,4 +35,232 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { PlatformInterface.verify(instance, _token); _instance = instance; } + + /// Clears the GATT cache for a [remoteId]. + Future clearGattCache( + String remoteId, + ) { + throw UnimplementedError(); + } + + /// Connects to the device for a [request]. + /// + /// Returns [true] if the connection state is changed. + /// + /// Implementations should call [OnConnectionStateChanged] with the changed connection state. + Future connect( + BmConnectRequest request, + ) { + throw UnimplementedError(); + } + + /// Returns the number of connected devices. + Future connectedCount() { + throw UnimplementedError(); + } + + /// Creates a bond to a [remoteId]. + /// + /// Returns [true] if the bond state is changed. + /// + /// Implementations should call [OnBondStateChanged] with the changed bond state. + Future createBond( + String remoteId, + ) { + throw UnimplementedError(); + } + + /// Disconnects from a [remoteId]. + /// + /// Returns [true] if the connection state is changed. + /// + /// Implementations should call [OnConnectionStateChanged] with the changed connection state. + Future disconnect( + String remoteId, + ) { + throw UnimplementedError(); + } + + /// Discovers the services for a [remoteId]. + /// + /// Implementations should call [OnDiscoveredServices] with the discovered services. + Future discoverServices( + String remoteId, + ) { + throw UnimplementedError(); + } + + /// Returns the number of remaining connected devices after restarting Flutter. + Future flutterRestart() { + throw UnimplementedError(); + } + + /// Returns the adapter name. + Future getAdapterName() { + throw UnimplementedError(); + } + + /// Returns the adapter state. + Future getAdapterState() { + throw UnimplementedError(); + } + + /// Returns the bond state for a [remoteId]. + Future getBondState( + String remoteId, + ) { + throw UnimplementedError(); + } + + /// Returns the bonded devices. + Future getBondedDevices() { + throw UnimplementedError(); + } + + /// Returns the Physical Layer (PHY) support. + Future getPhySupport() { + throw UnimplementedError(); + } + + /// Returns the system devices. + Future getSystemDevices() { + throw UnimplementedError(); + } + + /// Returns [true] if Bluetooth is supported on the hardware. + Future isSupported() { + throw UnimplementedError(); + } + + /// Reads the characteristic for a [request]. + /// + /// Implementations should call [OnCharacteristicReceived] with the read characteristic. + Future readCharacteristic( + BmReadCharacteristicRequest request, + ) { + throw UnimplementedError(); + } + + /// Reads the descriptor for a [request]. + /// + /// Implementations should call [OnDescriptorRead] with the read descriptor. + Future readDescriptor( + BmReadDescriptorRequest request, + ) { + throw UnimplementedError(); + } + + /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. + /// + /// Implementations should call [OnReadRssi] with the read RSSI. + Future readRssi( + String remoteId, + ) { + throw UnimplementedError(); + } + + /// Removes the bond to a [remoteId]. + /// + /// Returns [true] if the bond state is changed. + /// + /// Implementations should call [OnBondStateChanged] with the changed bond state. + Future removeBond( + String remoteId, + ) { + throw UnimplementedError(); + } + + /// Requests a change to the connection priority for a [request]. + Future requestConnectionPriority( + BmConnectionPriorityRequest request, + ) { + throw UnimplementedError(); + } + + /// Requests a change to the Maximum Transmission Unit (MTU) for a [request]. + /// + /// Implementations should call [OnMtuChanged] with the changed MTU. + Future requestMtu( + BmMtuChangeRequest request, + ) { + throw UnimplementedError(); + } + + /// Sets the log level. + Future setLogLevel( + int level, + ) { + throw UnimplementedError(); + } + + /// Sets the notify value for a [request]. + /// + /// Returns [true] if the characteristic has a Client Characteristic Configuration Descriptor (CCCD). + /// + /// Implementations should call [OnDescriptorWritten] with the written CCCD. + Future setNotifyValue( + BmSetNotifyValueRequest request, + ) { + throw UnimplementedError(); + } + + /// Sets the options. + Future setOptions( + Map options, + ) { + throw UnimplementedError(); + } + + /// Sets the preferred Physical Layer (PHY). + Future setPreferredPhy( + BmPreferredPhy preferredPhy, + ) { + throw UnimplementedError(); + } + + /// Starts scanning for devices. + /// + /// Implementations should call [OnScanResponse] for each scanned device. + Future startScan( + BmScanSettings settings, + ) { + throw UnimplementedError(); + } + + /// Stops scanning for devices. + Future stopScan() { + throw UnimplementedError(); + } + + /// Turns off the adapter. + Future turnOff() { + throw UnimplementedError(); + } + + /// Turns on the adapter. + /// + /// Returns [true] if the power state is changed. + /// + /// Implementations should call [OnTurnOnResponse] with the power state. + Future turnOn() { + throw UnimplementedError(); + } + + /// Writes the characteristic for a [request]. + /// + /// Implementations should call [OnCharacteristicWritten] with the written characteristic. + Future writeCharacteristic( + BmWriteCharacteristicRequest request, + ) { + throw UnimplementedError(); + } + + /// Writes the descriptor for a [request]. + /// + /// Implementations should call [OnDescriptorWritten] with the written descriptor. + Future writeDescriptor( + BmWriteDescriptorRequest request, + ) { + throw UnimplementedError(); + } } diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart index c89ab2fe..fbbd6085 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart @@ -20,7 +20,7 @@ void main() { 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 0, + 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -42,7 +42,7 @@ void main() { 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 0, + 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -64,7 +64,7 @@ void main() { 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 0, + 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -86,7 +86,7 @@ void main() { 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 0, + 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -108,7 +108,7 @@ void main() { 'with_msd': null, 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 0, + 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -130,7 +130,7 @@ void main() { 'with_msd': [], 'with_service_data': null, 'continuous_updates': false, - 'continuous_divisor': 0, + 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, From ee9585a66ff31c85b398d45e0bd105a945d58891 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 18:18:20 +0100 Subject: [PATCH 18/90] refactor: update method channel implementation --- .../flutter_blue_plus_platform_interface.dart | 2 + .../lib/src/common/enums/log_level.dart | 8 + .../lib/src/common/models/options.dart | 22 ++ .../lib/src/flutter_blue_plus_platform.dart | 35 +- .../src/method_channel_flutter_blue_plus.dart | 320 +++++++++++++++++- 5 files changed, 370 insertions(+), 17 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 34e51c9a..b011abec 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -8,8 +8,10 @@ export 'src/characteristic/models/bm_characteristic_properties.dart'; export 'src/characteristic/models/bm_read_characteristic_request.dart'; export 'src/characteristic/models/bm_set_notify_value_request.dart'; export 'src/characteristic/models/bm_write_characteristic_request.dart'; +export 'src/common/enums/log_level.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; +export 'src/common/models/options.dart'; export 'src/common/models/phy_support.dart'; export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; export 'src/descriptor/models/bm_descriptor_data.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart new file mode 100644 index 00000000..ae462139 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart @@ -0,0 +1,8 @@ +enum LogLevel { + none, // 0 + error, // 1 + warning, // 2 + info, // 3 + debug, // 4 + verbose, // 5 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart new file mode 100644 index 00000000..fec83483 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart @@ -0,0 +1,22 @@ +class Options { + /// Whether to show the power alert (iOS & macOS only). i.e. CBCentralManagerOptionShowPowerAlertKey + final bool showPowerAlert; + + Options({ + required this.showPowerAlert, + }); + + factory Options.fromMap( + Map json, + ) { + return Options( + showPowerAlert: json['show_power_alert'], + ); + } + + Map toMap() { + return { + 'show_power_alert': showPowerAlert, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index e95d8317..8947143c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -4,6 +4,9 @@ import 'adapter/models/bm_bluetooth_adapter_state.dart'; import 'characteristic/models/bm_read_characteristic_request.dart'; import 'characteristic/models/bm_set_notify_value_request.dart'; import 'characteristic/models/bm_write_characteristic_request.dart'; +import 'common/enums/log_level.dart'; +import 'common/models/device_identifier.dart'; +import 'common/models/options.dart'; import 'common/models/phy_support.dart'; import 'descriptor/models/bm_read_descriptor_request.dart'; import 'descriptor/models/bm_write_descriptor_request.dart'; @@ -36,9 +39,9 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { _instance = instance; } - /// Clears the GATT cache for a [remoteId]. + /// Clears the GATT cache for a [device]. Future clearGattCache( - String remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } @@ -59,33 +62,33 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Creates a bond to a [remoteId]. + /// Creates a bond to a [device]. /// /// Returns [true] if the bond state is changed. /// /// Implementations should call [OnBondStateChanged] with the changed bond state. Future createBond( - String remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } - /// Disconnects from a [remoteId]. + /// Disconnects from a [device]. /// /// Returns [true] if the connection state is changed. /// /// Implementations should call [OnConnectionStateChanged] with the changed connection state. Future disconnect( - String remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } - /// Discovers the services for a [remoteId]. + /// Discovers the services for a [device]. /// /// Implementations should call [OnDiscoveredServices] with the discovered services. Future discoverServices( - String remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } @@ -105,9 +108,9 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Returns the bond state for a [remoteId]. + /// Returns the bond state for a [device]. Future getBondState( - String remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } @@ -150,22 +153,22 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. + /// Reads the Received Signal Strength Indicator (RSSI) for a [device]. /// /// Implementations should call [OnReadRssi] with the read RSSI. Future readRssi( - String remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } - /// Removes the bond to a [remoteId]. + /// Removes the bond to a [device]. /// /// Returns [true] if the bond state is changed. /// /// Implementations should call [OnBondStateChanged] with the changed bond state. Future removeBond( - String remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } @@ -188,7 +191,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Sets the log level. Future setLogLevel( - int level, + LogLevel level, ) { throw UnimplementedError(); } @@ -206,7 +209,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Sets the options. Future setOptions( - Map options, + Options options, ) { throw UnimplementedError(); } diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index a2b8fc02..c734edfd 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -1,4 +1,322 @@ +import 'package:flutter/services.dart'; + +import 'adapter/models/bm_bluetooth_adapter_state.dart'; +import 'characteristic/models/bm_read_characteristic_request.dart'; +import 'characteristic/models/bm_set_notify_value_request.dart'; +import 'characteristic/models/bm_write_characteristic_request.dart'; +import 'common/enums/log_level.dart'; +import 'common/models/device_identifier.dart'; +import 'common/models/options.dart'; +import 'common/models/phy_support.dart'; +import 'descriptor/models/bm_read_descriptor_request.dart'; +import 'descriptor/models/bm_write_descriptor_request.dart'; +import 'device/models/bm_bond_state_response.dart'; +import 'device/models/bm_connect_request.dart'; +import 'device/models/bm_connection_priority_request.dart'; +import 'device/models/bm_devices_list.dart'; +import 'device/models/bm_mtu_change_request.dart'; +import 'device/models/bm_preferred_phy.dart'; import 'flutter_blue_plus_platform.dart'; +import 'scan/models/bm_scan_settings.dart'; + +const _channel = MethodChannel('flutter_blue_plus/methods'); /// An implementation of [FlutterBluePlusPlatform] that uses method channels. -class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform {} +class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { + @override + Future clearGattCache( + DeviceIdentifier device, + ) async { + await _channel.invokeMethod( + 'clearGattCache', + device.str, + ); + } + + @override + Future connect( + BmConnectRequest request, + ) async { + final result = await _channel.invokeMethod( + 'connect', + request.toMap(), + ); + + return result!; + } + + @override + Future connectedCount() async { + final result = await _channel.invokeMethod( + 'connectedCount', + ); + + return result!; + } + + @override + Future createBond( + DeviceIdentifier device, + ) async { + final result = await _channel.invokeMethod( + 'createBond', + device.str, + ); + + return result!; + } + + @override + Future disconnect( + DeviceIdentifier device, + ) async { + final result = await _channel.invokeMethod( + 'disconnect', + device.str, + ); + + return result!; + } + + @override + Future discoverServices( + DeviceIdentifier device, + ) async { + await _channel.invokeMethod( + 'discoverServices', + device.str, + ); + } + + @override + Future flutterRestart() async { + final result = await _channel.invokeMethod( + 'flutterRestart', + ); + + return result!; + } + + @override + Future getAdapterName() async { + final result = await _channel.invokeMethod( + 'getAdapterName', + ); + + return result!; + } + + @override + Future getAdapterState() async { + final result = await _channel.invokeMethod>( + 'getAdapterState', + ); + + return BmBluetoothAdapterState.fromMap(result!); + } + + @override + Future getBondState( + DeviceIdentifier device, + ) async { + final result = await _channel.invokeMethod>( + 'getBondState', + device.str, + ); + + return BmBondStateResponse.fromMap(result!); + } + + @override + Future getBondedDevices() async { + final result = await _channel.invokeMethod>( + 'getBondedDevices', + ); + + return BmDevicesList.fromMap(result!); + } + + @override + Future getPhySupport() async { + final result = await _channel.invokeMethod>( + 'getPhySupport', + ); + + return PhySupport.fromMap(result!); + } + + @override + Future getSystemDevices() async { + final result = await _channel.invokeMethod>( + 'getSystemDevices', + ); + + return BmDevicesList.fromMap(result!); + } + + @override + Future isSupported() async { + final result = await _channel.invokeMethod( + 'isSupported', + ); + + return result!; + } + + @override + Future readCharacteristic( + BmReadCharacteristicRequest request, + ) async { + await _channel.invokeMethod( + 'readCharacteristic', + request.toMap(), + ); + } + + @override + Future readDescriptor( + BmReadDescriptorRequest request, + ) async { + await _channel.invokeMethod( + 'readDescriptor', + request.toMap(), + ); + } + + @override + Future readRssi( + DeviceIdentifier device, + ) async { + await _channel.invokeMethod( + 'readRssi', + device.str, + ); + } + + @override + Future removeBond( + DeviceIdentifier device, + ) async { + final result = await _channel.invokeMethod( + 'removeBond', + device.str, + ); + + return result!; + } + + @override + Future requestConnectionPriority( + BmConnectionPriorityRequest request, + ) async { + await _channel.invokeMethod( + 'requestConnectionPriority', + request.toMap(), + ); + } + + @override + Future requestMtu( + BmMtuChangeRequest request, + ) async { + await _channel.invokeMethod( + 'requestMtu', + request.toMap(), + ); + } + + @override + Future setLogLevel( + LogLevel level, + ) async { + await _channel.invokeMethod( + 'setLogLevel', + level.index, + ); + } + + @override + Future setNotifyValue( + BmSetNotifyValueRequest request, + ) async { + final result = await _channel.invokeMethod( + 'setNotifyValue', + request.toMap(), + ); + + return result!; + } + + @override + Future setOptions( + Options options, + ) async { + await _channel.invokeMethod( + 'setOptions', + options.toMap(), + ); + } + + @override + Future setPreferredPhy( + BmPreferredPhy preferredPhy, + ) async { + await _channel.invokeMethod( + 'setPreferredPhy', + preferredPhy.toMap(), + ); + } + + @override + Future startScan( + BmScanSettings settings, + ) async { + await _channel.invokeMethod( + 'startScan', + settings.toMap(), + ); + } + + @override + Future stopScan() async { + await _channel.invokeMethod( + 'stopScan', + ); + } + + @override + Future turnOff() async { + await _channel.invokeMethod( + 'turnOff', + ); + } + + @override + Future turnOn() async { + final result = await _channel.invokeMethod( + 'turnOn', + ); + + return result!; + } + + @override + Future writeCharacteristic( + BmWriteCharacteristicRequest request, + ) async { + await _channel.invokeMethod( + 'writeCharacteristic', + request.toMap(), + ); + } + + @override + Future writeDescriptor( + BmWriteDescriptorRequest request, + ) async { + await _channel.invokeMethod( + 'writeDescriptor', + request.toMap(), + ); + } +} From 2e684c573b845ac0b00f9c43ab300a08ef16d00b Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sat, 17 Aug 2024 20:48:09 +0100 Subject: [PATCH 19/90] test: add method channel implementation --- ...method_channel_flutter_blue_plus_test.dart | 1215 +++++++++++++++++ 1 file changed, 1215 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart new file mode 100644 index 00000000..93794eda --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart @@ -0,0 +1,1215 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/method_channel_flutter_blue_plus.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group( + 'MethodChannelFlutterBluePlus', + () { + final flutterBluePlus = MethodChannelFlutterBluePlus(); + final log = []; + + Future? Function(MethodCall methodCall)? handler; + + group( + 'clearGattCache', + () { + test( + 'invokes the method', + () async { + final device = DeviceIdentifier(''); + + await flutterBluePlus.clearGattCache(device); + + expect( + log, + orderedEquals([ + isMethodCall( + 'clearGattCache', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'connect', + () { + final result = true; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final request = BmConnectRequest( + remoteId: DeviceIdentifier(''), + autoConnect: false, + ); + + expect( + await flutterBluePlus.connect(request), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final request = BmConnectRequest( + remoteId: DeviceIdentifier(''), + autoConnect: false, + ); + + await flutterBluePlus.connect(request); + + expect( + log, + orderedEquals([ + isMethodCall( + 'connect', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'connectedCount', + () { + final result = 0; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.connectedCount(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.connectedCount(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'connectedCount', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'createBond', + () { + final result = true; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final device = DeviceIdentifier(''); + + expect( + await flutterBluePlus.createBond(device), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final device = DeviceIdentifier(''); + + await flutterBluePlus.createBond(device); + + expect( + log, + orderedEquals([ + isMethodCall( + 'createBond', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'disconnect', + () { + final result = true; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final device = DeviceIdentifier(''); + + expect( + await flutterBluePlus.disconnect(device), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final device = DeviceIdentifier(''); + + await flutterBluePlus.disconnect(device); + + expect( + log, + orderedEquals([ + isMethodCall( + 'disconnect', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'discoverServices', + () { + test( + 'invokes the method', + () async { + final device = DeviceIdentifier(''); + + await flutterBluePlus.discoverServices(device); + + expect( + log, + orderedEquals([ + isMethodCall( + 'discoverServices', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'flutterRestart', + () { + final result = 0; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.flutterRestart(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.flutterRestart(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'flutterRestart', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getAdapterName', + () { + final result = ''; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.getAdapterName(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getAdapterName(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'getAdapterName', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getAdapterState', + () { + final result = BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ); + + setUp( + () { + handler = (methodCall) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + (await flutterBluePlus.getAdapterState()).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getAdapterState(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'getAdapterState', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getBondState', + () { + final result = BmBondStateResponse( + remoteId: DeviceIdentifier(''), + bondState: BmBondStateEnum.none, + ); + + setUp( + () { + handler = (methodCall) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final device = DeviceIdentifier(''); + + expect( + (await flutterBluePlus.getBondState(device)).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + final device = DeviceIdentifier(''); + + await flutterBluePlus.getBondState(device); + + expect( + log, + orderedEquals([ + isMethodCall( + 'getBondState', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getBondedDevices', + () { + final result = BmDevicesList( + devices: [], + ); + + setUp( + () { + handler = (methodCall) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + (await flutterBluePlus.getBondedDevices()).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getBondedDevices(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'getBondedDevices', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getPhySupport', + () { + final result = PhySupport( + le2M: false, + leCoded: false, + ); + + setUp( + () { + handler = (methodCall) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + (await flutterBluePlus.getPhySupport()).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getPhySupport(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'getPhySupport', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getSystemDevices', + () { + final result = BmDevicesList( + devices: [], + ); + + setUp( + () { + handler = (methodCall) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + (await flutterBluePlus.getSystemDevices()).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getSystemDevices(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'getSystemDevices', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'isSupported', + () { + final result = true; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.isSupported(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.isSupported(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'isSupported', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'readCharacteristic', + () { + test( + 'invokes the method', + () async { + final request = BmReadCharacteristicRequest( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ); + + await flutterBluePlus.readCharacteristic(request); + + expect( + log, + orderedEquals([ + isMethodCall( + 'readCharacteristic', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'readDescriptor', + () { + test( + 'invokes the method', + () async { + final request = BmReadDescriptorRequest( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ); + + await flutterBluePlus.readDescriptor(request); + + expect( + log, + orderedEquals([ + isMethodCall( + 'readDescriptor', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'readRssi', + () { + test( + 'invokes the method', + () async { + final device = DeviceIdentifier(''); + + await flutterBluePlus.readRssi(device); + + expect( + log, + orderedEquals([ + isMethodCall( + 'readRssi', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'removeBond', + () { + final result = true; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final device = DeviceIdentifier(''); + + expect( + await flutterBluePlus.removeBond(device), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final device = DeviceIdentifier(''); + + await flutterBluePlus.removeBond(device); + + expect( + log, + orderedEquals([ + isMethodCall( + 'removeBond', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'requestConnectionPriority', + () { + test( + 'invokes the method', + () async { + final request = BmConnectionPriorityRequest( + remoteId: DeviceIdentifier(''), + connectionPriority: BmConnectionPriorityEnum.balanced, + ); + + await flutterBluePlus.requestConnectionPriority(request); + + expect( + log, + orderedEquals([ + isMethodCall( + 'requestConnectionPriority', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'requestMtu', + () { + test( + 'invokes the method', + () async { + final request = BmMtuChangeRequest( + remoteId: DeviceIdentifier(''), + mtu: 0, + ); + + await flutterBluePlus.requestMtu(request); + + expect( + log, + orderedEquals([ + isMethodCall( + 'requestMtu', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'setLogLevel', + () { + test( + 'invokes the method', + () async { + final level = LogLevel.none; + + await flutterBluePlus.setLogLevel(level); + + expect( + log, + orderedEquals([ + isMethodCall( + 'setLogLevel', + arguments: level.index, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'setNotifyValue', + () { + final result = true; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final request = BmSetNotifyValueRequest( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ); + + expect( + await flutterBluePlus.setNotifyValue(request), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final request = BmSetNotifyValueRequest( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ); + + await flutterBluePlus.setNotifyValue(request); + + expect( + log, + orderedEquals([ + isMethodCall( + 'setNotifyValue', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'setOptions', + () { + test( + 'invokes the method', + () async { + final options = Options( + showPowerAlert: false, + ); + + await flutterBluePlus.setOptions(options); + + expect( + log, + orderedEquals([ + isMethodCall( + 'setOptions', + arguments: options.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'setPreferredPhy', + () { + test( + 'invokes the method', + () async { + final preferredPhy = BmPreferredPhy( + remoteId: DeviceIdentifier(''), + txPhy: 0, + rxPhy: 0, + phyOptions: 0, + ); + + await flutterBluePlus.setPreferredPhy(preferredPhy); + + expect( + log, + orderedEquals([ + isMethodCall( + 'setPreferredPhy', + arguments: preferredPhy.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'startScan', + () { + test( + 'invokes the method', + () async { + final settings = BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ); + + await flutterBluePlus.startScan(settings); + + expect( + log, + orderedEquals([ + isMethodCall( + 'startScan', + arguments: settings.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'stopScan', + () { + test( + 'invokes the method', + () async { + await flutterBluePlus.stopScan(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'stopScan', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'turnOff', + () { + test( + 'invokes the method', + () async { + await flutterBluePlus.turnOff(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'turnOff', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'turnOn', + () { + final result = true; + + setUp( + () { + handler = (methodCall) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + handler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.turnOn(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.turnOn(); + + expect( + log, + orderedEquals([ + isMethodCall( + 'turnOn', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'writeCharacteristic', + () { + test( + 'invokes the method', + () async { + final request = BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ); + + await flutterBluePlus.writeCharacteristic(request); + + expect( + log, + orderedEquals([ + isMethodCall( + 'writeCharacteristic', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'writeDescriptor', + () { + test( + 'invokes the method', + () async { + final request = BmWriteDescriptorRequest( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ); + + await flutterBluePlus.writeDescriptor(request); + + expect( + log, + orderedEquals([ + isMethodCall( + 'writeDescriptor', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + setUp( + () { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler( + MethodChannel('flutter_blue_plus/methods'), + (methodCall) { + log.add(methodCall); + + return handler?.call(methodCall); + }, + ); + }, + ); + + tearDown( + () { + log.clear(); + }, + ); + }, + ); +} From 7af78abb75975ef0185b106eb88f1e6d79100b5f Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 07:49:40 +0100 Subject: [PATCH 20/90] chore: add changelog to platform interface --- packages/flutter_blue_plus_platform_interface/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/CHANGELOG.md diff --git a/packages/flutter_blue_plus_platform_interface/CHANGELOG.md b/packages/flutter_blue_plus_platform_interface/CHANGELOG.md new file mode 100644 index 00000000..0d8803f9 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +* Initial release. From 09022fb40b1edbb8bdd24cfd6830c2da39e19201 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 07:50:08 +0100 Subject: [PATCH 21/90] build: update platform interface pubspec --- packages/flutter_blue_plus_platform_interface/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index 1804d08c..b524581a 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -1,11 +1,11 @@ name: flutter_blue_plus_platform_interface description: A common platform interface for the flutter_blue_plus plugin. -version: 0.0.0 +version: 1.0.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: sdk: ">=2.12.0 <4.0.0" - flutter: ">=1.17.0" + flutter: ">=2.0.0" dependencies: convert: ^3.0.0 From 9d14ed00d3e44369f194c0c19ffd83206e701edf Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 07:52:08 +0100 Subject: [PATCH 22/90] refactor: migrate android implementation --- android/settings.gradle | 1 - packages/flutter_blue_plus_android/.gitignore | 29 ++++++++++++++++++ .../flutter_blue_plus_android/.metadata | 6 ++-- .../flutter_blue_plus_android/CHANGELOG.md | 3 ++ packages/flutter_blue_plus_android/LICENSE | 28 +++++++++++++++++ packages/flutter_blue_plus_android/README.md | 15 ++++++++++ .../analysis_options.yaml | 1 + .../android}/.gitignore | 1 + .../android}/build.gradle | 2 ++ .../android/settings.gradle | 3 ++ .../android}/src/main/AndroidManifest.xml | 0 .../FlutterBluePlusPlugin.java | 0 .../flutter_blue_plus_android/pubspec.yaml | 30 +++++++++++++++++++ 13 files changed, 115 insertions(+), 4 deletions(-) delete mode 100644 android/settings.gradle create mode 100644 packages/flutter_blue_plus_android/.gitignore rename .metadata => packages/flutter_blue_plus_android/.metadata (73%) create mode 100644 packages/flutter_blue_plus_android/CHANGELOG.md create mode 100644 packages/flutter_blue_plus_android/LICENSE create mode 100644 packages/flutter_blue_plus_android/README.md create mode 100644 packages/flutter_blue_plus_android/analysis_options.yaml rename {android => packages/flutter_blue_plus_android/android}/.gitignore (95%) rename {android => packages/flutter_blue_plus_android/android}/build.gradle (93%) create mode 100644 packages/flutter_blue_plus_android/android/settings.gradle rename {android => packages/flutter_blue_plus_android/android}/src/main/AndroidManifest.xml (100%) rename {android => packages/flutter_blue_plus_android/android}/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java (100%) create mode 100644 packages/flutter_blue_plus_android/pubspec.yaml diff --git a/android/settings.gradle b/android/settings.gradle deleted file mode 100644 index 943eabda..00000000 --- a/android/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'flutter_blue_plus' diff --git a/packages/flutter_blue_plus_android/.gitignore b/packages/flutter_blue_plus_android/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/flutter_blue_plus_android/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/.metadata b/packages/flutter_blue_plus_android/.metadata similarity index 73% rename from .metadata rename to packages/flutter_blue_plus_android/.metadata index 7516097a..8123a41b 100644 --- a/.metadata +++ b/packages/flutter_blue_plus_android/.metadata @@ -1,10 +1,10 @@ # This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades, etc. +# Used by Flutter tool to assess capabilities and perform upgrades etc. # # This file should be version controlled and should not be manually edited. version: - revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b - channel: stable + revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" + channel: "beta" project_type: plugin diff --git a/packages/flutter_blue_plus_android/CHANGELOG.md b/packages/flutter_blue_plus_android/CHANGELOG.md new file mode 100644 index 00000000..1e7cb110 --- /dev/null +++ b/packages/flutter_blue_plus_android/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.33.0 + +* Split from `flutter_blue_plus` as a federated implementation. diff --git a/packages/flutter_blue_plus_android/LICENSE b/packages/flutter_blue_plus_android/LICENSE new file mode 100644 index 00000000..0df3b4a3 --- /dev/null +++ b/packages/flutter_blue_plus_android/LICENSE @@ -0,0 +1,28 @@ +Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Buffalo PC Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_android/README.md b/packages/flutter_blue_plus_android/README.md new file mode 100644 index 00000000..dc692c17 --- /dev/null +++ b/packages/flutter_blue_plus_android/README.md @@ -0,0 +1,15 @@ +# flutter_blue_plus_android + +The Android implementation of [`flutter_blue_plus`][1]. + +## Usage + +This package is [endorsed][2], which means you can simply use `flutter_blue_plus` +normally. This package will be automatically included in your app when you do, +so you do not need to add it to your `pubspec.yaml`. + +However, if you `import` this package to use any of its APIs directly, you +should add it to your `pubspec.yaml` as usual. + +[1]: https://pub.dev/packages/flutter_blue_plus +[2]: https://flutter.dev/to/endorsed-federated-plugin diff --git a/packages/flutter_blue_plus_android/analysis_options.yaml b/packages/flutter_blue_plus_android/analysis_options.yaml new file mode 100644 index 00000000..f9b30346 --- /dev/null +++ b/packages/flutter_blue_plus_android/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/android/.gitignore b/packages/flutter_blue_plus_android/android/.gitignore similarity index 95% rename from android/.gitignore rename to packages/flutter_blue_plus_android/android/.gitignore index c6cbe562..161bdcda 100644 --- a/android/.gitignore +++ b/packages/flutter_blue_plus_android/android/.gitignore @@ -6,3 +6,4 @@ .DS_Store /build /captures +.cxx diff --git a/android/build.gradle b/packages/flutter_blue_plus_android/android/build.gradle similarity index 93% rename from android/build.gradle rename to packages/flutter_blue_plus_android/android/build.gradle index 2c6f5f39..04f31190 100644 --- a/android/build.gradle +++ b/packages/flutter_blue_plus_android/android/build.gradle @@ -1,3 +1,5 @@ +package packages.flutter_blue_plus_android.android + group 'com.lib.flutter_blue_plus' version '1.0' diff --git a/packages/flutter_blue_plus_android/android/settings.gradle b/packages/flutter_blue_plus_android/android/settings.gradle new file mode 100644 index 00000000..902780c0 --- /dev/null +++ b/packages/flutter_blue_plus_android/android/settings.gradle @@ -0,0 +1,3 @@ +package packages.flutter_blue_plus_android.android + +rootProject.name = 'flutter_blue_plus' diff --git a/android/src/main/AndroidManifest.xml b/packages/flutter_blue_plus_android/android/src/main/AndroidManifest.xml similarity index 100% rename from android/src/main/AndroidManifest.xml rename to packages/flutter_blue_plus_android/android/src/main/AndroidManifest.xml diff --git a/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java b/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java similarity index 100% rename from android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java rename to packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java diff --git a/packages/flutter_blue_plus_android/pubspec.yaml b/packages/flutter_blue_plus_android/pubspec.yaml new file mode 100644 index 00000000..761ec1a0 --- /dev/null +++ b/packages/flutter_blue_plus_android/pubspec.yaml @@ -0,0 +1,30 @@ +name: flutter_blue_plus_android +description: Android implementation of the flutter_blue_plus plugin. +version: 1.33.0 +homepage: https://github.com/boskokg/flutter_blue_plus + +environment: + sdk: ">=2.12.0 <4.0.0" + flutter: ">=2.0.0" + +dependencies: + flutter: + sdk: flutter + flutter_blue_plus_platform_interface: ^1.0.0 + +dev_dependencies: + flutter_lints: ^4.0.0 + flutter_test: + sdk: flutter + +dependency_overrides: + flutter_blue_plus_platform_interface: + path: ../flutter_blue_plus_platform_interface + +flutter: + plugin: + implements: flutter_blue_plus + platforms: + android: + package: com.lib.flutter_blue_plus + pluginClass: FlutterBluePlusPlugin From 022a1a8c6a3bb5538dee6066aebce2501ff07151 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 07:52:57 +0100 Subject: [PATCH 23/90] refactor: migrate ios and macos implementation --- ios/Assets/.gitkeep | 0 ios/flutter_blue_plus.podspec | 20 ----------- macos/Classes/FlutterBluePlusPlugin.h | 1 - macos/Classes/FlutterBluePlusPlugin.m | 1 - macos/flutter_blue_plus.podspec | 22 ------------- packages/flutter_blue_plus_darwin/.gitignore | 29 ++++++++++++++++ packages/flutter_blue_plus_darwin/.metadata | 30 +++++++++++++++++ .../flutter_blue_plus_darwin/CHANGELOG.md | 3 ++ packages/flutter_blue_plus_darwin/LICENSE | 28 ++++++++++++++++ packages/flutter_blue_plus_darwin/README.md | 15 +++++++++ .../analysis_options.yaml | 1 + .../darwin}/.gitignore | 2 +- .../darwin}/Classes/FlutterBluePlusPlugin.h | 0 .../darwin}/Classes/FlutterBluePlusPlugin.m | 0 .../darwin/flutter_blue_plus_darwin.podspec | 22 +++++++++++++ .../flutter_blue_plus_darwin/pubspec.yaml | 33 +++++++++++++++++++ 16 files changed, 162 insertions(+), 45 deletions(-) delete mode 100644 ios/Assets/.gitkeep delete mode 100644 ios/flutter_blue_plus.podspec delete mode 120000 macos/Classes/FlutterBluePlusPlugin.h delete mode 120000 macos/Classes/FlutterBluePlusPlugin.m delete mode 100644 macos/flutter_blue_plus.podspec create mode 100644 packages/flutter_blue_plus_darwin/.gitignore create mode 100644 packages/flutter_blue_plus_darwin/.metadata create mode 100644 packages/flutter_blue_plus_darwin/CHANGELOG.md create mode 100644 packages/flutter_blue_plus_darwin/LICENSE create mode 100644 packages/flutter_blue_plus_darwin/README.md create mode 100644 packages/flutter_blue_plus_darwin/analysis_options.yaml rename {ios => packages/flutter_blue_plus_darwin/darwin}/.gitignore (90%) rename {ios => packages/flutter_blue_plus_darwin/darwin}/Classes/FlutterBluePlusPlugin.h (100%) rename {ios => packages/flutter_blue_plus_darwin/darwin}/Classes/FlutterBluePlusPlugin.m (100%) create mode 100644 packages/flutter_blue_plus_darwin/darwin/flutter_blue_plus_darwin.podspec create mode 100644 packages/flutter_blue_plus_darwin/pubspec.yaml diff --git a/ios/Assets/.gitkeep b/ios/Assets/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/ios/flutter_blue_plus.podspec b/ios/flutter_blue_plus.podspec deleted file mode 100644 index d4c7245c..00000000 --- a/ios/flutter_blue_plus.podspec +++ /dev/null @@ -1,20 +0,0 @@ -# -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. -# Run `pod lib lint flutter_blue_plus.podspec` to validate before publishing. -# -Pod::Spec.new do |s| - s.name = 'flutter_blue_plus' - s.version = '0.0.1' - s.summary = 'Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS' - s.description = 'Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS' - s.homepage = 'https://github.com/boskokg/flutter_blue_plus' - s.license = { :file => '../LICENSE' } - s.author = { 'Chip Weinberger' => 'weinberger.c@gmail.com' } - s.source = { :path => '.' } - s.source_files = 'Classes/**/*' - s.public_header_files = 'Classes/**/*.h' - s.dependency 'Flutter' - s.platform = :ios, '9.0' - s.framework = 'CoreBluetooth' - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', } -end diff --git a/macos/Classes/FlutterBluePlusPlugin.h b/macos/Classes/FlutterBluePlusPlugin.h deleted file mode 120000 index 2f315101..00000000 --- a/macos/Classes/FlutterBluePlusPlugin.h +++ /dev/null @@ -1 +0,0 @@ -../../ios/Classes/FlutterBluePlusPlugin.h \ No newline at end of file diff --git a/macos/Classes/FlutterBluePlusPlugin.m b/macos/Classes/FlutterBluePlusPlugin.m deleted file mode 120000 index 0c610151..00000000 --- a/macos/Classes/FlutterBluePlusPlugin.m +++ /dev/null @@ -1 +0,0 @@ -../../ios/Classes/FlutterBluePlusPlugin.m \ No newline at end of file diff --git a/macos/flutter_blue_plus.podspec b/macos/flutter_blue_plus.podspec deleted file mode 100644 index 6944e77d..00000000 --- a/macos/flutter_blue_plus.podspec +++ /dev/null @@ -1,22 +0,0 @@ -# -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. -# Run `pod lib lint flutter_blue_plus.podspec' to validate before publishing. -# -Pod::Spec.new do |s| - s.name = 'flutter_blue_plus' - s.version = '0.0.1' - s.summary = 'Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS' - s.description = 'Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS' - s.homepage = 'https://github.com/boskokg/flutter_blue_plus' - s.license = { :file => '../LICENSE' } - s.author = { 'Chip Weinberger' => 'weinberger.c@gmail.com' } - s.source = { :path => '.' } - s.source_files = 'Classes/**/*' - s.public_header_files = 'Classes/**/*.h' - s.dependency 'FlutterMacOS' - s.platform = :osx, '10.11' - s.framework = 'CoreBluetooth' - s.pod_target_xcconfig = { - 'DEFINES_MODULE' => 'YES', - } -end diff --git a/packages/flutter_blue_plus_darwin/.gitignore b/packages/flutter_blue_plus_darwin/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/flutter_blue_plus_darwin/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/packages/flutter_blue_plus_darwin/.metadata b/packages/flutter_blue_plus_darwin/.metadata new file mode 100644 index 00000000..9b743e45 --- /dev/null +++ b/packages/flutter_blue_plus_darwin/.metadata @@ -0,0 +1,30 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" + channel: "beta" + +project_type: plugin + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: b864805a681ae6bb7d7f6cafb7a5a21489819bcf + base_revision: b864805a681ae6bb7d7f6cafb7a5a21489819bcf + - platform: ios + create_revision: b864805a681ae6bb7d7f6cafb7a5a21489819bcf + base_revision: b864805a681ae6bb7d7f6cafb7a5a21489819bcf + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/flutter_blue_plus_darwin/CHANGELOG.md b/packages/flutter_blue_plus_darwin/CHANGELOG.md new file mode 100644 index 00000000..1e7cb110 --- /dev/null +++ b/packages/flutter_blue_plus_darwin/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.33.0 + +* Split from `flutter_blue_plus` as a federated implementation. diff --git a/packages/flutter_blue_plus_darwin/LICENSE b/packages/flutter_blue_plus_darwin/LICENSE new file mode 100644 index 00000000..0df3b4a3 --- /dev/null +++ b/packages/flutter_blue_plus_darwin/LICENSE @@ -0,0 +1,28 @@ +Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Buffalo PC Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_darwin/README.md b/packages/flutter_blue_plus_darwin/README.md new file mode 100644 index 00000000..6e6d5ecd --- /dev/null +++ b/packages/flutter_blue_plus_darwin/README.md @@ -0,0 +1,15 @@ +# flutter_blue_plus_darwin + +The iOS and macOS implementation of [`flutter_blue_plus`][1]. + +## Usage + +This package is [endorsed][2], which means you can simply use `flutter_blue_plus` +normally. This package will be automatically included in your app when you do, +so you do not need to add it to your `pubspec.yaml`. + +However, if you `import` this package to use any of its APIs directly, you +should add it to your `pubspec.yaml` as usual. + +[1]: https://pub.dev/packages/flutter_blue_plus +[2]: https://flutter.dev/to/endorsed-federated-plugin diff --git a/packages/flutter_blue_plus_darwin/analysis_options.yaml b/packages/flutter_blue_plus_darwin/analysis_options.yaml new file mode 100644 index 00000000..f9b30346 --- /dev/null +++ b/packages/flutter_blue_plus_darwin/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/ios/.gitignore b/packages/flutter_blue_plus_darwin/darwin/.gitignore similarity index 90% rename from ios/.gitignore rename to packages/flutter_blue_plus_darwin/darwin/.gitignore index 0c885071..034771fc 100644 --- a/ios/.gitignore +++ b/packages/flutter_blue_plus_darwin/darwin/.gitignore @@ -35,4 +35,4 @@ Icon? /Flutter/Generated.xcconfig /Flutter/ephemeral/ -/Flutter/flutter_export_environment.sh \ No newline at end of file +/Flutter/flutter_export_environment.sh diff --git a/ios/Classes/FlutterBluePlusPlugin.h b/packages/flutter_blue_plus_darwin/darwin/Classes/FlutterBluePlusPlugin.h similarity index 100% rename from ios/Classes/FlutterBluePlusPlugin.h rename to packages/flutter_blue_plus_darwin/darwin/Classes/FlutterBluePlusPlugin.h diff --git a/ios/Classes/FlutterBluePlusPlugin.m b/packages/flutter_blue_plus_darwin/darwin/Classes/FlutterBluePlusPlugin.m similarity index 100% rename from ios/Classes/FlutterBluePlusPlugin.m rename to packages/flutter_blue_plus_darwin/darwin/Classes/FlutterBluePlusPlugin.m diff --git a/packages/flutter_blue_plus_darwin/darwin/flutter_blue_plus_darwin.podspec b/packages/flutter_blue_plus_darwin/darwin/flutter_blue_plus_darwin.podspec new file mode 100644 index 00000000..a8e159b1 --- /dev/null +++ b/packages/flutter_blue_plus_darwin/darwin/flutter_blue_plus_darwin.podspec @@ -0,0 +1,22 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint flutter_blue_plus.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'flutter_blue_plus' + s.version = '0.0.1' + s.summary = 'Flutter plugin for connecting and communicating with Bluetooth Low Energy devices, on Android and iOS' + s.description = 'Flutter plugin for connecting and communicating with Bluetooth Low Energy devices, on Android and iOS' + s.homepage = 'https://github.com/boskokg/flutter_blue_plus' + s.license = { :file => '../LICENSE' } + s.author = { 'Chip Weinberger' => 'weinberger.c@gmail.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.ios.dependency 'Flutter' + s.osx.dependency 'FlutterMacOS' + s.ios.deployment_target = '9.0' + s.osx.deployment_target = '10.11' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', } + s.framework = 'CoreBluetooth' +end diff --git a/packages/flutter_blue_plus_darwin/pubspec.yaml b/packages/flutter_blue_plus_darwin/pubspec.yaml new file mode 100644 index 00000000..3392cb0f --- /dev/null +++ b/packages/flutter_blue_plus_darwin/pubspec.yaml @@ -0,0 +1,33 @@ +name: flutter_blue_plus_darwin +description: iOS and macOS implementation of the flutter_blue_plus plugin. +version: 1.33.0 +homepage: https://github.com/boskokg/flutter_blue_plus + +environment: + sdk: ">=2.12.0 <4.0.0" + flutter: ">=3.7.0" + +dependencies: + flutter: + sdk: flutter + flutter_blue_plus_platform_interface: ^1.0.0 + +dev_dependencies: + flutter_lints: ^4.0.0 + flutter_test: + sdk: flutter + +dependency_overrides: + flutter_blue_plus_platform_interface: + path: ../flutter_blue_plus_platform_interface + +flutter: + plugin: + implements: flutter_blue_plus + platforms: + ios: + pluginClass: FlutterBluePlusPlugin + sharedDarwinSource: true + macos: + pluginClass: FlutterBluePlusPlugin + sharedDarwinSource: true From 0fff3fc6a5b8d4931b1ecf8ea90d44fc7ff23828 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 08:38:52 +0100 Subject: [PATCH 24/90] refactor: add bm user canceled error code --- .../lib/flutter_blue_plus_platform_interface.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index b011abec..e5a9820c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -39,3 +39,6 @@ export 'src/scan/models/bm_scan_settings.dart'; export 'src/scan/models/bm_service_data_filter.dart'; export 'src/service/models/bm_bluetooth_service.dart'; export 'src/service/models/bm_discover_services_result.dart'; + +// random number defined by flutter blue plus +int bmUserCanceledErrorCode = 23789258; From 7913c48564a3db27539ba7f45b36b46e68890520 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 08:39:14 +0100 Subject: [PATCH 25/90] refactor: rename device parameter to remote id --- .../lib/src/flutter_blue_plus_platform.dart | 28 +++++++++---------- .../src/method_channel_flutter_blue_plus.dart | 28 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index 8947143c..ce5ccab2 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -39,9 +39,9 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { _instance = instance; } - /// Clears the GATT cache for a [device]. + /// Clears the GATT cache for a [remoteId]. Future clearGattCache( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) { throw UnimplementedError(); } @@ -62,33 +62,33 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Creates a bond to a [device]. + /// Creates a bond to a [remoteId]. /// /// Returns [true] if the bond state is changed. /// /// Implementations should call [OnBondStateChanged] with the changed bond state. Future createBond( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) { throw UnimplementedError(); } - /// Disconnects from a [device]. + /// Disconnects from a [remoteId]. /// /// Returns [true] if the connection state is changed. /// /// Implementations should call [OnConnectionStateChanged] with the changed connection state. Future disconnect( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) { throw UnimplementedError(); } - /// Discovers the services for a [device]. + /// Discovers the services for a [remoteId]. /// /// Implementations should call [OnDiscoveredServices] with the discovered services. Future discoverServices( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) { throw UnimplementedError(); } @@ -108,9 +108,9 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Returns the bond state for a [device]. + /// Returns the bond state for a [remoteId]. Future getBondState( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) { throw UnimplementedError(); } @@ -153,22 +153,22 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Reads the Received Signal Strength Indicator (RSSI) for a [device]. + /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. /// /// Implementations should call [OnReadRssi] with the read RSSI. Future readRssi( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) { throw UnimplementedError(); } - /// Removes the bond to a [device]. + /// Removes the bond to a [remoteId]. /// /// Returns [true] if the bond state is changed. /// /// Implementations should call [OnBondStateChanged] with the changed bond state. Future removeBond( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) { throw UnimplementedError(); } diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index c734edfd..e678d758 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -25,11 +25,11 @@ const _channel = MethodChannel('flutter_blue_plus/methods'); class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future clearGattCache( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) async { await _channel.invokeMethod( 'clearGattCache', - device.str, + remoteId.str, ); } @@ -56,11 +56,11 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future createBond( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) async { final result = await _channel.invokeMethod( 'createBond', - device.str, + remoteId.str, ); return result!; @@ -68,11 +68,11 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future disconnect( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) async { final result = await _channel.invokeMethod( 'disconnect', - device.str, + remoteId.str, ); return result!; @@ -80,11 +80,11 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future discoverServices( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) async { await _channel.invokeMethod( 'discoverServices', - device.str, + remoteId.str, ); } @@ -117,11 +117,11 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getBondState( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) async { final result = await _channel.invokeMethod>( 'getBondState', - device.str, + remoteId.str, ); return BmBondStateResponse.fromMap(result!); @@ -185,21 +185,21 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future readRssi( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) async { await _channel.invokeMethod( 'readRssi', - device.str, + remoteId.str, ); } @override Future removeBond( - DeviceIdentifier device, + DeviceIdentifier remoteId, ) async { final result = await _channel.invokeMethod( 'removeBond', - device.str, + remoteId.str, ); return result!; From 38c5453dfe89bf972b0477b2c7272df21bbbc505 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 10:32:53 +0100 Subject: [PATCH 26/90] refactor: add events to platform interface --- .../lib/src/flutter_blue_plus_platform.dart | 130 ++++++++-- .../src/method_channel_flutter_blue_plus.dart | 223 +++++++++++++++--- ...method_channel_flutter_blue_plus_test.dart | 38 +-- 3 files changed, 319 insertions(+), 72 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index ce5ccab2..31deb750 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -1,6 +1,8 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'adapter/models/bm_bluetooth_adapter_state.dart'; +import 'adapter/models/bm_turn_on_response.dart'; +import 'characteristic/models/bm_characteristic_data.dart'; import 'characteristic/models/bm_read_characteristic_request.dart'; import 'characteristic/models/bm_set_notify_value_request.dart'; import 'characteristic/models/bm_write_characteristic_request.dart'; @@ -8,38 +10,124 @@ import 'common/enums/log_level.dart'; import 'common/models/device_identifier.dart'; import 'common/models/options.dart'; import 'common/models/phy_support.dart'; +import 'descriptor/models/bm_descriptor_data.dart'; import 'descriptor/models/bm_read_descriptor_request.dart'; import 'descriptor/models/bm_write_descriptor_request.dart'; +import 'device/models/bm_bluetooth_device.dart'; import 'device/models/bm_bond_state_response.dart'; import 'device/models/bm_connect_request.dart'; import 'device/models/bm_connection_priority_request.dart'; +import 'device/models/bm_connection_state_response.dart'; import 'device/models/bm_devices_list.dart'; import 'device/models/bm_mtu_change_request.dart'; +import 'device/models/bm_mtu_changed_response.dart'; +import 'device/models/bm_name_changed.dart'; import 'device/models/bm_preferred_phy.dart'; +import 'device/models/bm_read_rssi_result.dart'; import 'method_channel_flutter_blue_plus.dart'; +import 'scan/models/bm_scan_response.dart'; import 'scan/models/bm_scan_settings.dart'; +import 'service/models/bm_discover_services_result.dart'; /// The interface that implementations of flutter_blue_plus must implement. abstract class FlutterBluePlusPlatform extends PlatformInterface { - FlutterBluePlusPlatform() : super(token: _token); - static final _token = Object(); static FlutterBluePlusPlatform _instance = MethodChannelFlutterBluePlus(); + FlutterBluePlusPlatform() : super(token: _token); + /// The default instance of [FlutterBluePlusPlatform] to use. /// /// Defaults to [MethodChannelFlutterBluePlus]. - static FlutterBluePlusPlatform get instance => _instance; + static FlutterBluePlusPlatform get instance { + return _instance; + } - /// Platform-specific plugins should set this with their own platform-specific - /// class that extends [FlutterBluePlusPlatform] when they register themselves. - static set instance(FlutterBluePlusPlatform instance) { + /// Platform-specific plugins should set this with their own platform-specific class that extends [FlutterBluePlusPlatform] when they register themselves. + static set instance( + FlutterBluePlusPlatform instance, + ) { PlatformInterface.verify(instance, _token); _instance = instance; } - /// Clears the GATT cache for a [remoteId]. + /// Returns a stream of adapter state changed events. + Stream get onAdapterStateChanged { + throw UnimplementedError(); + } + + /// Returns a stream of bond state changed events. + Stream get onBondStateChanged { + throw UnimplementedError(); + } + + /// Returns a stream of characteristic received (notified or read) events. + Stream get onCharacteristicReceived { + throw UnimplementedError(); + } + + /// Returns a stream of characteristic written events. + Stream get onCharacteristicWritten { + throw UnimplementedError(); + } + + /// Returns a stream of connection state changed events. + Stream get onConnectionStateChanged { + throw UnimplementedError(); + } + + /// Returns a stream of descriptor read events. + Stream get onDescriptorRead { + throw UnimplementedError(); + } + + /// Returns a stream of descriptor written events. + Stream get onDescriptorWritten { + throw UnimplementedError(); + } + + /// Returns a stream of detached from engine events. + Stream get onDetachedFromEngine { + throw UnimplementedError(); + } + + /// Returns a stream of discovered services events. + Stream get onDiscoveredServices { + throw UnimplementedError(); + } + + /// Returns a stream of Maximum Transmission Unit (MTU) changed events. + Stream get onMtuChanged { + throw UnimplementedError(); + } + + /// Returns a stream of name changed events. + Stream get onNameChanged { + throw UnimplementedError(); + } + + /// Returns a stream of Received Signal Strength Indicator (RSSI) read events. + Stream get onReadRssi { + throw UnimplementedError(); + } + + /// Returns a stream of scan response events. + Stream get onScanResponse { + throw UnimplementedError(); + } + + /// Returns a stream of services reset events. + Stream get onServicesReset { + throw UnimplementedError(); + } + + /// Returns a stream of turn on response events. + Stream get onTurnOnResponse { + throw UnimplementedError(); + } + + /// Clears the Generic Attribute Profile (GATT) cache for a [remoteId]. Future clearGattCache( DeviceIdentifier remoteId, ) { @@ -50,7 +138,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the connection state is changed. /// - /// Implementations should call [OnConnectionStateChanged] with the changed connection state. + /// Implementations should add an event to the [onConnectionStateChanged] stream with the changed connection state. Future connect( BmConnectRequest request, ) { @@ -66,7 +154,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the bond state is changed. /// - /// Implementations should call [OnBondStateChanged] with the changed bond state. + /// Implementations should add an event to the [onBondStateChanged] stream with the changed bond state. Future createBond( DeviceIdentifier remoteId, ) { @@ -77,7 +165,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the connection state is changed. /// - /// Implementations should call [OnConnectionStateChanged] with the changed connection state. + /// Implementations should add an event to the [onConnectionStateChanged] stream with the changed connection state. Future disconnect( DeviceIdentifier remoteId, ) { @@ -86,7 +174,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Discovers the services for a [remoteId]. /// - /// Implementations should call [OnDiscoveredServices] with the discovered services. + /// Implementations should add an event to the [onDiscoveredServices] stream with the discovered services. Future discoverServices( DeviceIdentifier remoteId, ) { @@ -137,7 +225,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Reads the characteristic for a [request]. /// - /// Implementations should call [OnCharacteristicReceived] with the read characteristic. + /// Implementations should add an event to the [onCharacteristicReceived] stream with the read characteristic. Future readCharacteristic( BmReadCharacteristicRequest request, ) { @@ -146,7 +234,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Reads the descriptor for a [request]. /// - /// Implementations should call [OnDescriptorRead] with the read descriptor. + /// Implementations should add an event to the [onDescriptorRead] stream with the read descriptor. Future readDescriptor( BmReadDescriptorRequest request, ) { @@ -155,7 +243,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. /// - /// Implementations should call [OnReadRssi] with the read RSSI. + /// Implementations should add an event to the [onReadRssi] stream with the read RSSI. Future readRssi( DeviceIdentifier remoteId, ) { @@ -166,7 +254,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the bond state is changed. /// - /// Implementations should call [OnBondStateChanged] with the changed bond state. + /// Implementations should add an event to the [onBondStateChanged] stream with the changed bond state. Future removeBond( DeviceIdentifier remoteId, ) { @@ -182,7 +270,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Requests a change to the Maximum Transmission Unit (MTU) for a [request]. /// - /// Implementations should call [OnMtuChanged] with the changed MTU. + /// Implementations should add an event to the [onMtuChanged] stream with the changed MTU. Future requestMtu( BmMtuChangeRequest request, ) { @@ -200,7 +288,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the characteristic has a Client Characteristic Configuration Descriptor (CCCD). /// - /// Implementations should call [OnDescriptorWritten] with the written CCCD. + /// Implementations should add an event to the [onDescriptorWritten] stream with the written CCCD. Future setNotifyValue( BmSetNotifyValueRequest request, ) { @@ -223,7 +311,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Starts scanning for devices. /// - /// Implementations should call [OnScanResponse] for each scanned device. + /// Implementations should add an event to the [onScanResponse] stream for each scanned device. Future startScan( BmScanSettings settings, ) { @@ -244,14 +332,14 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the power state is changed. /// - /// Implementations should call [OnTurnOnResponse] with the power state. + /// Implementations should add an event to the [onTurnOnResponse] stream with the power state. Future turnOn() { throw UnimplementedError(); } /// Writes the characteristic for a [request]. /// - /// Implementations should call [OnCharacteristicWritten] with the written characteristic. + /// Implementations should add an event to the [onCharacteristicWritten] stream with the written characteristic. Future writeCharacteristic( BmWriteCharacteristicRequest request, ) { @@ -260,7 +348,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Writes the descriptor for a [request]. /// - /// Implementations should call [OnDescriptorWritten] with the written descriptor. + /// Implementations should add an event to the [onDescriptorWritten] stream with the written descriptor. Future writeDescriptor( BmWriteDescriptorRequest request, ) { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index e678d758..0949c4af 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -1,6 +1,11 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'adapter/models/bm_bluetooth_adapter_state.dart'; +import 'adapter/models/bm_turn_on_response.dart'; +import 'characteristic/models/bm_characteristic_data.dart'; import 'characteristic/models/bm_read_characteristic_request.dart'; import 'characteristic/models/bm_set_notify_value_request.dart'; import 'characteristic/models/bm_write_characteristic_request.dart'; @@ -8,26 +13,180 @@ import 'common/enums/log_level.dart'; import 'common/models/device_identifier.dart'; import 'common/models/options.dart'; import 'common/models/phy_support.dart'; +import 'descriptor/models/bm_descriptor_data.dart'; import 'descriptor/models/bm_read_descriptor_request.dart'; import 'descriptor/models/bm_write_descriptor_request.dart'; +import 'device/models/bm_bluetooth_device.dart'; import 'device/models/bm_bond_state_response.dart'; import 'device/models/bm_connect_request.dart'; import 'device/models/bm_connection_priority_request.dart'; +import 'device/models/bm_connection_state_response.dart'; import 'device/models/bm_devices_list.dart'; import 'device/models/bm_mtu_change_request.dart'; +import 'device/models/bm_mtu_changed_response.dart'; +import 'device/models/bm_name_changed.dart'; import 'device/models/bm_preferred_phy.dart'; +import 'device/models/bm_read_rssi_result.dart'; import 'flutter_blue_plus_platform.dart'; +import 'scan/models/bm_scan_response.dart'; import 'scan/models/bm_scan_settings.dart'; - -const _channel = MethodChannel('flutter_blue_plus/methods'); +import 'service/models/bm_discover_services_result.dart'; /// An implementation of [FlutterBluePlusPlatform] that uses method channels. class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { + @visibleForTesting + final channel = const MethodChannel('flutter_blue_plus/methods'); + + final _calls = StreamController.broadcast(); + + MethodChannelFlutterBluePlus() { + channel.setMethodCallHandler( + (call) async { + _calls.add(call); + }, + ); + } + + @override + Stream get onAdapterStateChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnAdapterStateChanged') { + yield BmBluetoothAdapterState.fromMap(call.arguments); + } + } + } + + @override + Stream get onBondStateChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnBondStateChanged') { + yield BmBondStateResponse.fromMap(call.arguments); + } + } + } + + @override + Stream get onCharacteristicReceived async* { + await for (final call in _calls.stream) { + if (call.method == 'OnCharacteristicReceived') { + yield BmCharacteristicData.fromMap(call.arguments); + } + } + } + + @override + Stream get onCharacteristicWritten async* { + await for (final call in _calls.stream) { + if (call.method == 'OnCharacteristicWritten') { + yield BmCharacteristicData.fromMap(call.arguments); + } + } + } + + @override + Stream get onConnectionStateChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnConnectionStateChanged') { + yield BmConnectionStateResponse.fromMap(call.arguments); + } + } + } + + @override + Stream get onDescriptorRead async* { + await for (final call in _calls.stream) { + if (call.method == 'OnDescriptorRead') { + yield BmDescriptorData.fromMap(call.arguments); + } + } + } + + @override + Stream get onDescriptorWritten async* { + await for (final call in _calls.stream) { + if (call.method == 'OnDescriptorWritten') { + yield BmDescriptorData.fromMap(call.arguments); + } + } + } + + @override + Stream get onDetachedFromEngine async* { + await for (final call in _calls.stream) { + if (call.method == 'OnDetachedFromEngine') { + yield null; + } + } + } + + @override + Stream get onDiscoveredServices async* { + await for (final call in _calls.stream) { + if (call.method == 'OnDiscoveredServices') { + yield BmDiscoverServicesResult.fromMap(call.arguments); + } + } + } + + @override + Stream get onMtuChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnMtuChanged') { + yield BmMtuChangedResponse.fromMap(call.arguments); + } + } + } + + @override + Stream get onNameChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnNameChanged') { + yield BmNameChanged.fromMap(call.arguments); + } + } + } + + @override + Stream get onReadRssi async* { + await for (final call in _calls.stream) { + if (call.method == 'OnReadRssi') { + yield BmReadRssiResult.fromMap(call.arguments); + } + } + } + + @override + Stream get onScanResponse async* { + await for (final call in _calls.stream) { + if (call.method == 'OnScanResponse') { + yield BmScanResponse.fromMap(call.arguments); + } + } + } + + @override + Stream get onServicesReset async* { + await for (final call in _calls.stream) { + if (call.method == 'OnServicesReset') { + yield BmBluetoothDevice.fromMap(call.arguments); + } + } + } + + @override + Stream get onTurnOnResponse async* { + await for (final call in _calls.stream) { + if (call.method == 'OnTurnOnResponse') { + yield BmTurnOnResponse.fromMap(call.arguments); + } + } + } + @override Future clearGattCache( DeviceIdentifier remoteId, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'clearGattCache', remoteId.str, ); @@ -37,7 +196,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future connect( BmConnectRequest request, ) async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'connect', request.toMap(), ); @@ -47,7 +206,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future connectedCount() async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'connectedCount', ); @@ -58,7 +217,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future createBond( DeviceIdentifier remoteId, ) async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'createBond', remoteId.str, ); @@ -70,7 +229,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future disconnect( DeviceIdentifier remoteId, ) async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'disconnect', remoteId.str, ); @@ -82,7 +241,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future discoverServices( DeviceIdentifier remoteId, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'discoverServices', remoteId.str, ); @@ -90,7 +249,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future flutterRestart() async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'flutterRestart', ); @@ -99,7 +258,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getAdapterName() async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'getAdapterName', ); @@ -108,7 +267,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getAdapterState() async { - final result = await _channel.invokeMethod>( + final result = await channel.invokeMethod>( 'getAdapterState', ); @@ -119,7 +278,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future getBondState( DeviceIdentifier remoteId, ) async { - final result = await _channel.invokeMethod>( + final result = await channel.invokeMethod>( 'getBondState', remoteId.str, ); @@ -129,7 +288,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getBondedDevices() async { - final result = await _channel.invokeMethod>( + final result = await channel.invokeMethod>( 'getBondedDevices', ); @@ -138,7 +297,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getPhySupport() async { - final result = await _channel.invokeMethod>( + final result = await channel.invokeMethod>( 'getPhySupport', ); @@ -147,7 +306,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getSystemDevices() async { - final result = await _channel.invokeMethod>( + final result = await channel.invokeMethod>( 'getSystemDevices', ); @@ -156,7 +315,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future isSupported() async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'isSupported', ); @@ -167,7 +326,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future readCharacteristic( BmReadCharacteristicRequest request, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'readCharacteristic', request.toMap(), ); @@ -177,7 +336,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future readDescriptor( BmReadDescriptorRequest request, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'readDescriptor', request.toMap(), ); @@ -187,7 +346,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future readRssi( DeviceIdentifier remoteId, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'readRssi', remoteId.str, ); @@ -197,7 +356,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future removeBond( DeviceIdentifier remoteId, ) async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'removeBond', remoteId.str, ); @@ -209,7 +368,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future requestConnectionPriority( BmConnectionPriorityRequest request, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'requestConnectionPriority', request.toMap(), ); @@ -219,7 +378,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future requestMtu( BmMtuChangeRequest request, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'requestMtu', request.toMap(), ); @@ -229,7 +388,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future setLogLevel( LogLevel level, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'setLogLevel', level.index, ); @@ -239,7 +398,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future setNotifyValue( BmSetNotifyValueRequest request, ) async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'setNotifyValue', request.toMap(), ); @@ -251,7 +410,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future setOptions( Options options, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'setOptions', options.toMap(), ); @@ -261,7 +420,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future setPreferredPhy( BmPreferredPhy preferredPhy, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'setPreferredPhy', preferredPhy.toMap(), ); @@ -271,7 +430,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future startScan( BmScanSettings settings, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'startScan', settings.toMap(), ); @@ -279,21 +438,21 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future stopScan() async { - await _channel.invokeMethod( + await channel.invokeMethod( 'stopScan', ); } @override Future turnOff() async { - await _channel.invokeMethod( + await channel.invokeMethod( 'turnOff', ); } @override Future turnOn() async { - final result = await _channel.invokeMethod( + final result = await channel.invokeMethod( 'turnOn', ); @@ -304,7 +463,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future writeCharacteristic( BmWriteCharacteristicRequest request, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'writeCharacteristic', request.toMap(), ); @@ -314,7 +473,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future writeDescriptor( BmWriteDescriptorRequest request, ) async { - await _channel.invokeMethod( + await channel.invokeMethod( 'writeDescriptor', request.toMap(), ); diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart index 93794eda..e236e873 100644 --- a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart @@ -45,7 +45,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -103,7 +103,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -151,7 +151,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -203,7 +203,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -279,7 +279,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -327,7 +327,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -377,7 +377,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -428,7 +428,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -482,7 +482,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -533,7 +533,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -583,7 +583,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -631,7 +631,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -760,7 +760,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -890,7 +890,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -1089,7 +1089,7 @@ void main() { setUp( () { - handler = (methodCall) { + handler = (call) { return Future.value(result); }; }, @@ -1195,11 +1195,11 @@ void main() { () { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - MethodChannel('flutter_blue_plus/methods'), - (methodCall) { - log.add(methodCall); + flutterBluePlus.channel, + (call) { + log.add(call); - return handler?.call(methodCall); + return handler?.call(call); }, ); }, From 22e8b12cc2f89de804e5598e1f572854fb37b03e Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 11:40:00 +0100 Subject: [PATCH 27/90] chore: remove pubspec from root --- pubspec.yaml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 pubspec.yaml diff --git a/pubspec.yaml b/pubspec.yaml deleted file mode 100644 index 3cd93451..00000000 --- a/pubspec.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: flutter_blue_plus -description: Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, and MacOS. -version: 1.32.12 -homepage: https://github.com/boskokg/flutter_blue_plus - -environment: - sdk: ">=2.15.1 <4.0.0" - flutter: ">=2.5.0" - -dependencies: - flutter: - sdk: flutter - -flutter: - plugin: - platforms: - android: - package: com.lib.flutter_blue_plus - pluginClass: FlutterBluePlusPlugin - ios: - pluginClass: FlutterBluePlusPlugin - macos: - pluginClass: FlutterBluePlusPlugin From 044fa0f81cf9e7ba6a6baccbea8be71c6f62e4ad Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 16:15:40 +0100 Subject: [PATCH 28/90] test: update method channel implementation --- .../src/method_channel_flutter_blue_plus.dart | 191 ++-- .../lib/src/scan/models/bm_scan_response.dart | 4 +- ...method_channel_flutter_blue_plus_test.dart | 887 +++++++++++++++++- 3 files changed, 953 insertions(+), 129 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index 0949c4af..42c1dc71 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -40,146 +40,140 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { final _calls = StreamController.broadcast(); MethodChannelFlutterBluePlus() { - channel.setMethodCallHandler( - (call) async { - _calls.add(call); - }, - ); + channel.setMethodCallHandler(handleMethodCall); } @override - Stream get onAdapterStateChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnAdapterStateChanged') { - yield BmBluetoothAdapterState.fromMap(call.arguments); - } - } + Stream get onAdapterStateChanged { + return _calls.stream.where((call) { + return call.method == 'OnAdapterStateChanged'; + }).map((call) { + return BmBluetoothAdapterState.fromMap(call.arguments); + }); } @override - Stream get onBondStateChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnBondStateChanged') { - yield BmBondStateResponse.fromMap(call.arguments); - } - } + Stream get onBondStateChanged { + return _calls.stream.where((call) { + return call.method == 'OnBondStateChanged'; + }).map((call) { + return BmBondStateResponse.fromMap(call.arguments); + }); } @override - Stream get onCharacteristicReceived async* { - await for (final call in _calls.stream) { - if (call.method == 'OnCharacteristicReceived') { - yield BmCharacteristicData.fromMap(call.arguments); - } - } + Stream get onCharacteristicReceived { + return _calls.stream.where((call) { + return call.method == 'OnCharacteristicReceived'; + }).map((call) { + return BmCharacteristicData.fromMap(call.arguments); + }); } @override - Stream get onCharacteristicWritten async* { - await for (final call in _calls.stream) { - if (call.method == 'OnCharacteristicWritten') { - yield BmCharacteristicData.fromMap(call.arguments); - } - } + Stream get onCharacteristicWritten { + return _calls.stream.where((call) { + return call.method == 'OnCharacteristicWritten'; + }).map((call) { + return BmCharacteristicData.fromMap(call.arguments); + }); } @override - Stream get onConnectionStateChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnConnectionStateChanged') { - yield BmConnectionStateResponse.fromMap(call.arguments); - } - } + Stream get onConnectionStateChanged { + return _calls.stream.where((call) { + return call.method == 'OnConnectionStateChanged'; + }).map((call) { + return BmConnectionStateResponse.fromMap(call.arguments); + }); } @override - Stream get onDescriptorRead async* { - await for (final call in _calls.stream) { - if (call.method == 'OnDescriptorRead') { - yield BmDescriptorData.fromMap(call.arguments); - } - } + Stream get onDescriptorRead { + return _calls.stream.where((call) { + return call.method == 'OnDescriptorRead'; + }).map((call) { + return BmDescriptorData.fromMap(call.arguments); + }); } @override - Stream get onDescriptorWritten async* { - await for (final call in _calls.stream) { - if (call.method == 'OnDescriptorWritten') { - yield BmDescriptorData.fromMap(call.arguments); - } - } + Stream get onDescriptorWritten { + return _calls.stream.where((call) { + return call.method == 'OnDescriptorWritten'; + }).map((call) { + return BmDescriptorData.fromMap(call.arguments); + }); } @override - Stream get onDetachedFromEngine async* { - await for (final call in _calls.stream) { - if (call.method == 'OnDetachedFromEngine') { - yield null; - } - } + Stream get onDetachedFromEngine { + return _calls.stream.where((call) { + return call.method == 'OnDetachedFromEngine'; + }); } @override - Stream get onDiscoveredServices async* { - await for (final call in _calls.stream) { - if (call.method == 'OnDiscoveredServices') { - yield BmDiscoverServicesResult.fromMap(call.arguments); - } - } + Stream get onDiscoveredServices { + return _calls.stream.where((call) { + return call.method == 'OnDiscoveredServices'; + }).map((call) { + return BmDiscoverServicesResult.fromMap(call.arguments); + }); } @override - Stream get onMtuChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnMtuChanged') { - yield BmMtuChangedResponse.fromMap(call.arguments); - } - } + Stream get onMtuChanged { + return _calls.stream.where((call) { + return call.method == 'OnMtuChanged'; + }).map((call) { + return BmMtuChangedResponse.fromMap(call.arguments); + }); } @override - Stream get onNameChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnNameChanged') { - yield BmNameChanged.fromMap(call.arguments); - } - } + Stream get onNameChanged { + return _calls.stream.where((call) { + return call.method == 'OnNameChanged'; + }).map((call) { + return BmNameChanged.fromMap(call.arguments); + }); } @override - Stream get onReadRssi async* { - await for (final call in _calls.stream) { - if (call.method == 'OnReadRssi') { - yield BmReadRssiResult.fromMap(call.arguments); - } - } + Stream get onReadRssi { + return _calls.stream.where((call) { + return call.method == 'OnReadRssi'; + }).map((call) { + return BmReadRssiResult.fromMap(call.arguments); + }); } @override - Stream get onScanResponse async* { - await for (final call in _calls.stream) { - if (call.method == 'OnScanResponse') { - yield BmScanResponse.fromMap(call.arguments); - } - } + Stream get onScanResponse { + return _calls.stream.where((call) { + return call.method == 'OnScanResponse'; + }).map((call) { + return BmScanResponse.fromMap(call.arguments); + }); } @override - Stream get onServicesReset async* { - await for (final call in _calls.stream) { - if (call.method == 'OnServicesReset') { - yield BmBluetoothDevice.fromMap(call.arguments); - } - } + Stream get onServicesReset { + return _calls.stream.where((call) { + return call.method == 'OnServicesReset'; + }).map((call) { + return BmBluetoothDevice.fromMap(call.arguments); + }); } @override - Stream get onTurnOnResponse async* { - await for (final call in _calls.stream) { - if (call.method == 'OnTurnOnResponse') { - yield BmTurnOnResponse.fromMap(call.arguments); - } - } + Stream get onTurnOnResponse { + return _calls.stream.where((call) { + return call.method == 'OnTurnOnResponse'; + }).map((call) { + return BmTurnOnResponse.fromMap(call.arguments); + }); } @override @@ -313,6 +307,13 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { return BmDevicesList.fromMap(result!); } + @visibleForTesting + Future handleMethodCall( + MethodCall call, + ) async { + _calls.add(call); + } + @override Future isSupported() async { final result = await channel.invokeMethod( diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart index 90ba85aa..c6053b1a 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart @@ -33,8 +33,8 @@ class BmScanResponse { Map toMap() { return { 'advertisements': - advertisements.map((advertisement) => advertisement.toMap()), - 'success': success, + advertisements.map((advertisement) => advertisement.toMap()).toList(), + 'success': success ? 1 : 0, 'error_code': errorCode, 'error_string': errorString, }; diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart index e236e873..39b821b2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart @@ -12,7 +12,830 @@ void main() { final flutterBluePlus = MethodChannelFlutterBluePlus(); final log = []; - Future? Function(MethodCall methodCall)? handler; + Future? Function(MethodCall call)? methodCallHandler; + + group( + 'onAdapterStateChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ).toMap(); + + expectLater( + flutterBluePlus.onAdapterStateChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnAdapterStateChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ).toMap(); + + expectLater( + flutterBluePlus.onAdapterStateChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnAdapterStateChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onBondStateChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmBondStateResponse( + remoteId: DeviceIdentifier(''), + bondState: BmBondStateEnum.none, + ).toMap(); + + expectLater( + flutterBluePlus.onBondStateChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnBondStateChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmBondStateResponse( + remoteId: DeviceIdentifier(''), + bondState: BmBondStateEnum.none, + ).toMap(); + + expectLater( + flutterBluePlus.onBondStateChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnBondStateChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onCharacteristicReceived', + () { + test( + 'deserializes the event', + () async { + final arguments = BmCharacteristicData( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onCharacteristicReceived.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnCharacteristicReceived', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmCharacteristicData( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onCharacteristicReceived, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnCharacteristicReceived', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onCharacteristicWritten', + () { + test( + 'deserializes the event', + () async { + final arguments = BmCharacteristicData( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onCharacteristicWritten.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnCharacteristicWritten', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmCharacteristicData( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onCharacteristicWritten, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnCharacteristicWritten', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onConnectionStateChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmConnectionStateResponse( + remoteId: DeviceIdentifier(''), + connectionState: BmConnectionStateEnum.disconnected, + ).toMap(); + + expectLater( + flutterBluePlus.onConnectionStateChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnConnectionStateChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmConnectionStateResponse( + remoteId: DeviceIdentifier(''), + connectionState: BmConnectionStateEnum.disconnected, + ).toMap(); + + expectLater( + flutterBluePlus.onConnectionStateChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnConnectionStateChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onDescriptorRead', + () { + test( + 'deserializes the event', + () async { + final arguments = BmDescriptorData( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDescriptorRead.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDescriptorRead', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmDescriptorData( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDescriptorRead, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDescriptorRead', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onDescriptorWritten', + () { + test( + 'deserializes the event', + () async { + final arguments = BmDescriptorData( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDescriptorWritten.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDescriptorWritten', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmDescriptorData( + remoteId: DeviceIdentifier(''), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDescriptorWritten, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDescriptorWritten', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onDetachedFromEngine', + () { + test( + 'handles the method call', + () async { + expectLater( + flutterBluePlus.onDetachedFromEngine, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDetachedFromEngine', + ), + ); + }, + ); + }, + ); + + group( + 'onDiscoveredServices', + () { + test( + 'deserializes the event', + () async { + final arguments = BmDiscoverServicesResult( + remoteId: DeviceIdentifier(''), + services: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDiscoveredServices.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDiscoveredServices', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmDiscoverServicesResult( + remoteId: DeviceIdentifier(''), + services: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDiscoveredServices, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDiscoveredServices', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onMtuChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmMtuChangedResponse( + remoteId: DeviceIdentifier(''), + mtu: 0, + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onMtuChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnMtuChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmMtuChangedResponse( + remoteId: DeviceIdentifier(''), + mtu: 0, + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onMtuChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnMtuChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onNameChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmNameChanged( + remoteId: DeviceIdentifier(''), + name: '', + ).toMap(); + + expectLater( + flutterBluePlus.onNameChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnNameChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmNameChanged( + remoteId: DeviceIdentifier(''), + name: '', + ).toMap(); + + expectLater( + flutterBluePlus.onNameChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnNameChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onReadRssi', + () { + test( + 'deserializes the event', + () async { + final arguments = BmReadRssiResult( + remoteId: DeviceIdentifier(''), + rssi: 0, + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onReadRssi.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnReadRssi', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmReadRssiResult( + remoteId: DeviceIdentifier(''), + rssi: 0, + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onReadRssi, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnReadRssi', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onScanResponse', + () { + test( + 'deserializes the event', + () async { + final arguments = BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onScanResponse.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnScanResponse', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onScanResponse, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnScanResponse', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onServicesReset', + () { + test( + 'deserializes the event', + () async { + final arguments = BmBluetoothDevice( + remoteId: DeviceIdentifier(''), + ).toMap(); + + expectLater( + flutterBluePlus.onServicesReset.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnServicesReset', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmBluetoothDevice( + remoteId: DeviceIdentifier(''), + ).toMap(); + + expectLater( + flutterBluePlus.onServicesReset, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnServicesReset', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onServicesReset', + () { + test( + 'deserializes the event', + () async { + final arguments = BmTurnOnResponse( + userAccepted: true, + ).toMap(); + + expectLater( + flutterBluePlus.onTurnOnResponse.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnTurnOnResponse', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmTurnOnResponse( + userAccepted: true, + ).toMap(); + + expectLater( + flutterBluePlus.onTurnOnResponse, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnTurnOnResponse', + arguments, + ), + ); + }, + ); + }, + ); group( 'clearGattCache', @@ -45,7 +868,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -53,7 +876,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -103,7 +926,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -111,7 +934,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -151,7 +974,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -159,7 +982,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -203,7 +1026,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -211,7 +1034,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -279,7 +1102,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -287,7 +1110,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -327,7 +1150,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -335,7 +1158,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -377,7 +1200,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result.toMap()); }; }, @@ -385,7 +1208,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -428,7 +1251,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result.toMap()); }; }, @@ -436,7 +1259,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -482,7 +1305,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result.toMap()); }; }, @@ -490,7 +1313,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -533,7 +1356,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result.toMap()); }; }, @@ -541,7 +1364,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -583,7 +1406,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result.toMap()); }; }, @@ -591,7 +1414,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -631,7 +1454,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -639,7 +1462,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -760,7 +1583,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -768,7 +1591,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -890,7 +1713,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -898,7 +1721,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -1089,7 +1912,7 @@ void main() { setUp( () { - handler = (call) { + methodCallHandler = (call) { return Future.value(result); }; }, @@ -1097,7 +1920,7 @@ void main() { tearDown( () { - handler = null; + methodCallHandler = null; }, ); @@ -1199,7 +2022,7 @@ void main() { (call) { log.add(call); - return handler?.call(call); + return methodCallHandler?.call(call); }, ); }, From a585953b47ab1b49d8d884fbc56c6f033a4cd630 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 16:50:59 +0100 Subject: [PATCH 29/90] refactor: migrate core package --- example/macos/Podfile.lock | 22 - example/pubspec.yaml | 21 - lib/src/bluetooth_msgs.dart | 861 ------------- lib/src/guid.dart | 92 -- packages/flutter_blue_plus/.gitignore | 29 + packages/flutter_blue_plus/.metadata | 10 + .../flutter_blue_plus/CHANGELOG.md | 2 + packages/flutter_blue_plus/LICENSE | 28 + packages/flutter_blue_plus/README.md | 1142 +++++++++++++++++ .../flutter_blue_plus/analysis_options.yaml | 1 + .../flutter_blue_plus/example}/.gitignore | 0 .../flutter_blue_plus/example}/.metadata | 0 .../example}/.vscode/settings.json | 0 .../flutter_blue_plus/example}/README.md | 0 .../example}/analysis_options.yaml | 0 .../example}/android/.gitignore | 0 .../example}/android/app/build.gradle | 0 .../android/app/src/debug/AndroidManifest.xml | 0 .../android/app/src/main/AndroidManifest.xml | 0 .../MainActivity.java | 0 .../res/drawable-v21/launch_background.xml | 0 .../main/res/drawable/launch_background.xml | 0 .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin .../app/src/main/res/values-night/styles.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../app/src/profile/AndroidManifest.xml | 0 .../example}/android/build.gradle | 0 .../example}/android/gradle.properties | 0 .../gradle/wrapper/gradle-wrapper.properties | 0 .../example}/android/settings.gradle | 0 .../flutter_blue_plus/example}/ios/.gitignore | 0 .../ios/Flutter/AppFrameworkInfo.plist | 0 .../example}/ios/Flutter/Debug.xcconfig | 0 .../example}/ios/Flutter/Release.xcconfig | 0 .../flutter_blue_plus/example}/ios/Podfile | 0 .../ios/Runner.xcodeproj/project.pbxproj | 0 .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/WorkspaceSettings.xcsettings | 0 .../xcshareddata/xcschemes/Runner.xcscheme | 0 .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/WorkspaceSettings.xcsettings | 0 .../example}/ios/Runner/AppDelegate.swift | 0 .../AppIcon.appiconset/Contents.json | 0 .../Icon-App-1024x1024@1x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@1x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@2x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@3x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@1x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@2x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@3x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@1x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@2x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@3x.png | Bin .../AppIcon.appiconset/Icon-App-60x60@2x.png | Bin .../AppIcon.appiconset/Icon-App-60x60@3x.png | Bin .../AppIcon.appiconset/Icon-App-76x76@1x.png | Bin .../AppIcon.appiconset/Icon-App-76x76@2x.png | Bin .../Icon-App-83.5x83.5@2x.png | Bin .../LaunchImage.imageset/Contents.json | 0 .../LaunchImage.imageset/LaunchImage.png | Bin .../LaunchImage.imageset/LaunchImage@2x.png | Bin .../LaunchImage.imageset/LaunchImage@3x.png | Bin .../LaunchImage.imageset/README.md | 0 .../Runner/Base.lproj/LaunchScreen.storyboard | 0 .../ios/Runner/Base.lproj/Main.storyboard | 0 .../example}/ios/Runner/Info.plist | 0 .../ios/Runner/Runner-Bridging-Header.h | 0 .../flutter_blue_plus/example}/lib/main.dart | 0 .../lib/screens/bluetooth_off_screen.dart | 0 .../example}/lib/screens/device_screen.dart | 0 .../example}/lib/screens/scan_screen.dart | 0 .../example}/lib/utils/extra.dart | 0 .../example}/lib/utils/snackbar.dart | 0 .../example}/lib/utils/utils.dart | 0 .../lib/widgets/characteristic_tile.dart | 0 .../example}/lib/widgets/descriptor_tile.dart | 0 .../lib/widgets/scan_result_tile.dart | 0 .../example}/lib/widgets/service_tile.dart | 0 .../lib/widgets/system_device_tile.dart | 0 .../example}/macos/.gitignore | 0 .../macos/Flutter/Flutter-Debug.xcconfig | 0 .../macos/Flutter/Flutter-Release.xcconfig | 0 .../Flutter/GeneratedPluginRegistrant.swift | 2 +- .../flutter_blue_plus/example}/macos/Podfile | 0 .../macos/Runner.xcodeproj/project.pbxproj | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/xcschemes/Runner.xcscheme | 0 .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../example}/macos/Runner/AppDelegate.swift | 0 .../AppIcon.appiconset/Contents.json | 0 .../AppIcon.appiconset/app_icon_1024.png | Bin .../AppIcon.appiconset/app_icon_128.png | Bin .../AppIcon.appiconset/app_icon_16.png | Bin .../AppIcon.appiconset/app_icon_256.png | Bin .../AppIcon.appiconset/app_icon_32.png | Bin .../AppIcon.appiconset/app_icon_512.png | Bin .../AppIcon.appiconset/app_icon_64.png | Bin .../macos/Runner/Base.lproj/MainMenu.xib | 0 .../macos/Runner/Configs/AppInfo.xcconfig | 0 .../macos/Runner/Configs/Debug.xcconfig | 0 .../macos/Runner/Configs/Release.xcconfig | 0 .../macos/Runner/Configs/Warnings.xcconfig | 0 .../macos/Runner/DebugProfile.entitlements | 0 .../example}/macos/Runner/Info.plist | 0 .../macos/Runner/MainFlutterWindow.swift | 0 .../macos/Runner/Release.entitlements | 0 .../macos/RunnerTests/RunnerTests.swift | 0 .../flutter_blue_plus/example/pubspec.lock | 107 ++ .../flutter_blue_plus/example/pubspec.yaml | 29 + .../lib}/flutter_blue_plus.dart | 8 +- .../lib}/src/bluetooth_characteristic.dart | 35 +- .../lib}/src/bluetooth_descriptor.dart | 26 +- .../lib}/src/bluetooth_device.dart | 83 +- .../lib}/src/bluetooth_events.dart | 60 +- .../lib}/src/bluetooth_service.dart | 2 +- .../lib}/src/bluetooth_utils.dart | 4 + .../lib}/src/flutter_blue_plus.dart | 233 ++-- .../flutter_blue_plus/lib}/src/utils.dart | 77 +- packages/flutter_blue_plus/pubspec.yaml | 38 + .../FlutterBluePlusPlugin.java | 4 +- 127 files changed, 1554 insertions(+), 1362 deletions(-) delete mode 100644 example/macos/Podfile.lock delete mode 100644 example/pubspec.yaml delete mode 100644 lib/src/bluetooth_msgs.dart delete mode 100644 lib/src/guid.dart create mode 100644 packages/flutter_blue_plus/.gitignore create mode 100644 packages/flutter_blue_plus/.metadata rename CHANGELOG.md => packages/flutter_blue_plus/CHANGELOG.md (99%) create mode 100644 packages/flutter_blue_plus/LICENSE create mode 100644 packages/flutter_blue_plus/README.md create mode 100644 packages/flutter_blue_plus/analysis_options.yaml rename {example => packages/flutter_blue_plus/example}/.gitignore (100%) rename {example => packages/flutter_blue_plus/example}/.metadata (100%) rename {example => packages/flutter_blue_plus/example}/.vscode/settings.json (100%) rename {example => packages/flutter_blue_plus/example}/README.md (100%) rename {example => packages/flutter_blue_plus/example}/analysis_options.yaml (100%) rename {example => packages/flutter_blue_plus/example}/android/.gitignore (100%) rename {example => packages/flutter_blue_plus/example}/android/app/build.gradle (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/debug/AndroidManifest.xml (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/AndroidManifest.xml (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/drawable-v21/launch_background.xml (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/drawable/launch_background.xml (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/mipmap-hdpi/ic_launcher.png (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/mipmap-mdpi/ic_launcher.png (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/values-night/styles.xml (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/main/res/values/styles.xml (100%) rename {example => packages/flutter_blue_plus/example}/android/app/src/profile/AndroidManifest.xml (100%) rename {example => packages/flutter_blue_plus/example}/android/build.gradle (100%) rename {example => packages/flutter_blue_plus/example}/android/gradle.properties (100%) rename {example => packages/flutter_blue_plus/example}/android/gradle/wrapper/gradle-wrapper.properties (100%) rename {example => packages/flutter_blue_plus/example}/android/settings.gradle (100%) rename {example => packages/flutter_blue_plus/example}/ios/.gitignore (100%) rename {example => packages/flutter_blue_plus/example}/ios/Flutter/AppFrameworkInfo.plist (100%) rename {example => packages/flutter_blue_plus/example}/ios/Flutter/Debug.xcconfig (100%) rename {example => packages/flutter_blue_plus/example}/ios/Flutter/Release.xcconfig (100%) rename {example => packages/flutter_blue_plus/example}/ios/Podfile (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner.xcodeproj/project.pbxproj (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner.xcworkspace/contents.xcworkspacedata (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/AppDelegate.swift (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Base.lproj/LaunchScreen.storyboard (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Base.lproj/Main.storyboard (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Info.plist (100%) rename {example => packages/flutter_blue_plus/example}/ios/Runner/Runner-Bridging-Header.h (100%) rename {example => packages/flutter_blue_plus/example}/lib/main.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/screens/bluetooth_off_screen.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/screens/device_screen.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/screens/scan_screen.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/utils/extra.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/utils/snackbar.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/utils/utils.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/widgets/characteristic_tile.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/widgets/descriptor_tile.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/widgets/scan_result_tile.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/widgets/service_tile.dart (100%) rename {example => packages/flutter_blue_plus/example}/lib/widgets/system_device_tile.dart (100%) rename {example => packages/flutter_blue_plus/example}/macos/.gitignore (100%) rename {example => packages/flutter_blue_plus/example}/macos/Flutter/Flutter-Debug.xcconfig (100%) rename {example => packages/flutter_blue_plus/example}/macos/Flutter/Flutter-Release.xcconfig (100%) rename {example => packages/flutter_blue_plus/example}/macos/Flutter/GeneratedPluginRegistrant.swift (88%) rename {example => packages/flutter_blue_plus/example}/macos/Podfile (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner.xcodeproj/project.pbxproj (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner.xcworkspace/contents.xcworkspacedata (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/AppDelegate.swift (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Base.lproj/MainMenu.xib (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Configs/AppInfo.xcconfig (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Configs/Debug.xcconfig (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Configs/Release.xcconfig (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Configs/Warnings.xcconfig (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/DebugProfile.entitlements (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Info.plist (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/MainFlutterWindow.swift (100%) rename {example => packages/flutter_blue_plus/example}/macos/Runner/Release.entitlements (100%) rename {example => packages/flutter_blue_plus/example}/macos/RunnerTests/RunnerTests.swift (100%) create mode 100644 packages/flutter_blue_plus/example/pubspec.lock create mode 100644 packages/flutter_blue_plus/example/pubspec.yaml rename {lib => packages/flutter_blue_plus/lib}/flutter_blue_plus.dart (63%) rename {lib => packages/flutter_blue_plus/lib}/src/bluetooth_characteristic.dart (89%) rename {lib => packages/flutter_blue_plus/lib}/src/bluetooth_descriptor.dart (83%) rename {lib => packages/flutter_blue_plus/lib}/src/bluetooth_device.dart (88%) rename {lib => packages/flutter_blue_plus/lib}/src/bluetooth_events.dart (76%) rename {lib => packages/flutter_blue_plus/lib}/src/bluetooth_service.dart (94%) rename {lib => packages/flutter_blue_plus/lib}/src/bluetooth_utils.dart (95%) rename {lib => packages/flutter_blue_plus/lib}/src/flutter_blue_plus.dart (82%) rename {lib => packages/flutter_blue_plus/lib}/src/utils.dart (87%) create mode 100644 packages/flutter_blue_plus/pubspec.yaml diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock deleted file mode 100644 index c6166877..00000000 --- a/example/macos/Podfile.lock +++ /dev/null @@ -1,22 +0,0 @@ -PODS: - - flutter_blue_plus (0.0.1): - - FlutterMacOS - - FlutterMacOS (1.0.0) - -DEPENDENCIES: - - flutter_blue_plus (from `Flutter/ephemeral/.symlinks/plugins/flutter_blue_plus/macos`) - - FlutterMacOS (from `Flutter/ephemeral`) - -EXTERNAL SOURCES: - flutter_blue_plus: - :path: Flutter/ephemeral/.symlinks/plugins/flutter_blue_plus/macos - FlutterMacOS: - :path: Flutter/ephemeral - -SPEC CHECKSUMS: - flutter_blue_plus: e2868679021f19d12a8c0c58a33f1df66ec7fa6a - FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 - -PODFILE CHECKSUM: b5ff078e9cf81bae88fdc8e0ce3668e57b68e9b6 - -COCOAPODS: 1.14.3 diff --git a/example/pubspec.yaml b/example/pubspec.yaml deleted file mode 100644 index 8794903a..00000000 --- a/example/pubspec.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: flutter_blue_plus_example -description: Demonstrates how to use the flutter_blue_plus plugin. - -# The following line prevents the package from being accidentally published to -# pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' - -environment: - sdk: ">=2.15.1 <3.0.0" - -dependencies: - flutter: - sdk: flutter - - flutter_blue_plus: - # Note: We use a path dependency because the example app & plugin are bundled together. - # In *your* app you should use ^1.17.3 or similar - path: ../ - -flutter: - uses-material-design: true diff --git a/lib/src/bluetooth_msgs.dart b/lib/src/bluetooth_msgs.dart deleted file mode 100644 index 1e80a2b4..00000000 --- a/lib/src/bluetooth_msgs.dart +++ /dev/null @@ -1,861 +0,0 @@ -part of flutter_blue_plus; - -enum BmAdapterStateEnum { - unknown, // 0 - unavailable, // 1 - unauthorized, // 2 - turningOn, // 3 - on, // 4 - turningOff, // 5 - off, // 6 -} - -class BmBluetoothAdapterState { - BmAdapterStateEnum adapterState; - - BmBluetoothAdapterState({required this.adapterState}); - - Map toMap() { - final Map data = {}; - data['adapter_state'] = adapterState.index; - return data; - } - - factory BmBluetoothAdapterState.fromMap(Map json) { - return BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.values[json['adapter_state']], - ); - } -} - -class BmMsdFilter { - int manufacturerId; - List? data; - List? mask; - BmMsdFilter(this.manufacturerId, this.data, this.mask); - Map toMap() { - final Map map = {}; - map['manufacturer_id'] = manufacturerId; - map['data'] = _hexEncode(data ?? []); - map['mask'] = _hexEncode(mask ?? []); - return map; - } -} - -class BmServiceDataFilter { - Guid service; - List data; - List mask; - BmServiceDataFilter(this.service, this.data, this.mask); - Map toMap() { - final Map map = {}; - map['service'] = service.str; - map['data'] = _hexEncode(data); - map['mask'] = _hexEncode(mask); - return map; - } -} - -class BmScanSettings { - final List withServices; - final List withRemoteIds; - final List withNames; - final List withKeywords; - final List withMsd; - final List withServiceData; - final bool continuousUpdates; - final int continuousDivisor; - final bool androidLegacy; - final int androidScanMode; - final bool androidUsesFineLocation; - - BmScanSettings({ - required this.withServices, - required this.withRemoteIds, - required this.withNames, - required this.withKeywords, - required this.withMsd, - required this.withServiceData, - required this.continuousUpdates, - required this.continuousDivisor, - required this.androidLegacy, - required this.androidScanMode, - required this.androidUsesFineLocation, - }); - - Map toMap() { - final Map data = {}; - data['with_services'] = withServices.map((s) => s.str).toList(); - data['with_remote_ids'] = withRemoteIds; - data['with_names'] = withNames; - data['with_keywords'] = withKeywords; - data['with_msd'] = withMsd.map((d) => d.toMap()).toList(); - data['with_service_data'] = withServiceData.map((d) => d.toMap()).toList(); - data['continuous_updates'] = continuousUpdates; - data['continuous_divisor'] = continuousDivisor; - data['android_legacy'] = androidLegacy; - data['android_scan_mode'] = androidScanMode; - data['android_uses_fine_location'] = androidUsesFineLocation; - return data; - } -} - -class BmScanAdvertisement { - final DeviceIdentifier remoteId; - final String? platformName; - final String? advName; - final bool connectable; - final int? txPowerLevel; - final int? appearance; // not supported on iOS / macOS - final Map> manufacturerData; - final Map> serviceData; - final List serviceUuids; - final int rssi; - - BmScanAdvertisement({ - required this.remoteId, - required this.platformName, - required this.advName, - required this.connectable, - required this.txPowerLevel, - required this.appearance, - required this.manufacturerData, - required this.serviceData, - required this.serviceUuids, - required this.rssi, - }); - - factory BmScanAdvertisement.fromMap(Map json) { - // Get raw data - var rawManufacturerData = json['manufacturer_data'] ?? {}; - var rawServiceData = json['service_data'] ?? {}; - var rawServiceUuids = json['service_uuids'] ?? []; - - // Cast the data to the right type - Map> manufacturerData = {}; - for (var key in rawManufacturerData.keys) { - manufacturerData[key] = _hexDecode(rawManufacturerData[key]); - } - - // Cast the data to the right type - Map> serviceData = {}; - for (var key in rawServiceData.keys) { - serviceData[Guid(key)] = _hexDecode(rawServiceData[key]); - } - - // Cast the data to the right type - List serviceUuids = []; - for (var val in rawServiceUuids) { - serviceUuids.add(Guid(val)); - } - - return BmScanAdvertisement( - remoteId: DeviceIdentifier(json['remote_id']), - platformName: json['platform_name'], - advName: json['adv_name'], - connectable: json['connectable'] != null ? json['connectable'] != 0 : false, - txPowerLevel: json['tx_power_level'], - appearance: json['appearance'], - manufacturerData: manufacturerData, - serviceData: serviceData, - serviceUuids: serviceUuids, - rssi: json['rssi'] != null ? json['rssi'] : 0, - ); - } -} - -class BmScanResponse { - final List advertisements; - final bool success; - final int errorCode; - final String errorString; - - BmScanResponse({ - required this.advertisements, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmScanResponse.fromMap(Map json) { - List advertisements = []; - for (var item in json['advertisements']) { - advertisements.add(BmScanAdvertisement.fromMap(item)); - } - - bool success = json['success'] == null || json['success'] != 0; - - return BmScanResponse( - advertisements: advertisements, - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : "", - ); - } -} - -class BmConnectRequest { - DeviceIdentifier remoteId; - bool autoConnect; - - BmConnectRequest({ - required this.remoteId, - required this.autoConnect, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['auto_connect'] = autoConnect ? 1 : 0; - return data; - } -} - -class BmBluetoothDevice { - DeviceIdentifier remoteId; - String? platformName; - - BmBluetoothDevice({ - required this.remoteId, - required this.platformName, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['platform_name'] = platformName; - return data; - } - - factory BmBluetoothDevice.fromMap(Map json) { - return BmBluetoothDevice( - remoteId: DeviceIdentifier(json['remote_id']), - platformName: json['platform_name'], - ); - } -} - -class BmNameChanged { - DeviceIdentifier remoteId; - String name; - - BmNameChanged({ - required this.remoteId, - required this.name, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['name'] = name; - return data; - } - - factory BmNameChanged.fromMap(Map json) { - return BmNameChanged( - remoteId: DeviceIdentifier(json['remote_id']), - name: json['name'], - ); - } -} - -class BmBluetoothService { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - bool isPrimary; - List characteristics; - List includedServices; - - BmBluetoothService({ - required this.serviceUuid, - required this.remoteId, - required this.isPrimary, - required this.characteristics, - required this.includedServices, - }); - - factory BmBluetoothService.fromMap(Map json) { - // convert characteristics - List chrs = []; - for (var v in json['characteristics']) { - chrs.add(BmBluetoothCharacteristic.fromMap(v)); - } - - // convert services - List svcs = []; - for (var v in json['included_services']) { - svcs.add(BmBluetoothService.fromMap(v)); - } - - return BmBluetoothService( - serviceUuid: Guid(json['service_uuid']), - remoteId: DeviceIdentifier(json['remote_id']), - isPrimary: json['is_primary'] != 0, - characteristics: chrs, - includedServices: svcs, - ); - } -} - -class BmBluetoothCharacteristic { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - List descriptors; - BmCharacteristicProperties properties; - - BmBluetoothCharacteristic({ - required this.remoteId, - required this.serviceUuid, - required this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptors, - required this.properties, - }); - - factory BmBluetoothCharacteristic.fromMap(Map json) { - // convert descriptors - List descs = []; - for (var v in json['descriptors']) { - descs.add(BmBluetoothDescriptor.fromMap(v)); - } - - return BmBluetoothCharacteristic( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptors: descs, - properties: BmCharacteristicProperties.fromMap(json['properties']), - ); - } -} - -class BmBluetoothDescriptor { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - - BmBluetoothDescriptor({ - required this.remoteId, - required this.serviceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - }); - - factory BmBluetoothDescriptor.fromMap(Map json) { - return BmBluetoothDescriptor( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - ); - } -} - -class BmCharacteristicProperties { - bool broadcast; - bool read; - bool writeWithoutResponse; - bool write; - bool notify; - bool indicate; - bool authenticatedSignedWrites; - bool extendedProperties; - bool notifyEncryptionRequired; - bool indicateEncryptionRequired; - - BmCharacteristicProperties({ - required this.broadcast, - required this.read, - required this.writeWithoutResponse, - required this.write, - required this.notify, - required this.indicate, - required this.authenticatedSignedWrites, - required this.extendedProperties, - required this.notifyEncryptionRequired, - required this.indicateEncryptionRequired, - }); - - factory BmCharacteristicProperties.fromMap(Map json) { - return BmCharacteristicProperties( - broadcast: json['broadcast'] != 0, - read: json['read'] != 0, - writeWithoutResponse: json['write_without_response'] != 0, - write: json['write'] != 0, - notify: json['notify'] != 0, - indicate: json['indicate'] != 0, - authenticatedSignedWrites: json['authenticated_signed_writes'] != 0, - extendedProperties: json['extended_properties'] != 0, - notifyEncryptionRequired: json['notify_encryption_required'] != 0, - indicateEncryptionRequired: json['indicate_encryption_required'] != 0, - ); - } -} - -class BmDiscoverServicesResult { - final DeviceIdentifier remoteId; - final List services; - final bool success; - final int errorCode; - final String errorString; - - BmDiscoverServicesResult({ - required this.remoteId, - required this.services, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmDiscoverServicesResult.fromMap(Map json) { - return BmDiscoverServicesResult( - remoteId: DeviceIdentifier(json['remote_id']), - services: (json['services'] as List) - .map((e) => BmBluetoothService.fromMap(e as Map)) - .toList(), - success: json['success'] != 0, - errorCode: json['error_code'], - errorString: json['error_string'], - ); - } -} - -class BmReadCharacteristicRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - - BmReadCharacteristicRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['service_uuid'] = serviceUuid.str; - data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['characteristic_uuid'] = characteristicUuid.str; - return data; - } -} - -class BmCharacteristicData { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final List value; - final bool success; - final int errorCode; - final String errorString; - - BmCharacteristicData({ - required this.remoteId, - required this.serviceUuid, - required this.secondaryServiceUuid, - required this.characteristicUuid, - required this.value, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmCharacteristicData.fromMap(Map json) { - return BmCharacteristicData( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, - characteristicUuid: Guid(json['characteristic_uuid']), - value: _hexDecode(json['value']), - success: json['success'] != 0, - errorCode: json['error_code'], - errorString: json['error_string'], - ); - } -} - -class BmReadDescriptorRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - - BmReadDescriptorRequest({ - required this.remoteId, - required this.serviceUuid, - required this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['service_uuid'] = serviceUuid.str; - data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['characteristic_uuid'] = characteristicUuid.str; - data['descriptor_uuid'] = descriptorUuid.str; - return data; - } -} - -enum BmWriteType { - withResponse, - withoutResponse, -} - -class BmWriteCharacteristicRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final BmWriteType writeType; - final bool allowLongWrite; - final List value; - - BmWriteCharacteristicRequest({ - required this.remoteId, - required this.serviceUuid, - required this.secondaryServiceUuid, - required this.characteristicUuid, - required this.writeType, - required this.allowLongWrite, - required this.value, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['service_uuid'] = serviceUuid.str; - data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['characteristic_uuid'] = characteristicUuid.str; - data['write_type'] = writeType.index; - data['allow_long_write'] = allowLongWrite ? 1 : 0; - data['value'] = _hexEncode(value); - return data; - } -} - -class BmWriteDescriptorRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - final List value; - - BmWriteDescriptorRequest({ - required this.remoteId, - required this.serviceUuid, - required this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - required this.value, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['service_uuid'] = serviceUuid.str; - data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['characteristic_uuid'] = characteristicUuid.str; - data['descriptor_uuid'] = descriptorUuid.str; - data['value'] = _hexEncode(value); - return data; - } -} - -class BmDescriptorData { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - final List value; - final bool success; - final int errorCode; - final String errorString; - - BmDescriptorData({ - required this.remoteId, - required this.serviceUuid, - required this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - required this.value, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmDescriptorData.fromMap(Map json) { - return BmDescriptorData( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - value: _hexDecode(json['value']), - success: json['success'] != 0, - errorCode: json['error_code'], - errorString: json['error_string'], - ); - } -} - -class BmSetNotifyValueRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final bool forceIndications; - final bool enable; - - BmSetNotifyValueRequest({ - required this.remoteId, - required this.serviceUuid, - required this.secondaryServiceUuid, - required this.characteristicUuid, - required this.forceIndications, - required this.enable, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['service_uuid'] = serviceUuid.str; - data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['characteristic_uuid'] = characteristicUuid.str; - data['force_indications'] = forceIndications; - data['enable'] = enable; - return data; - } -} - -enum BmConnectionStateEnum { - disconnected, // 0 - connected, // 1 -} - -class BmConnectionStateResponse { - final DeviceIdentifier remoteId; - final BmConnectionStateEnum connectionState; - final int? disconnectReasonCode; - final String? disconnectReasonString; - - BmConnectionStateResponse({ - required this.remoteId, - required this.connectionState, - required this.disconnectReasonCode, - required this.disconnectReasonString, - }); - - factory BmConnectionStateResponse.fromMap(Map json) { - return BmConnectionStateResponse( - remoteId: DeviceIdentifier(json['remote_id']), - connectionState: BmConnectionStateEnum.values[json['connection_state'] as int], - disconnectReasonCode: json['disconnect_reason_code'], - disconnectReasonString: json['disconnect_reason_string'], - ); - } -} - -class BmDevicesList { - final List devices; - - BmDevicesList({required this.devices}); - - factory BmDevicesList.fromMap(Map json) { - // convert to BmBluetoothDevice - List devices = []; - for (var i = 0; i < json['devices'].length; i++) { - devices.add(BmBluetoothDevice.fromMap(json['devices'][i])); - } - return BmDevicesList(devices: devices); - } -} - -class BmMtuChangeRequest { - final DeviceIdentifier remoteId; - final int mtu; - - BmMtuChangeRequest({required this.remoteId, required this.mtu}); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['mtu'] = mtu; - return data; - } -} - -class BmMtuChangedResponse { - final DeviceIdentifier remoteId; - final int mtu; - final bool success; - final int errorCode; - final String errorString; - - BmMtuChangedResponse({ - required this.remoteId, - required this.mtu, - this.success = true, - this.errorCode = 0, - this.errorString = "", - }); - - factory BmMtuChangedResponse.fromMap(Map json) { - return BmMtuChangedResponse( - remoteId: DeviceIdentifier(json['remote_id']), - mtu: json['mtu'], - success: json['success'] != 0, - errorCode: json['error_code'], - errorString: json['error_string'], - ); - } - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['mtu'] = mtu; - data['success'] = success ? 1 : 0; - data['error_code'] = errorCode; - data['error_string'] = errorString; - return data; - } -} - -class BmReadRssiResult { - final DeviceIdentifier remoteId; - final int rssi; - final bool success; - final int errorCode; - final String errorString; - - BmReadRssiResult({ - required this.remoteId, - required this.rssi, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmReadRssiResult.fromMap(Map json) { - return BmReadRssiResult( - remoteId: DeviceIdentifier(json['remote_id']), - rssi: json['rssi'], - success: json['success'] != 0, - errorCode: json['error_code'], - errorString: json['error_string'], - ); - } -} - -enum BmConnectionPriorityEnum { - balanced, // 0 - high, // 1 - lowPower, // 2 -} - -class BmConnectionPriorityRequest { - final DeviceIdentifier remoteId; - final BmConnectionPriorityEnum connectionPriority; - - BmConnectionPriorityRequest({ - required this.remoteId, - required this.connectionPriority, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['connection_priority'] = connectionPriority.index; - return data; - } -} - -class BmPreferredPhy { - final DeviceIdentifier remoteId; - final int txPhy; - final int rxPhy; - final int phyOptions; - - BmPreferredPhy({ - required this.remoteId, - required this.txPhy, - required this.rxPhy, - required this.phyOptions, - }); - - Map toMap() { - final Map data = {}; - data['remote_id'] = remoteId.str; - data['tx_phy'] = txPhy; - data['rx_phy'] = rxPhy; - data['phy_options'] = phyOptions; - return data; - } - - factory BmPreferredPhy.fromMap(Map json) { - return BmPreferredPhy( - remoteId: DeviceIdentifier(json['remote_id']), - txPhy: json['tx_phy'], - rxPhy: json['rx_phy'], - phyOptions: json['phy_options'], - ); - } -} - -enum BmBondStateEnum { - none, // 0 - bonding, // 1 - bonded, // 2 -} - -class BmBondStateResponse { - final DeviceIdentifier remoteId; - final BmBondStateEnum bondState; - final BmBondStateEnum? prevState; - - BmBondStateResponse({ - required this.remoteId, - required this.bondState, - required this.prevState, - }); - - factory BmBondStateResponse.fromMap(Map json) { - return BmBondStateResponse( - remoteId: DeviceIdentifier(json['remote_id']), - bondState: BmBondStateEnum.values[json['bond_state']], - prevState: json['prev_state'] != null ? BmBondStateEnum.values[json['prev_state']] : null, - ); - } -} - -// BmTurnOnResponse -class BmTurnOnResponse { - bool userAccepted; - - BmTurnOnResponse({ - required this.userAccepted, - }); - - factory BmTurnOnResponse.fromMap(Map json) { - return BmTurnOnResponse( - userAccepted: json['user_accepted'], - ); - } -} - -// random number defined by flutter blue plus. -// Ideally it should not conflict with iOS or Android error codes. -int bmUserCanceledErrorCode = 23789258; diff --git a/lib/src/guid.dart b/lib/src/guid.dart deleted file mode 100644 index 5bad07b7..00000000 --- a/lib/src/guid.dart +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. -// All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -part of flutter_blue_plus; - -// Supports 16-bit, 32-bit, or 128-bit UUIDs -class Guid { - final List bytes; - - Guid.empty() : bytes = List.filled(16, 0); - - Guid.fromBytes(this.bytes) : assert(_checkLen(bytes.length), 'GUID must be 16, 32, or 128 bit.'); - - Guid.fromString(String input) : bytes = _fromString(input); - - Guid(String input) : bytes = _fromString(input); - - static List _fromString(String input) { - if (input.isEmpty) { - return List.filled(16, 0); - } - - input = input.replaceAll('-', ''); - - List? bytes = _tryHexDecode(input); - if (bytes == null) { - throw FormatException("GUID not hex format: $input"); - } - - _checkLen(bytes.length); - - return bytes; - } - - static bool _checkLen(int len) { - if (!(len == 16 || len == 4 || len == 2)) { - throw FormatException("GUID must be 16, 32, or 128 bit, yours: ${len * 8}-bit"); - } - return true; - } - - // 128-bit representation - String get str128 { - if (bytes.length == 2) { - // 16-bit uuid - return '0000${_hexEncode(bytes)}-0000-1000-8000-00805f9b34fb'.toLowerCase(); - } - if (bytes.length == 4) { - // 32-bit uuid - return '${_hexEncode(bytes)}-0000-1000-8000-00805f9b34fb'.toLowerCase(); - } - // 128-bit uuid - String one = _hexEncode(bytes.sublist(0, 4)); - String two = _hexEncode(bytes.sublist(4, 6)); - String three = _hexEncode(bytes.sublist(6, 8)); - String four = _hexEncode(bytes.sublist(8, 10)); - String five = _hexEncode(bytes.sublist(10, 16)); - return "$one-$two-$three-$four-$five".toLowerCase(); - } - - // shortest representation - String get str { - bool starts = str128.startsWith('0000'); - bool ends = str128.contains('-0000-1000-8000-00805f9b34fb'); - if (starts && ends) { - // 16-bit - return str128.substring(4, 8); - } - if (ends) { - // 32-bit - return str128.substring(0, 8); - } - // 128-bit - return str128; - } - - @override - String toString() => str; - - @override - operator ==(other) => other is Guid && hashCode == other.hashCode; - - @override - int get hashCode => str128.hashCode; - - @Deprecated('use str128 instead') - String get uuid128 => str128; - - @Deprecated('use str instead') - String get uuid => str; -} diff --git a/packages/flutter_blue_plus/.gitignore b/packages/flutter_blue_plus/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/flutter_blue_plus/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/packages/flutter_blue_plus/.metadata b/packages/flutter_blue_plus/.metadata new file mode 100644 index 00000000..3bb479b8 --- /dev/null +++ b/packages/flutter_blue_plus/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" + channel: "beta" + +project_type: package diff --git a/CHANGELOG.md b/packages/flutter_blue_plus/CHANGELOG.md similarity index 99% rename from CHANGELOG.md rename to packages/flutter_blue_plus/CHANGELOG.md index bccc790f..fb2d1a23 100644 --- a/CHANGELOG.md +++ b/packages/flutter_blue_plus/CHANGELOG.md @@ -1,3 +1,5 @@ +## 1.33.0 +* **[Improve]** move Android, iOS, macOS implementations to federated packages ## 1.32.12 * **[Fix]** Android: further improve `disconnect(queue:false)` reliability diff --git a/packages/flutter_blue_plus/LICENSE b/packages/flutter_blue_plus/LICENSE new file mode 100644 index 00000000..5341ca7c --- /dev/null +++ b/packages/flutter_blue_plus/LICENSE @@ -0,0 +1,28 @@ +Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger, Thomas Clark. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Buffalo PC Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus/README.md b/packages/flutter_blue_plus/README.md new file mode 100644 index 00000000..deb42558 --- /dev/null +++ b/packages/flutter_blue_plus/README.md @@ -0,0 +1,1142 @@ +[![pub package](https://img.shields.io/pub/v/flutter_blue_plus.svg)](https://pub.dartlang.org/packages/flutter_blue_plus) +[![Chat](https://img.shields.io/discord/634853295160033301.svg?style=flat-square&colorB=758ED3)](https://discord.gg/Yk5Efra) + +
+

+FlutterBlue +

+

+ +**Note: this plugin is continuous work from [FlutterBlue](https://github.com/pauldemarco/flutter_blue).** + +Migrating from [FlutterBlue](https://github.com/pauldemarco/flutter_blue)? See [Migration Guide](MIGRATION.md) + +## Contents + +- [Introduction](#introduction) +- [Usage](#usage) +- [Getting Started](#getting-started) +- [Using Ble in App Background](#using-ble-in-app-background) +- [Reference](#reference) +- [Debugging](#debugging) +- [Mocking](#mocking) +- [Common Problems](#common-problems) + +## Introduction + +FlutterBluePlus is a Bluetooth Low Energy plugin for [Flutter](https://flutter.dev). + +It supports BLE Central Role only (most common). + +If you need BLE Peripheral Role, you should check out [FlutterBlePeripheral](https://pub.dev/packages/flutter_ble_peripheral). + +## Tutorial + +If you are new to Bluetooth, you should start by reading BLE tutorials. +* [Novel Bits BLE Tutorial](https://novelbits.io/bluetooth-low-energy-ble-complete-guide/) +* [All About Circuits BLE Tutorial](https://www.allaboutcircuits.com/technical-articles/exploring-the-basics-of-bluetooth-low-energy-a-beginners-guide-to-ble/) +* [Embetronicx BLE Tutorial](https://embetronicx.com/tutorials/tech_devices/bluetooth-low-energy-ble-introduction-part-1/) + +## ❗ Bluetooth Classic is not supported ❗ + + i.e. **Arduino HC-05 & HC-06,** speakers, headphones, mice, keyboards, gamepads, and more are **not** supported. These all use Bluetooth Classic. + + Also, iBeacons are **_not_** supported on iOS. Apple requires you to use CoreLocation. + +## Cross-Platform Bluetooth Low Energy + +FlutterBluePlus supports nearly every feature on all supported platforms: iOS, macOS, Android. + +FlutterBluePlus was written to be simple, robust, and easy to understand. + +## No Dependencies + +FlutterBluePlus has zero dependencies besides Flutter, Android, iOS, and macOS themselves. + +This makes FlutterBluePlus very stable, and easy to maintain. + +## Other BLE Libraries + +These other libraries are worth considering. They support all platforms, but fewer features. + +- [bluetooth_low_energy](https://pub.dev/packages/bluetooth_low_energy) +- [universal_ble](https://pub.dev/packages/universal_ble) +- [quick_blue](https://pub.dev/packages/quick_blue) + +## ⭐ Stars ⭐ + +Please star this repo & on [pub.dev](https://pub.dev/packages/flutter_blue_plus). We all benefit from having a larger community. + +## Discord 💬 + +[![Chat](https://img.shields.io/discord/634853295160033301.svg?style=flat-square&colorB=758ED3)](https://discord.gg/Yk5Efra) There is a community Discord server. ([Link](https://discord.gg/Yk5Efra)) + +## Example + +FlutterBluePlus has a beautiful example app, useful to debug issues. + +``` +cd ./example +flutter run +``` + +

+FlutterBlue +

+ +## Usage + +### 🔥 Error Handling 🔥 + +Flutter Blue Plus takes error handling seriously. + +Every error returned by the native platform is checked and thrown as an exception where appropriate. See [Reference](#reference) for a list of throwable functions. + +**Streams:** Streams returned by FlutterBluePlus never emit any errors and never close. There's no need to handle `onError` or `onDone` for `stream.listen(...)`. The one exception is `FlutterBluePlus.scanResults`, which you should handle `onError`. + +--- + +### Set Log Level + +```dart +// if your terminal doesn't support color you'll see annoying logs like `\x1B[1;35m` +FlutterBluePlus.setLogLevel(LogLevel.verbose, color:false) +``` + +Setting `LogLevel.verbose` shows *all* data in and out. + +⚫ = function name + +🟣 = args to platform + +🟡 = data from platform + +Screenshot 2023-07-27 at 4 53 08 AM + + +### Bluetooth On & Off + +**Note:** On iOS, a "*This app would like to use Bluetooth*" system dialogue appears on first call to any FlutterBluePlus method. + +```dart +// first, check if bluetooth is supported by your hardware +// Note: The platform is initialized on the first call to any FlutterBluePlus method. +if (await FlutterBluePlus.isSupported == false) { + print("Bluetooth not supported by this device"); + return; +} + +// handle bluetooth on & off +// note: for iOS the initial state is typically BluetoothAdapterState.unknown +// note: if you have permissions issues you will get stuck at BluetoothAdapterState.unauthorized +var subscription = FlutterBluePlus.adapterState.listen((BluetoothAdapterState state) { + print(state); + if (state == BluetoothAdapterState.on) { + // usually start scanning, connecting, etc + } else { + // show an error to the user, etc + } +}); + +// turn on bluetooth ourself if we can +// for iOS, the user controls bluetooth enable/disable +if (Platform.isAndroid) { + await FlutterBluePlus.turnOn(); +} + +// cancel to prevent duplicate listeners +subscription.cancel(); +``` + +### Scan for devices + +If your device is not found, see [Common Problems](#common-problems). + +**Note:** It is recommended to set scan filters to reduce main thread & platform channel usage. + +```dart +// listen to scan results +// Note: `onScanResults` only returns live scan results, i.e. during scanning. Use +// `scanResults` if you want live scan results *or* the results from a previous scan. +var subscription = FlutterBluePlus.onScanResults.listen((results) { + if (results.isNotEmpty) { + ScanResult r = results.last; // the most recently found device + print('${r.device.remoteId}: "${r.advertisementData.advName}" found!'); + } + }, + onError: (e) => print(e), +); + +// cleanup: cancel subscription when scanning stops +FlutterBluePlus.cancelWhenScanComplete(subscription); + +// Wait for Bluetooth enabled & permission granted +// In your real app you should use `FlutterBluePlus.adapterState.listen` to handle all states +await FlutterBluePlus.adapterState.where((val) => val == BluetoothAdapterState.on).first; + +// Start scanning w/ timeout +// Optional: use `stopScan()` as an alternative to timeout +await FlutterBluePlus.startScan( + withServices:[Guid("180D")], // match any of the specified services + withNames:["Bluno"], // *or* any of the specified names + timeout: Duration(seconds:15)); + +// wait for scanning to stop +await FlutterBluePlus.isScanning.where((val) => val == false).first; +``` + +### Connect to a device + +```dart +// listen for disconnection +var subscription = device.connectionState.listen((BluetoothConnectionState state) async { + if (state == BluetoothConnectionState.disconnected) { + // 1. typically, start a periodic timer that tries to + // reconnect, or just call connect() again right now + // 2. you must always re-discover services after disconnection! + print("${device.disconnectReason?.code} ${device.disconnectReason?.description}"); + } +}); + +// cleanup: cancel subscription when disconnected +// - [delayed] This option is only meant for `connectionState` subscriptions. +// When `true`, we cancel after a small delay. This ensures the `connectionState` +// listener receives the `disconnected` event. +// - [next] if true, the the stream will be canceled only on the *next* disconnection, +// not the current disconnection. This is useful if you setup your subscriptions +// before you connect. +device.cancelWhenDisconnected(subscription, delayed:true, next:true); + +// Connect to the device +await device.connect(); + +// Disconnect from device +await device.disconnect(); + +// cancel to prevent duplicate listeners +subscription.cancel(); +``` + +### Auto Connect + +Connects whenever your device is found. + +```dart +// enable auto connect +// - note: autoConnect is incompatible with mtu argument, so you must call requestMtu yourself +await device.connect(autoConnect:true, mtu:null) + +// wait until connection +// - when using autoConnect, connect() always returns immediately, so we must +// explicity listen to `device.connectionState` to know when connection occurs +await device.connectionState.where((val) => val == BluetoothConnectionState.connected).first; + +// disable auto connect +await device.disconnect() +``` + +### Save Device + +To save a device between app restarts, just write the `remoteId` to a file. + +Now you can connect without needing to scan again, like so: + +```dart +final String remoteId = await File('/remoteId.txt').readAsString(); +var device = BluetoothDevice.fromId(remoteId); +// AutoConnect is convenient because it does not "time out" +// even if the device is not available / turned off. +await device.connect(autoConnect: true); + +``` + + +### MTU + +On Android, we request an mtu of 512 by default during connection (see: `connect` function arguments). + +On iOS & macOS, the mtu is negotiated automatically, typically 135 to 255. + +```dart +final subscription = device.mtu.listen((int mtu) { + // iOS: initial value is always 23, but iOS will quickly negotiate a higher value + print("mtu $mtu"); +}); + +// cleanup: cancel subscription when disconnected +device.cancelWhenDisconnected(subscription); + +// You can also manually change the mtu yourself. +if (Platform.isAndroid) { + await device.requestMtu(512); +} +``` + +### Discover services + +```dart +// Note: You must call discoverServices after every re-connection! +List services = await device.discoverServices(); +services.forEach((service) { + // do something with service +}); +``` + +### Read Characteristics + +```dart +// Reads all characteristics +var characteristics = service.characteristics; +for(BluetoothCharacteristic c in characteristics) { + if (c.properties.read) { + List value = await c.read(); + print(value); + } +} +``` + +### Write Characteristic + +```dart +// Writes to a characteristic +await c.write([0x12, 0x34]); +``` + +**allowLongWrite**: To write large characteristics (up to 512 bytes) regardless of mtu, use `allowLongWrite`: + +```dart +/// allowLongWrite should be used with caution. +/// 1. it can only be used *with* response to avoid data loss +/// 2. the peripheral device must support the 'long write' ble protocol. +/// 3. Interrupted transfers can leave the characteristic in a partially written state +/// 4. If the mtu is small, it is very very slow. +await c.write(data, allowLongWrite:true); +``` + +**splitWrite**: To write lots of data (unlimited), you can define the `splitWrite` function. + +```dart +import 'dart:math'; +// split write should be used with caution. +// 1. due to splitting, `characteristic.read()` will return partial data. +// 2. it can only be used *with* response to avoid data loss +// 3. The characteristic must be designed to support split data +extension splitWrite on BluetoothCharacteristic { + Future splitWrite(List value, {int timeout = 15}) async { + int chunk = device.mtuNow - 3; // 3 bytes ble overhead + for (int i = 0; i < value.length; i += chunk) { + List subvalue = value.sublist(i, min(i + chunk, value.length)); + await write(subvalue, withoutResponse:false, timeout: timeout); + } + } +} +``` + +### Subscribe to a characteristic + +If `onValueReceived` is never called, see [Common Problems](#common-problems) in the README. + +```dart +final subscription = characteristic.onValueReceived.listen((value) { + // onValueReceived is updated: + // - anytime read() is called + // - anytime a notification arrives (if subscribed) +}); + +// cleanup: cancel subscription when disconnected +device.cancelWhenDisconnected(subscription); + +// subscribe +// Note: If a characteristic supports both **notifications** and **indications**, +// it will default to **notifications**. This matches how CoreBluetooth works on iOS. +await characteristic.setNotifyValue(true); +``` + +### Last Value Stream + +`lastValueStream` is an alternative to `onValueReceived`. It emits a value any time the characteristic changes, **including writes.** + +It is very convenient for simple characteristics that support both WRITE and READ (and/or NOTIFY). **e.g.** a "light switch toggle" characteristic. + +```dart +final subscription = characteristic.lastValueStream.listen((value) { + // lastValueStream` is updated: + // - anytime read() is called + // - anytime write() is called + // - anytime a notification arrives (if subscribed) + // - also when first listened to, it re-emits the last value for convenience. +}); + +// cleanup: cancel subscription when disconnected +device.cancelWhenDisconnected(subscription); + +// enable notifications +await characteristic.setNotifyValue(true); +``` + +### Read and write descriptors + +```dart +// Reads all descriptors +var descriptors = characteristic.descriptors; +for(BluetoothDescriptor d in descriptors) { + List value = await d.read(); + print(value); +} + +// Writes to a descriptor +await d.write([0x12, 0x34]) +``` + +### Services Changed Characteristic + +FlutterBluePlus automatically listens to the Services Changed Characteristic (0x2A05) + +In FlutterBluePlus, we call it `onServicesReset` because you must re-discover services. + +```dart +// - uses the GAP Services Changed characteristic (0x2A05) +// - you must call discoverServices() again +device.onServicesReset.listen(() async { + print("Services Reset"); + await device.discoverServices(); +}); +``` + +### Get Connected Devices + +Get devices currently connected to your app. + +```dart +List devs = FlutterBluePlus.connectedDevices; +for (var d in devs) { + print(d); +} +``` + +### Get System Devices + +Get devices connected to the system by *any* app. + +**Note:** you must connect *your app* to them before you can communicate with them. + +```dart +List devs = await FlutterBluePlus.systemDevices; +for (var d in devs) { + await d.connect(); // Must connect *our* app to the device + await d.discoverServices(); +} +``` + +### Create Bond (Android Only) + +**Note:** calling this is usually not necessary!! The platform will do it automatically. + +However, you can force the popup to show sooner. + +```dart +final bsSubscription = device.bondState.listen((value) { + print("$value prev:{$device.prevBondState}"); +}); + +// cleanup: cancel subscription when disconnected +device.cancelWhenDisconnected(bsSubscription); + +// Force the bonding popup to show now (Android Only) +await device.createBond(); + +// remove bond +await device.removeBond(); +``` + +### Events API + +Access streams from all devices simultaneously. + +There are streams for: +* events.onConnectionStateChanged +* events.onMtuChanged +* events.onReadRssi +* events.onServicesReset +* events.onDiscoveredServices +* events.onCharacteristicReceived +* events.onCharacteristicWritten +* events.onDescriptorRead +* events.onDescriptorWritten +* events.onNameChanged (iOS Only) +* events.onBondStateChanged (Android Only) + +```dart +// listen to *any device* connection state changes +FlutterBluePlus.events.onConnectionStateChanged.listen((event)) { + print('${event.device} ${event.connectionState}'); +} +``` + +## Mocking + +To mock `FlutterBluePlus` for development, refer to the [Mocking Guide](MOCKING.md). + +## Getting Started + +### Change the minSdkVersion for Android + +flutter_blue_plus is compatible only from version 21 of Android SDK so you should change this in **android/app/build.gradle**: + +```dart +android { + defaultConfig { + minSdkVersion: 21 +``` + +### Add permissions for Android (No Location) + +In the **android/app/src/main/AndroidManifest.xml** add: + +```xml + + + + + + + + + + + + + + +``` + +### Add permissions for Android (With Fine Location) + +If you want to use Bluetooth to determine location, or support iBeacons. + +In the **android/app/src/main/AndroidManifest.xml** add: + +```xml + + + + + + + + + + + + + + +``` + +And set **androidUsesFineLocation** when scanning: +```dart +// Start scanning +flutterBlue.startScan(timeout: Duration(seconds: 4), androidUsesFineLocation: true); +``` + +### Android Proguard + +Add the following line in your `project/android/app/proguard-rules.pro` file: + +``` +-keep class com.lib.flutter_blue_plus.* { *; } +``` + +to avoid seeing the following kind errors in your `release` builds: + +``` +PlatformException(startScan, Field androidScanMode_ for m0.e0 not found. Known fields are + [private int m0.e0.q, private b3.b0$i m0.e0.r, private boolean m0.e0.s, private static final m0.e0 m0.e0.t, + private static volatile b3.a1 m0.e0.u], java.lang.RuntimeException: Field androidScanMode_ for m0.e0 not found +``` + +### Add permissions for iOS + +In the **ios/Runner/Info.plist** let’s add: + +```dart + + NSBluetoothAlwaysUsageDescription + This app needs Bluetooth to function +``` + +For location permissions on iOS see more at: [https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services](https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services) + +### Add permissions for macOS + +Make sure you have granted access to the Bluetooth hardware: + +`Xcode -> Runners -> Targets -> Runner-> Signing & Capabilities -> App Sandbox -> Hardware -> Enable Bluetooth` + +Screenshot 2023-12-11 at 10 32 04 AM + +## Using Ble in App Background + +**This is an advanced use case**. FlutterBluePlus does not support everything. You may have to fork it. PRs are welcome. + +### iOS + +Documentation: https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html + +Add the following to your `Info.plist` + +``` +UIBackgroundModes + + bluetooth-central + +``` + +When this key-value pair is included in the app’s Info.plist file, the system wakes up your app to process ble `read`, `write`, and `subscription` events. + +You may also have to use https://pub.dev/packages/workmanager + +**Note**: Upon being woken up, an app has around 10 seconds to complete a task. Apps that spend too much time executing in the background can be throttled back by the system or killed. + +### Android + +You can try using https://pub.dev/packages/flutter_foreground_task or possibly https://pub.dev/packages/workmanager + +## Reference + +🌀 = Stream +⚡ = synchronous + +### FlutterBluePlus API + +| | Android | iOS | Throws | Description | +| :--------------------- | :----------------: | :----------------: | :----: | :----------------------------------------------------------| +| setLogLevel | :white_check_mark: | :white_check_mark: | | Configure plugin log level | +| setOptions | :white_check_mark: | :white_check_mark: | | Set configurable bluetooth options | +| isSupported | :white_check_mark: | :white_check_mark: | | Checks whether the device supports Bluetooth | +| turnOn | :white_check_mark: | | :fire: | Turns on the bluetooth adapter | +| adapterStateNow ⚡ | :white_check_mark: | :white_check_mark: | | Current state of the bluetooth adapter | +| adapterState 🌀 | :white_check_mark: | :white_check_mark: | | Stream of on & off states of the bluetooth adapter | +| startScan | :white_check_mark: | :white_check_mark: | :fire: | Starts a scan for Ble devices | +| stopScan | :white_check_mark: | :white_check_mark: | :fire: | Stop an existing scan for Ble devices | +| onScanResults 🌀 | :white_check_mark: | :white_check_mark: | | Stream of live scan results | +| scanResults 🌀 | :white_check_mark: | :white_check_mark: | | Stream of live scan results or previous results | +| lastScanResults ⚡ | :white_check_mark: | :white_check_mark: | | The most recent scan results | +| isScanning 🌀 | :white_check_mark: | :white_check_mark: | | Stream of current scanning state | +| isScanningNow ⚡ | :white_check_mark: | :white_check_mark: | | Is a scan currently running? | +| connectedDevices ⚡ | :white_check_mark: | :white_check_mark: | | List of devices connected to *your app* | +| systemDevices | :white_check_mark: | :white_check_mark: | :fire: | List of devices connected to the system, even by other apps| +| getPhySupport | :white_check_mark: | | :fire: | Get supported bluetooth phy codings | + +### FlutterBluePlus Events API + +| | Android | iOS | Throws | Description | +| :--------------------------------- | :----------------: | :----------------: | :----: | :-----------------------------------------------------| +| events.onConnectionStateChanged 🌀 | :white_check_mark: | :white_check_mark: | | Stream of connection changes of *all devices* | +| events.onMtuChanged 🌀 | :white_check_mark: | :white_check_mark: | | Stream of mtu changes of *all devices* | +| events.onReadRssi 🌀 | :white_check_mark: | :white_check_mark: | | Stream of rssi reads of *all devices* | +| events.onServicesReset 🌀 | :white_check_mark: | :white_check_mark: | | Stream of services resets of *all devices* | +| events.onDiscoveredServices 🌀 | :white_check_mark: | :white_check_mark: | | Stream of services discovered of *all devices* | +| events.onCharacteristicReceived 🌀 | :white_check_mark: | :white_check_mark: | | Stream of characteristic value reads of *all devices* | +| events.onCharacteristicWritten 🌀 | :white_check_mark: | :white_check_mark: | | Stream of characteristic value writes of *all devices*| +| events.onDescriptorRead 🌀 | :white_check_mark: | :white_check_mark: | | Stream of descriptor value reads of *all devices* | +| events.onDescriptorWritten 🌀 | :white_check_mark: | :white_check_mark: | | Stream of descriptor value writes of *all devices* | +| events.onBondStateChanged 🌀 | :white_check_mark: | | | Stream of android bond state changes of *all devices* | +| events.onNameChanged 🌀 | | :white_check_mark: | | Stream of iOS name changes of *all devices* | + + +### BluetoothDevice API + +| | Android | iOS | Throws | Description | +| :------------------------ | :----------------: | :----------------: | :----: | :----------------------------------------------------------| +| platformName ⚡ | :white_check_mark: | :white_check_mark: | | The platform preferred name of the device | +| advName ⚡ | :white_check_mark: | :white_check_mark: | | The advertised name of the device found during scanning | +| connect | :white_check_mark: | :white_check_mark: | :fire: | Establishes a connection to the device | +| disconnect | :white_check_mark: | :white_check_mark: | :fire: | Cancels an active or pending connection to the device | +| isConnected ⚡ | :white_check_mark: | :white_check_mark: | | Is this device currently connected to *your app*? | +| isDisonnected ⚡ | :white_check_mark: | :white_check_mark: | | Is this device currently disconnected from *your app*? | +| connectionState 🌀 | :white_check_mark: | :white_check_mark: | | Stream of connection changes for the Bluetooth Device | +| discoverServices | :white_check_mark: | :white_check_mark: | :fire: | Discover services | +| servicesList ⚡ | :white_check_mark: | :white_check_mark: | | The current list of available services | +| onServicesReset 🌀 | :white_check_mark: | :white_check_mark: | | The services changed & must be rediscovered | +| mtu 🌀 | :white_check_mark: | :white_check_mark: | | Stream of current mtu value + changes | +| mtuNow ⚡ | :white_check_mark: | :white_check_mark: | | The current mtu value | +| readRssi | :white_check_mark: | :white_check_mark: | :fire: | Read RSSI from a connected device | +| requestMtu | :white_check_mark: | | :fire: | Request to change the MTU for the device | +| requestConnectionPriority | :white_check_mark: | | :fire: | Request to update a high priority, low latency connection | +| bondState 🌀 | :white_check_mark: | | | Stream of device bond state. Can be useful on Android | +| createBond | :white_check_mark: | | :fire: | Force a system pairing dialogue to show, if needed | +| removeBond | :white_check_mark: | | :fire: | Remove Bluetooth Bond of device | +| setPreferredPhy | :white_check_mark: | | :fire: | Set preferred RX and TX phy for connection and phy options | +| clearGattCache | :white_check_mark: | | :fire: | Clear android cache of service discovery results | + +### BluetoothCharacteristic API + +| | Android | iOS | Throws | Description | +| :----------------- | :----------------: | :----------------: | :----: | :--------------------------------------------------------------| +| uuid ⚡ | :white_check_mark: | :white_check_mark: | | The uuid of characteristic | +| read | :white_check_mark: | :white_check_mark: | :fire: | Retrieves the value of the characteristic | +| write | :white_check_mark: | :white_check_mark: | :fire: | Writes the value of the characteristic | +| setNotifyValue | :white_check_mark: | :white_check_mark: | :fire: | Sets notifications or indications on the characteristic | +| isNotifying ⚡ | :white_check_mark: | :white_check_mark: | | Are notifications or indications currently enabled | +| onValueReceived 🌀 | :white_check_mark: | :white_check_mark: | | Stream of characteristic value updates received from the device| +| lastValue ⚡ | :white_check_mark: | :white_check_mark: | | The most recent value of the characteristic | +| lastValueStream 🌀 | :white_check_mark: | :white_check_mark: | | Stream of onValueReceived + writes | + +### BluetoothDescriptor API + +| | Android | iOS | Throws | Description | +| :---- | :----------------: | :----------------: | :----: | :----------------------------------------------| +| uuid ⚡ | :white_check_mark: | :white_check_mark: | | The uuid of descriptor | +| read | :white_check_mark: | :white_check_mark: | :fire: | Retrieves the value of the descriptor | +| write | :white_check_mark: | :white_check_mark: | :fire: | Writes the value of the descriptor | +| onValueReceived 🌀 | :white_check_mark: | :white_check_mark: | | Stream of descriptor value reads & writes | +| lastValue ⚡ | :white_check_mark: | :white_check_mark: | | The most recent value of the descriptor | +| lastValueStream 🌀 | :white_check_mark: | :white_check_mark: | | Stream of onValueReceived + writes | + +## Debugging + +The easiest way to debug issues in FlutterBluePlus is to make your own local copy. + +``` +cd /user/downloads +git clone https://github.com/boskokg/flutter_blue_plus.git +``` + +then in `pubspec.yaml` add the repo by path: + +``` + flutter_blue_plus: + path: /user/downloads/flutter_blue_plus +``` + +Now you can edit the FlutterBluePlus code yourself. + +## Common Problems + +Many common problems are easily solved. + +Adapter: +- [bluetooth must be turned on](#bluetooth-must-be-turned-on) +- [adapterState is not 'on' but my Bluetooth is on](#adapterstate-is-not-on-but-my-bluetooth-is-on) +- [adapterState is called multiple times](#adapterstate-is-called-multiple-times) + +Scanning: +- [Scanning does not find my device](#scanning-does-not-find-my-device) +- [Scanned device never goes away](#scanned-device-never-goes-away) +- [iBeacons not showing](#ibeacons-not-showing) + +Connecting: +- [Connection fails](#connection-fails) +- [connectionState is called multiple times](#connectionstate-is-called-multiple-times) +- [remoteId is different on Android vs iOS](#the-remoteid-is-different-on-android-versus-ios--macos) +- [iOS: "[Error] The connection has timed out unexpectedly."](#ios-error-the-connection-has-timed-out-unexpectedly) + +Reading & Writing: +- [List of Bluetooth GATT Errors](#list-of-bluetooth-gatt-errors) +- [Characteristic write fails](#characteristic-write-fails) +- [Characteristic read fails](#characteristic-read-fails) + +Subscriptions: +- [onValueReceived is never called (or lastValueStream)](#onvaluereceived-is-never-called-or-lastvaluestream) +- [onValueReceived data is split up (or lastValueStream)](#onvaluereceived-data-is-split-up-or-lastvaluestream) +- [onValueReceived is called with duplicate data (or lastValueStream)](#onvaluereceived-is-called-with-duplicate-data-or-lastvaluestream) + +Android Errors: +- [ANDROID_SPECIFIC_ERROR](#android_specific_error) +- [android pairing popup appears twice](#android-pairing-popup-appears-twice) + +Flutter Errors: +- [MissingPluginException(No implementation found for method XXXX ...)](#missingpluginexceptionno-implementation-found-for-method-xxxx-) + +--- + +### "bluetooth must be turned on" + +You need to wait for the bluetooth adapter to fully turn on. + +`await FlutterBluePlus.adapterState.where((state) => state == BluetoothAdapterState.on).first;` + +You can also use `FlutterBluePlus.adapterState.listen(...)`. See [Usage](#usage). + +--- + +### adapterState is not 'on' but my Bluetooth is on + +**For iOS:** + +`adapterState` always starts as `unknown`. You need to wait longer for the service to initialize. Use this code: + +``` +// wait for actual adapter state, up to 3 seconds +Set inProgress = {BluetoothAdapterState.unknown, BluetoothAdapterState.turningOn}; +var adapterState = FlutterBluePlus.adapterState.where((v) => !inProgress.contains(v)).first; +await adapterState.timeout(const Duration(seconds: 3)).onError((error, stackTrace) { + throw Exception("Could not determine Bluetooth state. ${FlutterBluePlus.adapterStateNow}"); +}); + +// check adapter state +if (FlutterBluePlus.adapterStateNow != BluetoothAdapterState.on) { + throw Exception("Bluetooth Is Not On. ${FlutterBluePlus.adapterStateNow}"); +} +``` + +If `adapterState` is `unavailable`, you must add access to Bluetooth Hardware in the app's Xcode settings. See [Getting Started](#getting-started). + +**For Android:** + +Check that your device supports Bluetooth & has permissions. + +--- + +### adapterState is called multiple times + +You are forgetting to cancel the original `FlutterBluePlus.adapterState.listen` resulting in multiple listeners. + +```dart +// tip: using ??= makes it easy to only make new listener when currently null +final subscription ??= FlutterBluePlus.adapterState.listen((value) { + // ... +}); + +// also, make sure you cancel the subscription when done! +subscription.cancel() +``` + +--- + +### Scanning does not find my device + +**1. you're using an emulator** + +Use a physical device. + +**2. try using another ble scanner app** + +* **iOS**: [nRF Connect](https://apps.apple.com/us/app/nrf-connect-for-mobile/id1054362403) +* **Android**: [BLE Scanner](https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner) + +Install a BLE scanner app on your phone. Can it find your device? + +**3. your device uses bluetooth classic, not BLE.** + +Headphones, speakers, keyboards, mice, gamepads, & printers all use Bluetooth Classic. + +These devices may be found in System Settings, but they cannot be connected to by FlutterBluePlus. FlutterBluePlus only supports Bluetooth Low Energy. + +**4. your device stopped advertising.** + +- you might need to reboot your device +- you might need to put your device in "discovery mode" +- your phone may have already connected automatically +- another app may have already connected to your device +- another phone may have already connected to your device + +Try looking through system devices: + +```dart +// search system devices. i.e. any device connected to by *any* app +List system = await FlutterBluePlus.systemDevices; +for (var d in system) { + print('${r.device.platformName} already connected to! ${r.device.remoteId}'); + if (d.platformName == "myBleDevice") { + await r.connect(); // must connect our app + } +} +``` + +**5. your scan filters are wrong.** + +- try removing all scan filters +- for `withServices` to work, your device must actively advertise the serviceUUIDs it supports + +**6. Android: you're calling startScan too often** + +On Adroid you can only call `startScan` 5 times per 30 second period. This is a platform restriction. + +--- + +### Scanned device never goes away + +This is expected. + +You must set the `removeIfGone` scan option if you want the device to go away when no longer available. + +--- + +### iBeacons Not Showing + +**iOS:** + +iOS does not support iBeacons using CoreBluetooth. You must find a plugin meant for CoreLocation. + +**Android:** + +1. you need to enable location permissions, see [Getting Started](#getting-started) +2. you must pass `androidUsesFineLocation:true` to the `startScan` method. + +--- + +### Connection fails + +**1. Your ble device may be low battery** + +Bluetooth can become erratic when your peripheral device is low on battery. + +**2. Your ble device may have refused the connection or have a bug** + +Connection is a two-way process. Your ble device may be misconfigured. + +**3. You may be on the edge of the Bluetooth range.** + +The signal is too weak, or there are a lot of devices causing radio interference. + +**4. Some phones have an issue connecting while scanning.** + +The Huawei P8 Lite is one of the reported phones to have this issue. Try stopping your scanner before connecting. + +**5. Try restarting your phone** + +Bluetooth is a complicated system service, and can enter a bad state. + +--- + +### connectionState is called multiple times + +You are forgetting to cancel the original `device.connectionState.listen` resulting in multiple listeners. + +```dart +// tip: using ??= makes it easy to only make new listener when currently null +final subscription ??= FlutterBluePlus.device.connectionState.listen((value) { + // ... +}); + +// also, make sure you cancel the subscription when done! +subscription.cancel() +``` + +--- + +### The remoteId is different on Android versus iOS & macOS + +This is expected. There is no way to avoid it. + +For privacy, iOS & macOS use a randomly generated uuid. This uuid will periodically change. + +e.g. `6920a902-ba0e-4a13-a35f-6bc91161c517` + +Android uses the mac address of the bluetooth device. It never changes. + +e.g. `05:A4:22:31:F7:ED` + +--- + +### iOS: "[Error] The connection has timed out unexpectedly." + +You can google this error. It is a common iOS ble error code. + +It means your device stopped working. FlutterBluePlus cannot fix it. + +--- + +### List of Bluetooth GATT Errors + +These GATT error codes are part of the BLE Specification. + +**These are *responses* from your ble device because you are sending an invalid request.** + +FlutterBluePlus cannot fix these errors. You are doing something wrong & your device is responding with an error. + +**GATT errors as they appear on iOS**: +``` +apple-code: 1 | The handle is invalid. +apple-code: 2 | Reading is not permitted. +apple-code: 3 | Writing is not permitted. +apple-code: 4 | The command is invalid. +apple-code: 6 | The request is not supported. +apple-code: 7 | The offset is invalid. +apple-code: 8 | Authorization is insufficient. +apple-code: 9 | The prepare queue is full. +apple-code: 10 | The attribute could not be found. +apple-code: 11 | The attribute is not long. +apple-code: 12 | The encryption key size is insufficient. +apple-code: 13 | The value's length is invalid. +apple-code: 14 | Unlikely error. +apple-code: 15 | Encryption is insufficient. +apple-code: 16 | The group type is unsupported. +apple-code: 17 | Resources are insufficient. +apple-code: 18 | Unknown ATT error. +``` + +**GATT errors as they appear on Android**: +``` +android-code: 1 | GATT_INVALID_HANDLE +android-code: 2 | GATT_READ_NOT_PERMITTED +android-code: 3 | GATT_WRITE_NOT_PERMITTED +android-code: 4 | GATT_INVALID_PDU +android-code: 5 | GATT_INSUFFICIENT_AUTHENTICATION +android-code: 6 | GATT_REQUEST_NOT_SUPPORTED +android-code: 7 | GATT_INVALID_OFFSET +android-code: 8 | GATT_INSUFFICIENT_AUTHORIZATION +android-code: 9 | GATT_PREPARE_QUEUE_FULL +android-code: 10 | GATT_ATTR_NOT_FOUND +android-code: 11 | GATT_ATTR_NOT_LONG +android-code: 12 | GATT_INSUFFICIENT_KEY_SIZE +android-code: 13 | GATT_INVALID_ATTRIBUTE_LENGTH +android-code: 14 | GATT_UNLIKELY +android-code: 15 | GATT_INSUFFICIENT_ENCRYPTION +android-code: 16 | GATT_UNSUPPORTED_GROUP +android-code: 17 | GATT_INSUFFICIENT_RESOURCES +``` + +**Descriptions**: +``` +1 | Invalid Handle | The attribute handle given was not valid on this server. +2 | Read Not Permitted | The attribute cannot be read. +3 | Write Not Permitted | The attribute cannot be written. +4 | Invalid PDU | The attribute PDU was invalid. +5 | Insufficient Authentication | The attribute requires authentication before it can be read or written. +6 | Request Not Supported | Attribute server does not support the request received from the client. +7 | Invalid Offset | Offset specified was past the end of the attribute. +8 | Insufficient Authorization | The attribute requires an authorization before it can be read or written. +9 | Prepare Queue Full | Too many prepare writes have been queued. +10 | Attribute Not Found | No attribute found within the given attribute handle range. +11 | Attribute Not Long | The attribute cannot be read or written using the Read Blob or Write Blob requests. +12 | Insufficient Key Size | The Encryption Key Size used for encrypting this link is insufficient. +13 | Invalid Attribute Value Length | The attribute value length is invalid for the operation. +14 | Unlikely Error | The request has encountered an unlikely error and cannot be completed. +15 | Insufficient Encryption | The attribute requires encryption before it can be read or written. +16 | Unsupported Group Type | The attribute type is not a supported grouping as defined by a higher layer. +17 | Insufficient Resources | Insufficient Resources to complete the request. +``` + +--- + +### characteristic write fails + +First, check the [List of Bluetooth GATT Errors](#list-of-bluetooth-gatt-errors) for your error. + +**1. your bluetooth device turned off, or is out of range** + +If your device turns off or crashes during a write, it will cause a failure. + +**2. Your Bluetooth device has bugs** + +Maybe your device crashed, or is not sending a response due to software bugs. + +**3. there is radio interference** + +Bluetooth is wireless and will not always work. + +--- + +### Characteristic read fails + +First, check the [List of Bluetooth GATT Errors](#list-of-bluetooth-gatt-errors) for your error. + +**1. your bluetooth device turned off, or is out of range** + +If your device turns off or crashes during a read, it will cause a failure. + +**2. Your Bluetooth device has bugs** + +Maybe your device crashed, or is not sending a response due to software bugs. + +**3. there is radio interference** + +Bluetooth is wireless and will not always work. + +--- + +### onValueReceived is never called (or lastValueStream) + +**1. you are not calling the right function** + +`lastValueStream` is called for `await chr.read()` & `await chr.write()` & `await chr.setNotifyValue(true)` + +`onValueReceived` is only called for `await chr.read()` & `await chr.setNotifyValue(true)` + +**2. your device has nothing to send** + +If you are using `await chr.setNotifyValue(true)`, your _device_ chooses when to send data. + +Try interacting with your device to get it to send new data. + +**3. your device has bugs** + +Try rebooting your ble device. + +Some ble devices have buggy software and stop sending data + +--- + +### onValueReceived data is split up (or lastValueStream) + +Verify that the mtu is large enough to hold your message. + +```dart +device.mtu +``` + +If it still happens, it is a problem with your peripheral device. + +--- + +### onValueReceived is called with duplicate data (or lastValueStream) + +You are probably forgetting to cancel the original `chr.onValueReceived.listen` resulting in multiple listens. + +The easiest solution is to use `device.cancelWhenDisconnected(subscription)` to cancel device subscriptions. + +```dart +final subscription = chr.onValueReceived.listen((value) { + // ... +}); + +// make sure you have this line! +device.cancelWhenDisconnected(subscription); + +await characteristic.setNotifyValue(true); +``` + +--- + +### ANDROID_SPECIFIC_ERROR + +There is no 100% solution. + +FBP already has mitigations for this error, but Android will still fail with this code randomly. + +The recommended solution is to `catch` the error, and retry. + +--- + +### android pairing popup appears twice + +This is a bug in android itself. + +You can call `createBond()` yourself just after connecting and this will resolve the issue. + +--- + +### MissingPluginException(No implementation found for method XXXX ...) + +If you just added flutter_blue_plus to your pubspec.yaml, a hot reload / hot restart is not enough. + +You need to fully stop your app and run again so that the native plugins are loaded. + +Also try `flutter clean`. + + + + + + + + + + diff --git a/packages/flutter_blue_plus/analysis_options.yaml b/packages/flutter_blue_plus/analysis_options.yaml new file mode 100644 index 00000000..f9b30346 --- /dev/null +++ b/packages/flutter_blue_plus/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/example/.gitignore b/packages/flutter_blue_plus/example/.gitignore similarity index 100% rename from example/.gitignore rename to packages/flutter_blue_plus/example/.gitignore diff --git a/example/.metadata b/packages/flutter_blue_plus/example/.metadata similarity index 100% rename from example/.metadata rename to packages/flutter_blue_plus/example/.metadata diff --git a/example/.vscode/settings.json b/packages/flutter_blue_plus/example/.vscode/settings.json similarity index 100% rename from example/.vscode/settings.json rename to packages/flutter_blue_plus/example/.vscode/settings.json diff --git a/example/README.md b/packages/flutter_blue_plus/example/README.md similarity index 100% rename from example/README.md rename to packages/flutter_blue_plus/example/README.md diff --git a/example/analysis_options.yaml b/packages/flutter_blue_plus/example/analysis_options.yaml similarity index 100% rename from example/analysis_options.yaml rename to packages/flutter_blue_plus/example/analysis_options.yaml diff --git a/example/android/.gitignore b/packages/flutter_blue_plus/example/android/.gitignore similarity index 100% rename from example/android/.gitignore rename to packages/flutter_blue_plus/example/android/.gitignore diff --git a/example/android/app/build.gradle b/packages/flutter_blue_plus/example/android/app/build.gradle similarity index 100% rename from example/android/app/build.gradle rename to packages/flutter_blue_plus/example/android/app/build.gradle diff --git a/example/android/app/src/debug/AndroidManifest.xml b/packages/flutter_blue_plus/example/android/app/src/debug/AndroidManifest.xml similarity index 100% rename from example/android/app/src/debug/AndroidManifest.xml rename to packages/flutter_blue_plus/example/android/app/src/debug/AndroidManifest.xml diff --git a/example/android/app/src/main/AndroidManifest.xml b/packages/flutter_blue_plus/example/android/app/src/main/AndroidManifest.xml similarity index 100% rename from example/android/app/src/main/AndroidManifest.xml rename to packages/flutter_blue_plus/example/android/app/src/main/AndroidManifest.xml diff --git a/example/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java b/packages/flutter_blue_plus/example/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java similarity index 100% rename from example/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java rename to packages/flutter_blue_plus/example/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java diff --git a/example/android/app/src/main/res/drawable-v21/launch_background.xml b/packages/flutter_blue_plus/example/android/app/src/main/res/drawable-v21/launch_background.xml similarity index 100% rename from example/android/app/src/main/res/drawable-v21/launch_background.xml rename to packages/flutter_blue_plus/example/android/app/src/main/res/drawable-v21/launch_background.xml diff --git a/example/android/app/src/main/res/drawable/launch_background.xml b/packages/flutter_blue_plus/example/android/app/src/main/res/drawable/launch_background.xml similarity index 100% rename from example/android/app/src/main/res/drawable/launch_background.xml rename to packages/flutter_blue_plus/example/android/app/src/main/res/drawable/launch_background.xml diff --git a/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/example/android/app/src/main/res/values-night/styles.xml b/packages/flutter_blue_plus/example/android/app/src/main/res/values-night/styles.xml similarity index 100% rename from example/android/app/src/main/res/values-night/styles.xml rename to packages/flutter_blue_plus/example/android/app/src/main/res/values-night/styles.xml diff --git a/example/android/app/src/main/res/values/styles.xml b/packages/flutter_blue_plus/example/android/app/src/main/res/values/styles.xml similarity index 100% rename from example/android/app/src/main/res/values/styles.xml rename to packages/flutter_blue_plus/example/android/app/src/main/res/values/styles.xml diff --git a/example/android/app/src/profile/AndroidManifest.xml b/packages/flutter_blue_plus/example/android/app/src/profile/AndroidManifest.xml similarity index 100% rename from example/android/app/src/profile/AndroidManifest.xml rename to packages/flutter_blue_plus/example/android/app/src/profile/AndroidManifest.xml diff --git a/example/android/build.gradle b/packages/flutter_blue_plus/example/android/build.gradle similarity index 100% rename from example/android/build.gradle rename to packages/flutter_blue_plus/example/android/build.gradle diff --git a/example/android/gradle.properties b/packages/flutter_blue_plus/example/android/gradle.properties similarity index 100% rename from example/android/gradle.properties rename to packages/flutter_blue_plus/example/android/gradle.properties diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/flutter_blue_plus/example/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from example/android/gradle/wrapper/gradle-wrapper.properties rename to packages/flutter_blue_plus/example/android/gradle/wrapper/gradle-wrapper.properties diff --git a/example/android/settings.gradle b/packages/flutter_blue_plus/example/android/settings.gradle similarity index 100% rename from example/android/settings.gradle rename to packages/flutter_blue_plus/example/android/settings.gradle diff --git a/example/ios/.gitignore b/packages/flutter_blue_plus/example/ios/.gitignore similarity index 100% rename from example/ios/.gitignore rename to packages/flutter_blue_plus/example/ios/.gitignore diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/packages/flutter_blue_plus/example/ios/Flutter/AppFrameworkInfo.plist similarity index 100% rename from example/ios/Flutter/AppFrameworkInfo.plist rename to packages/flutter_blue_plus/example/ios/Flutter/AppFrameworkInfo.plist diff --git a/example/ios/Flutter/Debug.xcconfig b/packages/flutter_blue_plus/example/ios/Flutter/Debug.xcconfig similarity index 100% rename from example/ios/Flutter/Debug.xcconfig rename to packages/flutter_blue_plus/example/ios/Flutter/Debug.xcconfig diff --git a/example/ios/Flutter/Release.xcconfig b/packages/flutter_blue_plus/example/ios/Flutter/Release.xcconfig similarity index 100% rename from example/ios/Flutter/Release.xcconfig rename to packages/flutter_blue_plus/example/ios/Flutter/Release.xcconfig diff --git a/example/ios/Podfile b/packages/flutter_blue_plus/example/ios/Podfile similarity index 100% rename from example/ios/Podfile rename to packages/flutter_blue_plus/example/ios/Podfile diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.pbxproj similarity index 100% rename from example/ios/Runner.xcodeproj/project.pbxproj rename to packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.pbxproj diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to packages/flutter_blue_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/packages/flutter_blue_plus/example/ios/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from example/ios/Runner.xcworkspace/contents.xcworkspacedata rename to packages/flutter_blue_plus/example/ios/Runner.xcworkspace/contents.xcworkspacedata diff --git a/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/flutter_blue_plus/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/flutter_blue_plus/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/flutter_blue_plus/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to packages/flutter_blue_plus/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/example/ios/Runner/AppDelegate.swift b/packages/flutter_blue_plus/example/ios/Runner/AppDelegate.swift similarity index 100% rename from example/ios/Runner/AppDelegate.swift rename to packages/flutter_blue_plus/example/ios/Runner/AppDelegate.swift diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md rename to packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md diff --git a/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/packages/flutter_blue_plus/example/ios/Runner/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from example/ios/Runner/Base.lproj/LaunchScreen.storyboard rename to packages/flutter_blue_plus/example/ios/Runner/Base.lproj/LaunchScreen.storyboard diff --git a/example/ios/Runner/Base.lproj/Main.storyboard b/packages/flutter_blue_plus/example/ios/Runner/Base.lproj/Main.storyboard similarity index 100% rename from example/ios/Runner/Base.lproj/Main.storyboard rename to packages/flutter_blue_plus/example/ios/Runner/Base.lproj/Main.storyboard diff --git a/example/ios/Runner/Info.plist b/packages/flutter_blue_plus/example/ios/Runner/Info.plist similarity index 100% rename from example/ios/Runner/Info.plist rename to packages/flutter_blue_plus/example/ios/Runner/Info.plist diff --git a/example/ios/Runner/Runner-Bridging-Header.h b/packages/flutter_blue_plus/example/ios/Runner/Runner-Bridging-Header.h similarity index 100% rename from example/ios/Runner/Runner-Bridging-Header.h rename to packages/flutter_blue_plus/example/ios/Runner/Runner-Bridging-Header.h diff --git a/example/lib/main.dart b/packages/flutter_blue_plus/example/lib/main.dart similarity index 100% rename from example/lib/main.dart rename to packages/flutter_blue_plus/example/lib/main.dart diff --git a/example/lib/screens/bluetooth_off_screen.dart b/packages/flutter_blue_plus/example/lib/screens/bluetooth_off_screen.dart similarity index 100% rename from example/lib/screens/bluetooth_off_screen.dart rename to packages/flutter_blue_plus/example/lib/screens/bluetooth_off_screen.dart diff --git a/example/lib/screens/device_screen.dart b/packages/flutter_blue_plus/example/lib/screens/device_screen.dart similarity index 100% rename from example/lib/screens/device_screen.dart rename to packages/flutter_blue_plus/example/lib/screens/device_screen.dart diff --git a/example/lib/screens/scan_screen.dart b/packages/flutter_blue_plus/example/lib/screens/scan_screen.dart similarity index 100% rename from example/lib/screens/scan_screen.dart rename to packages/flutter_blue_plus/example/lib/screens/scan_screen.dart diff --git a/example/lib/utils/extra.dart b/packages/flutter_blue_plus/example/lib/utils/extra.dart similarity index 100% rename from example/lib/utils/extra.dart rename to packages/flutter_blue_plus/example/lib/utils/extra.dart diff --git a/example/lib/utils/snackbar.dart b/packages/flutter_blue_plus/example/lib/utils/snackbar.dart similarity index 100% rename from example/lib/utils/snackbar.dart rename to packages/flutter_blue_plus/example/lib/utils/snackbar.dart diff --git a/example/lib/utils/utils.dart b/packages/flutter_blue_plus/example/lib/utils/utils.dart similarity index 100% rename from example/lib/utils/utils.dart rename to packages/flutter_blue_plus/example/lib/utils/utils.dart diff --git a/example/lib/widgets/characteristic_tile.dart b/packages/flutter_blue_plus/example/lib/widgets/characteristic_tile.dart similarity index 100% rename from example/lib/widgets/characteristic_tile.dart rename to packages/flutter_blue_plus/example/lib/widgets/characteristic_tile.dart diff --git a/example/lib/widgets/descriptor_tile.dart b/packages/flutter_blue_plus/example/lib/widgets/descriptor_tile.dart similarity index 100% rename from example/lib/widgets/descriptor_tile.dart rename to packages/flutter_blue_plus/example/lib/widgets/descriptor_tile.dart diff --git a/example/lib/widgets/scan_result_tile.dart b/packages/flutter_blue_plus/example/lib/widgets/scan_result_tile.dart similarity index 100% rename from example/lib/widgets/scan_result_tile.dart rename to packages/flutter_blue_plus/example/lib/widgets/scan_result_tile.dart diff --git a/example/lib/widgets/service_tile.dart b/packages/flutter_blue_plus/example/lib/widgets/service_tile.dart similarity index 100% rename from example/lib/widgets/service_tile.dart rename to packages/flutter_blue_plus/example/lib/widgets/service_tile.dart diff --git a/example/lib/widgets/system_device_tile.dart b/packages/flutter_blue_plus/example/lib/widgets/system_device_tile.dart similarity index 100% rename from example/lib/widgets/system_device_tile.dart rename to packages/flutter_blue_plus/example/lib/widgets/system_device_tile.dart diff --git a/example/macos/.gitignore b/packages/flutter_blue_plus/example/macos/.gitignore similarity index 100% rename from example/macos/.gitignore rename to packages/flutter_blue_plus/example/macos/.gitignore diff --git a/example/macos/Flutter/Flutter-Debug.xcconfig b/packages/flutter_blue_plus/example/macos/Flutter/Flutter-Debug.xcconfig similarity index 100% rename from example/macos/Flutter/Flutter-Debug.xcconfig rename to packages/flutter_blue_plus/example/macos/Flutter/Flutter-Debug.xcconfig diff --git a/example/macos/Flutter/Flutter-Release.xcconfig b/packages/flutter_blue_plus/example/macos/Flutter/Flutter-Release.xcconfig similarity index 100% rename from example/macos/Flutter/Flutter-Release.xcconfig rename to packages/flutter_blue_plus/example/macos/Flutter/Flutter-Release.xcconfig diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/packages/flutter_blue_plus/example/macos/Flutter/GeneratedPluginRegistrant.swift similarity index 88% rename from example/macos/Flutter/GeneratedPluginRegistrant.swift rename to packages/flutter_blue_plus/example/macos/Flutter/GeneratedPluginRegistrant.swift index e56ee822..75f01990 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/packages/flutter_blue_plus/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,7 @@ import FlutterMacOS import Foundation -import flutter_blue_plus +import flutter_blue_plus_darwin func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FlutterBluePlusPlugin.register(with: registry.registrar(forPlugin: "FlutterBluePlusPlugin")) diff --git a/example/macos/Podfile b/packages/flutter_blue_plus/example/macos/Podfile similarity index 100% rename from example/macos/Podfile rename to packages/flutter_blue_plus/example/macos/Podfile diff --git a/example/macos/Runner.xcodeproj/project.pbxproj b/packages/flutter_blue_plus/example/macos/Runner.xcodeproj/project.pbxproj similarity index 100% rename from example/macos/Runner.xcodeproj/project.pbxproj rename to packages/flutter_blue_plus/example/macos/Runner.xcodeproj/project.pbxproj diff --git a/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/flutter_blue_plus/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/flutter_blue_plus/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/flutter_blue_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to packages/flutter_blue_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/example/macos/Runner.xcworkspace/contents.xcworkspacedata b/packages/flutter_blue_plus/example/macos/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from example/macos/Runner.xcworkspace/contents.xcworkspacedata rename to packages/flutter_blue_plus/example/macos/Runner.xcworkspace/contents.xcworkspacedata diff --git a/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/flutter_blue_plus/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/flutter_blue_plus/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/example/macos/Runner/AppDelegate.swift b/packages/flutter_blue_plus/example/macos/Runner/AppDelegate.swift similarity index 100% rename from example/macos/Runner/AppDelegate.swift rename to packages/flutter_blue_plus/example/macos/Runner/AppDelegate.swift diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png similarity index 100% rename from example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png rename to packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png similarity index 100% rename from example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png rename to packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png similarity index 100% rename from example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png rename to packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png similarity index 100% rename from example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png rename to packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png similarity index 100% rename from example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png rename to packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png similarity index 100% rename from example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png rename to packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png similarity index 100% rename from example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png rename to packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png diff --git a/example/macos/Runner/Base.lproj/MainMenu.xib b/packages/flutter_blue_plus/example/macos/Runner/Base.lproj/MainMenu.xib similarity index 100% rename from example/macos/Runner/Base.lproj/MainMenu.xib rename to packages/flutter_blue_plus/example/macos/Runner/Base.lproj/MainMenu.xib diff --git a/example/macos/Runner/Configs/AppInfo.xcconfig b/packages/flutter_blue_plus/example/macos/Runner/Configs/AppInfo.xcconfig similarity index 100% rename from example/macos/Runner/Configs/AppInfo.xcconfig rename to packages/flutter_blue_plus/example/macos/Runner/Configs/AppInfo.xcconfig diff --git a/example/macos/Runner/Configs/Debug.xcconfig b/packages/flutter_blue_plus/example/macos/Runner/Configs/Debug.xcconfig similarity index 100% rename from example/macos/Runner/Configs/Debug.xcconfig rename to packages/flutter_blue_plus/example/macos/Runner/Configs/Debug.xcconfig diff --git a/example/macos/Runner/Configs/Release.xcconfig b/packages/flutter_blue_plus/example/macos/Runner/Configs/Release.xcconfig similarity index 100% rename from example/macos/Runner/Configs/Release.xcconfig rename to packages/flutter_blue_plus/example/macos/Runner/Configs/Release.xcconfig diff --git a/example/macos/Runner/Configs/Warnings.xcconfig b/packages/flutter_blue_plus/example/macos/Runner/Configs/Warnings.xcconfig similarity index 100% rename from example/macos/Runner/Configs/Warnings.xcconfig rename to packages/flutter_blue_plus/example/macos/Runner/Configs/Warnings.xcconfig diff --git a/example/macos/Runner/DebugProfile.entitlements b/packages/flutter_blue_plus/example/macos/Runner/DebugProfile.entitlements similarity index 100% rename from example/macos/Runner/DebugProfile.entitlements rename to packages/flutter_blue_plus/example/macos/Runner/DebugProfile.entitlements diff --git a/example/macos/Runner/Info.plist b/packages/flutter_blue_plus/example/macos/Runner/Info.plist similarity index 100% rename from example/macos/Runner/Info.plist rename to packages/flutter_blue_plus/example/macos/Runner/Info.plist diff --git a/example/macos/Runner/MainFlutterWindow.swift b/packages/flutter_blue_plus/example/macos/Runner/MainFlutterWindow.swift similarity index 100% rename from example/macos/Runner/MainFlutterWindow.swift rename to packages/flutter_blue_plus/example/macos/Runner/MainFlutterWindow.swift diff --git a/example/macos/Runner/Release.entitlements b/packages/flutter_blue_plus/example/macos/Runner/Release.entitlements similarity index 100% rename from example/macos/Runner/Release.entitlements rename to packages/flutter_blue_plus/example/macos/Runner/Release.entitlements diff --git a/example/macos/RunnerTests/RunnerTests.swift b/packages/flutter_blue_plus/example/macos/RunnerTests/RunnerTests.swift similarity index 100% rename from example/macos/RunnerTests/RunnerTests.swift rename to packages/flutter_blue_plus/example/macos/RunnerTests/RunnerTests.swift diff --git a/packages/flutter_blue_plus/example/pubspec.lock b/packages/flutter_blue_plus/example/pubspec.lock new file mode 100644 index 00000000..fb57eafd --- /dev/null +++ b/packages/flutter_blue_plus/example/pubspec.lock @@ -0,0 +1,107 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + characters: + dependency: transitive + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_blue_plus: + dependency: "direct main" + description: + path: ".." + relative: true + source: path + version: "1.33.0" + flutter_blue_plus_android: + dependency: "direct overridden" + description: + path: "../../flutter_blue_plus_android" + relative: true + source: path + version: "1.33.0" + flutter_blue_plus_darwin: + dependency: "direct overridden" + description: + path: "../../flutter_blue_plus_darwin" + relative: true + source: path + version: "1.33.0" + flutter_blue_plus_platform_interface: + dependency: "direct overridden" + description: + path: "../../flutter_blue_plus_platform_interface" + relative: true + source: path + version: "1.0.0" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" + source: hosted + version: "0.11.1" + meta: + dependency: transitive + description: + name: meta + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" + source: hosted + version: "1.15.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" +sdks: + dart: ">=3.3.0-0 <4.0.0" diff --git a/packages/flutter_blue_plus/example/pubspec.yaml b/packages/flutter_blue_plus/example/pubspec.yaml new file mode 100644 index 00000000..c599d728 --- /dev/null +++ b/packages/flutter_blue_plus/example/pubspec.yaml @@ -0,0 +1,29 @@ +name: flutter_blue_plus_example +description: Demonstrates how to use the flutter_blue_plus plugin. + +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' + +environment: + sdk: ">=2.15.1 <3.0.0" + +dependencies: + flutter: + sdk: flutter + flutter_blue_plus: ^1.33.0 + +# Note: We use path dependency overrides because the example app & plugin are bundled together. +# In *your* app you should omit this dependency overrides section. +dependency_overrides: + flutter_blue_plus: + path: ../ + flutter_blue_plus_android: + path: ../../flutter_blue_plus_android + flutter_blue_plus_darwin: + path: ../../flutter_blue_plus_darwin + flutter_blue_plus_platform_interface: + path: ../../flutter_blue_plus_platform_interface + +flutter: + uses-material-design: true diff --git a/lib/flutter_blue_plus.dart b/packages/flutter_blue_plus/lib/flutter_blue_plus.dart similarity index 63% rename from lib/flutter_blue_plus.dart rename to packages/flutter_blue_plus/lib/flutter_blue_plus.dart index b174f6a2..06215d33 100644 --- a/lib/flutter_blue_plus.dart +++ b/packages/flutter_blue_plus/lib/flutter_blue_plus.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -7,15 +7,15 @@ library flutter_blue_plus; import 'dart:async'; import 'dart:io'; -import 'package:flutter/services.dart'; +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; + +export 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; part 'src/bluetooth_characteristic.dart'; part 'src/bluetooth_descriptor.dart'; part 'src/bluetooth_device.dart'; -part 'src/bluetooth_msgs.dart'; part 'src/bluetooth_events.dart'; part 'src/bluetooth_service.dart'; part 'src/bluetooth_utils.dart'; part 'src/flutter_blue_plus.dart'; -part 'src/guid.dart'; part 'src/utils.dart'; diff --git a/lib/src/bluetooth_characteristic.dart b/packages/flutter_blue_plus/lib/src/bluetooth_characteristic.dart similarity index 89% rename from lib/src/bluetooth_characteristic.dart rename to packages/flutter_blue_plus/lib/src/bluetooth_characteristic.dart index 0ef7610b..5f7fe266 100644 --- a/lib/src/bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus/lib/src/bluetooth_characteristic.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -56,10 +56,7 @@ class BluetoothCharacteristic { /// - anytime `write()` is called /// - anytime a notification arrives (if subscribed) /// - and when first listened to, it re-emits the last value for convenience - Stream> get lastValueStream => FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnCharacteristicReceived" || m.method == "OnCharacteristicWritten") - .map((m) => m.arguments) - .map((args) => BmCharacteristicData.fromMap(args)) + Stream> get lastValueStream => _mergeStreams([FlutterBluePlusPlatform.instance.onCharacteristicReceived, FlutterBluePlusPlatform.instance.onCharacteristicWritten]) .where((p) => p.remoteId == remoteId) .where((p) => p.serviceUuid == serviceUuid) .where((p) => p.characteristicUuid == characteristicUuid) @@ -70,10 +67,7 @@ class BluetoothCharacteristic { /// this stream emits values: /// - anytime `read()` is called /// - anytime a notification arrives (if subscribed) - Stream> get onValueReceived => FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnCharacteristicReceived") - .map((m) => m.arguments) - .map((args) => BmCharacteristicData.fromMap(args)) + Stream> get onValueReceived => FlutterBluePlusPlatform.instance.onCharacteristicReceived .where((p) => p.remoteId == remoteId) .where((p) => p.serviceUuid == serviceUuid) .where((p) => p.characteristicUuid == characteristicUuid) @@ -115,10 +109,7 @@ class BluetoothCharacteristic { secondaryServiceUuid: null, ); - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnCharacteristicReceived") - .map((m) => m.arguments) - .map((args) => BmCharacteristicData.fromMap(args)) + var responseStream = FlutterBluePlusPlatform.instance.onCharacteristicReceived .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid); @@ -127,7 +118,7 @@ class BluetoothCharacteristic { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod('readCharacteristic', request.toMap()); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.readCharacteristic(request), 'readCharacteristic', request.toMap()); // wait for response BmCharacteristicData response = await futureResponse @@ -150,7 +141,7 @@ class BluetoothCharacteristic { } /// Writes a characteristic. - /// - [withoutResponse]: + /// - [withoutResponse]: /// If `true`, the write is not guaranteed and always returns immediately with success. /// If `false`, the write returns error on failure. /// - [allowLongWrite]: if set, larger writes > MTU are allowed (up to 512 bytes). @@ -189,10 +180,7 @@ class BluetoothCharacteristic { value: value, ); - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnCharacteristicWritten") - .map((m) => m.arguments) - .map((args) => BmCharacteristicData.fromMap(args)) + var responseStream = FlutterBluePlusPlatform.instance.onCharacteristicWritten .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid); @@ -201,7 +189,7 @@ class BluetoothCharacteristic { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod('writeCharacteristic', request.toMap()); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.writeCharacteristic(request), 'writeCharacteristic', request.toMap()); // wait for response so that we can: // 1. check for success (writeWithResponse) @@ -254,10 +242,7 @@ class BluetoothCharacteristic { // Notifications & Indications are configured by writing to the // Client Characteristic Configuration Descriptor (CCCD) - Stream responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDescriptorWritten") - .map((m) => m.arguments) - .map((args) => BmDescriptorData.fromMap(args)) + Stream responseStream = FlutterBluePlusPlatform.instance.onDescriptorWritten .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid) @@ -267,7 +252,7 @@ class BluetoothCharacteristic { Future futureResponse = responseStream.first; // invoke - bool hasCCCD = await FlutterBluePlus._invokeMethod('setNotifyValue', request.toMap()); + bool hasCCCD = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.setNotifyValue(request), 'setNotifyValue', request.toMap()); // wait for CCCD descriptor to be written? if (hasCCCD) { diff --git a/lib/src/bluetooth_descriptor.dart b/packages/flutter_blue_plus/lib/src/bluetooth_descriptor.dart similarity index 83% rename from lib/src/bluetooth_descriptor.dart rename to packages/flutter_blue_plus/lib/src/bluetooth_descriptor.dart index 041feb46..2f7b6f6c 100644 --- a/lib/src/bluetooth_descriptor.dart +++ b/packages/flutter_blue_plus/lib/src/bluetooth_descriptor.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -42,10 +42,7 @@ class BluetoothDescriptor { /// - anytime `read()` is called /// - anytime `write()` is called /// - and when first listened to, it re-emits the last value for convenience - Stream> get lastValueStream => FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDescriptorRead" || m.method == "OnDescriptorWritten") - .map((m) => m.arguments) - .map((args) => BmDescriptorData.fromMap(args)) + Stream> get lastValueStream => _mergeStreams([FlutterBluePlusPlatform.instance.onDescriptorRead, FlutterBluePlusPlatform.instance.onDescriptorWritten]) .where((p) => p.remoteId == remoteId) .where((p) => p.characteristicUuid == characteristicUuid) .where((p) => p.serviceUuid == serviceUuid) @@ -56,10 +53,7 @@ class BluetoothDescriptor { /// this stream emits values: /// - anytime `read()` is called - Stream> get onValueReceived => FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDescriptorRead") - .map((m) => m.arguments) - .map((args) => BmDescriptorData.fromMap(args)) + Stream> get onValueReceived => FlutterBluePlusPlatform.instance.onDescriptorRead .where((p) => p.remoteId == remoteId) .where((p) => p.characteristicUuid == characteristicUuid) .where((p) => p.serviceUuid == serviceUuid) @@ -91,10 +85,7 @@ class BluetoothDescriptor { descriptorUuid: descriptorUuid, ); - Stream responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDescriptorRead") - .map((m) => m.arguments) - .map((args) => BmDescriptorData.fromMap(args)) + Stream responseStream = FlutterBluePlusPlatform.instance.onDescriptorRead .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid) @@ -104,7 +95,7 @@ class BluetoothDescriptor { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod('readDescriptor', request.toMap()); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.readDescriptor(request), 'readDescriptor', request.toMap()); // wait for response BmDescriptorData response = await futureResponse @@ -147,10 +138,7 @@ class BluetoothDescriptor { value: value, ); - Stream responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDescriptorWritten") - .map((m) => m.arguments) - .map((args) => BmDescriptorData.fromMap(args)) + Stream responseStream = FlutterBluePlusPlatform.instance.onDescriptorWritten .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid) @@ -160,7 +148,7 @@ class BluetoothDescriptor { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod('writeDescriptor', request.toMap()); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.writeDescriptor(request), 'writeDescriptor', request.toMap()); // wait for response BmDescriptorData response = await futureResponse diff --git a/lib/src/bluetooth_device.dart b/packages/flutter_blue_plus/lib/src/bluetooth_device.dart similarity index 88% rename from lib/src/bluetooth_device.dart rename to packages/flutter_blue_plus/lib/src/bluetooth_device.dart index ded23e7b..36b59454 100644 --- a/lib/src/bluetooth_device.dart +++ b/packages/flutter_blue_plus/lib/src/bluetooth_device.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -120,10 +120,7 @@ class BluetoothDevice { autoConnect: autoConnect, ); - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnConnectionStateChanged") - .map((m) => m.arguments) - .map((args) => BmConnectionStateResponse.fromMap(args)) + var responseStream = FlutterBluePlusPlatform.instance.onConnectionStateChanged .where((p) => p.remoteId == remoteId); // Start listening now, before invokeMethod, to ensure we don't miss the response @@ -135,7 +132,7 @@ class BluetoothDevice { } // invoke - bool changed = await FlutterBluePlus._invokeMethod('connect', request.toMap()); + bool changed = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.connect(request), 'connect', request.toMap()); // we return the disconnect mutex now so that this // connection attempt can be canceled by calling disconnect @@ -148,7 +145,7 @@ class BluetoothDevice { .fbpTimeout(timeout.inSeconds, "connect") .catchError((e) async { if (e is FlutterBluePlusException && e.code == FbpErrorCode.timeout.index) { - await FlutterBluePlus._invokeMethod('disconnect', remoteId.str); // cancel connection attempt + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.disconnect(remoteId), 'disconnect', remoteId.str); // cancel connection attempt } throw e; }); @@ -206,10 +203,7 @@ class BluetoothDevice { // remove from auto connect list if there FlutterBluePlus._autoConnect.remove(remoteId); - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnConnectionStateChanged") - .map((m) => m.arguments) - .map((args) => BmConnectionStateResponse.fromMap(args)) + var responseStream = FlutterBluePlusPlatform.instance.onConnectionStateChanged .where((p) => p.remoteId == remoteId) .where((p) => p.connectionState == BmConnectionStateEnum.disconnected); @@ -220,7 +214,7 @@ class BluetoothDevice { await _ensureAndroidDisconnectionDelay(androidDelay); // invoke - bool changed = await FlutterBluePlus._invokeMethod('disconnect', remoteId.str); + bool changed = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.disconnect(remoteId), 'disconnect', remoteId.str); // only wait for disconnection if weren't already disconnected if (changed) { @@ -257,17 +251,14 @@ class BluetoothDevice { List result = []; try { - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDiscoveredServices") - .map((m) => m.arguments) - .map((args) => BmDiscoverServicesResult.fromMap(args)) + var responseStream = FlutterBluePlusPlatform.instance.onDiscoveredServices .where((p) => p.remoteId == remoteId); // Start listening now, before invokeMethod, to ensure we don't miss the response Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod('discoverServices', remoteId.str); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.discoverServices(remoteId), 'discoverServices', remoteId.str); // wait for response BmDiscoverServicesResult response = await futureResponse @@ -317,10 +308,7 @@ class BluetoothDevice { if (FlutterBluePlus._connectionStates[remoteId] != null) { initialValue = _bmToConnectionState(FlutterBluePlus._connectionStates[remoteId]!.connectionState); } - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnConnectionStateChanged") - .map((m) => m.arguments) - .map((args) => BmConnectionStateResponse.fromMap(args)) + return FlutterBluePlusPlatform.instance.onConnectionStateChanged .where((p) => p.remoteId == remoteId) .map((p) => _bmToConnectionState(p.connectionState)) .newStreamWithInitialValue(initialValue); @@ -338,10 +326,7 @@ class BluetoothDevice { Stream get mtu { // get initial value from our cache int initialValue = FlutterBluePlus._mtuValues[remoteId]?.mtu ?? 23; - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnMtuChanged") - .map((m) => m.arguments) - .map((args) => BmMtuChangedResponse.fromMap(args)) + return FlutterBluePlus._onMtuChanged .where((p) => p.remoteId == remoteId) .map((p) => p.mtu) .newStreamWithInitialValue(initialValue); @@ -351,10 +336,7 @@ class BluetoothDevice { /// - uses the GAP Services Changed characteristic (0x2A05) /// - you must re-call discoverServices() when services are reset Stream get onServicesReset { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnServicesReset") - .map((m) => m.arguments) - .map((args) => BmBluetoothDevice.fromMap(args)) + return FlutterBluePlusPlatform.instance.onServicesReset .where((p) => p.remoteId == remoteId) .map((m) => null); } @@ -374,17 +356,14 @@ class BluetoothDevice { int rssi = 0; try { - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnReadRssi") - .map((m) => m.arguments) - .map((args) => BmReadRssiResult.fromMap(args)) + var responseStream = FlutterBluePlusPlatform.instance.onReadRssi .where((p) => (p.remoteId == remoteId)); // Start listening now, before invokeMethod, to ensure we don't miss the response Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod('readRssi', remoteId.str); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.readRssi(remoteId), 'readRssi', remoteId.str); // wait for response BmReadRssiResult response = await futureResponse @@ -452,10 +431,7 @@ class BluetoothDevice { mtu: desiredMtu, ); - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnMtuChanged") - .map((m) => m.arguments) - .map((args) => BmMtuChangedResponse.fromMap(args)) + var responseStream = FlutterBluePlus._onMtuChanged .where((p) => p.remoteId == remoteId) .map((p) => p.mtu); @@ -463,7 +439,7 @@ class BluetoothDevice { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod('requestMtu', request.toMap()); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.requestMtu(request), 'requestMtu', request.toMap()); // wait for response mtu = await futureResponse @@ -497,7 +473,7 @@ class BluetoothDevice { ); // invoke - await FlutterBluePlus._invokeMethod('requestConnectionPriority', request.toMap()); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.requestConnectionPriority(request), 'requestConnectionPriority', request.toMap()); } /// Set the preferred connection (Android Only) @@ -530,7 +506,7 @@ class BluetoothDevice { ); // invoke - await FlutterBluePlus._invokeMethod('setPreferredPhy', request.toMap()); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.setPreferredPhy(request), 'setPreferredPhy', request.toMap()); } /// Force the bonding popup to show now (Android Only) @@ -552,10 +528,7 @@ class BluetoothDevice { await mtx.take(); try { - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnBondStateChanged") - .map((m) => m.arguments) - .map((args) => BmBondStateResponse.fromMap(args)) + var responseStream = FlutterBluePlusPlatform.instance.onBondStateChanged .where((p) => p.remoteId == remoteId) .where((p) => p.bondState != BmBondStateEnum.bonding); @@ -563,7 +536,7 @@ class BluetoothDevice { Future futureResponse = responseStream.first; // invoke - bool changed = await FlutterBluePlus._invokeMethod('createBond', remoteId.str); + bool changed = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.createBond(remoteId), 'createBond', remoteId.str); // only wait for 'bonded' if we weren't already bonded if (changed) { @@ -595,10 +568,7 @@ class BluetoothDevice { await mtx.take(); try { - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnBondStateChanged") - .map((m) => m.arguments) - .map((args) => BmBondStateResponse.fromMap(args)) + var responseStream = FlutterBluePlusPlatform.instance.onBondStateChanged .where((p) => p.remoteId == remoteId) .where((p) => p.bondState != BmBondStateEnum.bonding); @@ -606,7 +576,7 @@ class BluetoothDevice { Future futureResponse = responseStream.first; // invoke - bool changed = await FlutterBluePlus._invokeMethod('removeBond', remoteId.str); + bool changed = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.removeBond(remoteId), 'removeBond', remoteId.str); // only wait for 'unbonded' state if we weren't already unbonded if (changed) { @@ -641,7 +611,7 @@ class BluetoothDevice { } // invoke - await FlutterBluePlus._invokeMethod('clearGattCache', remoteId.str); + await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.clearGattCache(remoteId), 'clearGattCache', remoteId.str); } /// Get the current bondState of the device (Android Only) @@ -653,19 +623,14 @@ class BluetoothDevice { // get current state if needed if (FlutterBluePlus._bondStates[remoteId] == null) { - var val = await FlutterBluePlus._methodChannel - .invokeMethod('getBondState', remoteId.str) - .then((args) => BmBondStateResponse.fromMap(args)); + var val = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.getBondState(remoteId), 'getBondState', remoteId.str); // update _bondStates if it is still null after the await if (FlutterBluePlus._bondStates[remoteId] == null) { FlutterBluePlus._bondStates[remoteId] = val; } } - yield* FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnBondStateChanged") - .map((m) => m.arguments) - .map((args) => BmBondStateResponse.fromMap(args)) + yield* FlutterBluePlusPlatform.instance.onBondStateChanged .where((p) => p.remoteId == remoteId) .map((p) => _bmToBondState(p.bondState)) .newStreamWithInitialValue(_bmToBondState(FlutterBluePlus._bondStates[remoteId]!.bondState)); diff --git a/lib/src/bluetooth_events.dart b/packages/flutter_blue_plus/lib/src/bluetooth_events.dart similarity index 76% rename from lib/src/bluetooth_events.dart rename to packages/flutter_blue_plus/lib/src/bluetooth_events.dart index e74bde23..d493fba2 100644 --- a/lib/src/bluetooth_events.dart +++ b/packages/flutter_blue_plus/lib/src/bluetooth_events.dart @@ -1,91 +1,63 @@ +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + part of flutter_blue_plus; class BluetoothEvents { Stream get onConnectionStateChanged { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnConnectionStateChanged") - .map((m) => m.arguments) - .map((args) => BmConnectionStateResponse.fromMap(args)) + return FlutterBluePlusPlatform.instance.onConnectionStateChanged .map((p) => OnConnectionStateChangedEvent(p)); } Stream get onMtuChanged { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnMtuChanged") - .map((m) => m.arguments) - .map((args) => BmMtuChangedResponse.fromMap(args)) + return FlutterBluePlus._onMtuChanged .map((p) => OnMtuChangedEvent(p)); } Stream get onReadRssi { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnReadRssi") - .map((m) => m.arguments) - .map((args) => BmReadRssiResult.fromMap(args)) + return FlutterBluePlusPlatform.instance.onReadRssi .map((p) => OnReadRssiEvent(p)); } Stream get onServicesReset { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnServicesReset") - .map((m) => m.arguments) - .map((args) => BmBluetoothDevice.fromMap(args)) + return FlutterBluePlusPlatform.instance.onServicesReset .map((p) => OnServicesResetEvent(p)); } Stream get onDiscoveredServices { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDiscoveredServices") - .map((m) => m.arguments) - .map((args) => BmDiscoverServicesResult.fromMap(args)) + return FlutterBluePlusPlatform.instance.onDiscoveredServices .map((p) => OnDiscoveredServicesEvent(p)); } Stream get onCharacteristicReceived { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnCharacteristicReceived") - .map((m) => m.arguments) - .map((args) => BmCharacteristicData.fromMap(args)) + return FlutterBluePlusPlatform.instance.onCharacteristicReceived .map((p) => OnCharacteristicReceivedEvent(p)); } Stream get onCharacteristicWritten { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnCharacteristicWritten") - .map((m) => m.arguments) - .map((args) => BmCharacteristicData.fromMap(args)) + return FlutterBluePlusPlatform.instance.onCharacteristicWritten .map((p) => OnCharacteristicWrittenEvent(p)); } Stream get onDescriptorRead { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDescriptorRead") - .map((m) => m.arguments) - .map((args) => BmDescriptorData.fromMap(args)) + return FlutterBluePlusPlatform.instance.onDescriptorRead .map((p) => OnDescriptorReadEvent(p)); } Stream get onDescriptorWritten { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnDescriptorWritten") - .map((m) => m.arguments) - .map((args) => BmDescriptorData.fromMap(args)) + return FlutterBluePlusPlatform.instance.onDescriptorWritten .map((p) => OnDescriptorWrittenEvent(p)); } Stream get onNameChanged { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnNameChanged") - .map((m) => m.arguments) - .map((args) => BmBluetoothDevice.fromMap(args)) + return FlutterBluePlusPlatform.instance.onNameChanged + .map((p) => BmBluetoothDevice(remoteId: p.remoteId, platformName: p.name)) .map((p) => OnNameChangedEvent(p)); } Stream get onBondStateChanged { - return FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnBondStateChanged") - .map((m) => m.arguments) - .map((args) => BmBondStateResponse.fromMap(args)) + return FlutterBluePlusPlatform.instance.onBondStateChanged .map((p) => OnBondStateChangedEvent(p)); } } diff --git a/lib/src/bluetooth_service.dart b/packages/flutter_blue_plus/lib/src/bluetooth_service.dart similarity index 94% rename from lib/src/bluetooth_service.dart rename to packages/flutter_blue_plus/lib/src/bluetooth_service.dart index 3e3e10ce..89c6f830 100644 --- a/lib/src/bluetooth_service.dart +++ b/packages/flutter_blue_plus/lib/src/bluetooth_service.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. diff --git a/lib/src/bluetooth_utils.dart b/packages/flutter_blue_plus/lib/src/bluetooth_utils.dart similarity index 95% rename from lib/src/bluetooth_utils.dart rename to packages/flutter_blue_plus/lib/src/bluetooth_utils.dart index 793104cc..b3e2de8d 100644 --- a/lib/src/bluetooth_utils.dart +++ b/packages/flutter_blue_plus/lib/src/bluetooth_utils.dart @@ -1,3 +1,7 @@ +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + part of flutter_blue_plus; /// State of the bluetooth adapter. diff --git a/lib/src/flutter_blue_plus.dart b/packages/flutter_blue_plus/lib/src/flutter_blue_plus.dart similarity index 82% rename from lib/src/flutter_blue_plus.dart rename to packages/flutter_blue_plus/lib/src/flutter_blue_plus.dart index 1b872201..f1ccb8c3 100644 --- a/lib/src/flutter_blue_plus.dart +++ b/packages/flutter_blue_plus/lib/src/flutter_blue_plus.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -11,13 +11,6 @@ class FlutterBluePlus { static bool _initialized = false; - /// native platform channel - static final MethodChannel _methodChannel = const MethodChannel('flutter_blue_plus/methods'); - - /// a broadcast stream version of the MethodChannel - // ignore: close_sinks - static final StreamController _methodStream = StreamController.broadcast(); - // always keep track of these device variables static final Map _connectionStates = {}; static final Map _knownServices = {}; @@ -39,6 +32,12 @@ class FlutterBluePlus { /// stream used for the scanResults public api static final _scanResults = _StreamControllerReEmit>(initialValue: []); + /// stream used for merging internal and external changes to the mtu + static final _onMtuChanged = _mergeStreams([_onMtuChangedController.stream, FlutterBluePlusPlatform.instance.onMtuChanged]); + + /// stream used for internal changes to the mtu when the connection state changes + static final _onMtuChangedController = StreamController.broadcast(); + /// buffers the scan results static _BufferStream? _scanBuffer; @@ -62,14 +61,14 @@ class FlutterBluePlus { static LogLevel get logLevel => _logLevel; /// Checks whether the hardware supports Bluetooth - static Future get isSupported async => await _invokeMethod('isSupported'); + static Future get isSupported async => await _invokeMethod(() => FlutterBluePlusPlatform.instance.isSupported(), 'isSupported'); /// The current adapter state static BluetoothAdapterState get adapterStateNow => _adapterStateNow != null ? _bmToAdapterState(_adapterStateNow!) : BluetoothAdapterState.unknown; /// Return the friendly Bluetooth name of the local Bluetooth adapter - static Future get adapterName async => await _invokeMethod('getAdapterName'); + static Future get adapterName async => await _invokeMethod(() => FlutterBluePlusPlatform.instance.getAdapterName(), 'getAdapterName'); /// returns whether we are scanning as a stream static Stream get isScanning => _isScanning.stream; @@ -108,21 +107,20 @@ class FlutterBluePlus { static Future setOptions({ bool showPowerAlert = true, }) async { - await _invokeMethod('setOptions', {"show_power_alert": showPowerAlert}); + final options = Options(showPowerAlert: showPowerAlert); + + await _invokeMethod(() => FlutterBluePlusPlatform.instance.setOptions(options), 'setOptions', options.toMap()); } /// Turn on Bluetooth (Android only), static Future turnOn({int timeout = 60}) async { - var responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnTurnOnResponse") - .map((m) => m.arguments) - .map((args) => BmTurnOnResponse.fromMap(args)); + var responseStream = FlutterBluePlusPlatform.instance.onTurnOnResponse; // Start listening now, before invokeMethod, to ensure we don't miss the response Future futureResponse = responseStream.first; // invoke - bool changed = await _invokeMethod('turnOn'); + bool changed = await _invokeMethod(() => FlutterBluePlusPlatform.instance.turnOn(), 'turnOn'); // only wait if bluetooth was off if (changed) { @@ -143,18 +141,14 @@ class FlutterBluePlus { static Stream get adapterState async* { // get current state if needed if (_adapterStateNow == null) { - var result = await _invokeMethod('getAdapterState'); - var value = BmBluetoothAdapterState.fromMap(result).adapterState; + var result = await _invokeMethod(() => FlutterBluePlusPlatform.instance.getAdapterState(), 'getAdapterState'); // update _adapterStateNow if it is still null after the await if (_adapterStateNow == null) { - _adapterStateNow = value; + _adapterStateNow = result.adapterState; } } - yield* FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnAdapterStateChanged") - .map((m) => m.arguments) - .map((args) => BmBluetoothAdapterState.fromMap(args)) + yield* FlutterBluePlusPlatform.instance.onAdapterStateChanged .map((s) => _bmToAdapterState(s.adapterState)) .newStreamWithInitialValue(_bmToAdapterState(_adapterStateNow!)); } @@ -170,26 +164,24 @@ class FlutterBluePlus { /// - The list includes devices connected to by *any* app /// - You must still call device.connect() to connect them to *your app* static Future> get systemDevices async { - var result = await _invokeMethod('getSystemDevices'); - var r = BmDevicesList.fromMap(result); - for (BmBluetoothDevice device in r.devices) { + var result = await _invokeMethod(() => FlutterBluePlusPlatform.instance.getSystemDevices(), 'getSystemDevices'); + for (BmBluetoothDevice device in result) { if (device.platformName != null) { _platformNames[device.remoteId] = device.platformName!; } } - return r.devices.map((d) => BluetoothDevice.fromId(d.remoteId.str)).toList(); + return result.map((d) => BluetoothDevice.fromId(d.remoteId.str)).toList(); } /// Retrieve a list of bonded devices (Android only) static Future> get bondedDevices async { - var result = await _invokeMethod('getBondedDevices'); - var r = BmDevicesList.fromMap(result); - for (BmBluetoothDevice device in r.devices) { + var result = await _invokeMethod(() => FlutterBluePlusPlatform.instance.getBondedDevices(), 'getBondedDevices'); + for (BmBluetoothDevice device in result) { if (device.platformName != null) { _platformNames[device.remoteId] = device.platformName!; } } - return r.devices.map((d) => BluetoothDevice.fromId(d.remoteId.str)).toList(); + return result.map((d) => BluetoothDevice.fromId(d.remoteId.str)).toList(); } /// Start a scan, and return a stream of results @@ -277,16 +269,13 @@ class FlutterBluePlus { androidScanMode: androidScanMode.value, androidUsesFineLocation: androidUsesFineLocation); - Stream responseStream = FlutterBluePlus._methodStream.stream - .where((m) => m.method == "OnScanResponse") - .map((m) => m.arguments) - .map((args) => BmScanResponse.fromMap(args)); + Stream responseStream = FlutterBluePlusPlatform.instance.onScanResponse; // Start listening now, before invokeMethod, so we do not miss any results _scanBuffer = _BufferStream.listen(responseStream); // invoke platform method - await _invokeMethod('startScan', settings.toMap()).onError((e, s) => _stopScan(invokePlatform: false)); + await _invokeMethod(() => FlutterBluePlusPlatform.instance.startScan(settings), 'startScan', settings.toMap()).onError((e, s) => _stopScan(invokePlatform: false)); // check every 250ms for gone devices? late Stream outputStream = removeIfGone != null @@ -379,7 +368,7 @@ class FlutterBluePlus { subscription.cancel(); } if (invokePlatform) { - await _invokeMethod('stopScan'); + await _invokeMethod(() => FlutterBluePlusPlatform.instance.stopScan(), 'stopScan'); } } @@ -395,7 +384,7 @@ class FlutterBluePlus { static Future setLogLevel(LogLevel level, {color = true}) async { _logLevel = level; _logColor = color; - await _invokeMethod('setLogLevel', level.index); + await _invokeMethod(() => FlutterBluePlusPlatform.instance.setLogLevel(level), 'setLogLevel', level.index); } /// Request Bluetooth PHY support @@ -406,7 +395,7 @@ class FlutterBluePlus { ErrorPlatform.fbp, "getPhySupport", FbpErrorCode.androidOnly.index, "android-only"); } - return await _invokeMethod('getPhySupport').then((args) => PhySupport.fromMap(args)); + return await _invokeMethod(() => FlutterBluePlusPlatform.instance.getPhySupport(), 'getPhySupport'); } static Future _initFlutterBluePlus() async { @@ -416,39 +405,16 @@ class FlutterBluePlus { _initialized = true; - // set platform method handler - _methodChannel.setMethodCallHandler(_methodCallHandler); - - // flutter restart - wait for all devices to disconnect - if ((await _methodChannel.invokeMethod('flutterRestart')) != 0) { - await Future.delayed(Duration(milliseconds: 50)); - while ((await _methodChannel.invokeMethod('connectedCount')) != 0) { - await Future.delayed(Duration(milliseconds: 50)); - } - } - } - - static Future _methodCallHandler(MethodCall call) async { - // log result - if (logLevel == LogLevel.verbose) { - String func = '[[ ${call.method} ]]'; - String result = call.arguments.toString(); - func = _logColor ? _black(func) : func; - result = _logColor ? _brown(result) : result; - print("[FBP] $func result: $result"); - } - // android only - if (call.method == "OnDetachedFromEngine") { - _stopScan(invokePlatform: false); - } + FlutterBluePlusPlatform.instance.onDetachedFromEngine.log('OnDetachedFromEngine').listen((_) async { + await _stopScan(invokePlatform: false); + }); // keep track of adapter states - if (call.method == "OnAdapterStateChanged") { - BmBluetoothAdapterState r = BmBluetoothAdapterState.fromMap(call.arguments); + FlutterBluePlusPlatform.instance.onAdapterStateChanged.log('OnAdapterStateChanged', (r) => r.toMap()).listen((r) async { _adapterStateNow = r.adapterState; if (isScanningNow && r.adapterState != BmAdapterStateEnum.on) { - _stopScan(invokePlatform: false); + await _stopScan(invokePlatform: false); } if (r.adapterState == BmAdapterStateEnum.on) { for (DeviceIdentifier d in _autoConnect) { @@ -459,17 +425,16 @@ class FlutterBluePlus { }); } } - } + }); - // keep track of connection states - if (call.method == "OnConnectionStateChanged") { - var r = BmConnectionStateResponse.fromMap(call.arguments); + // keep track of connection states and cancel delayed subscriptions + FlutterBluePlusPlatform.instance.onConnectionStateChanged.log('OnConnectionStateChanged', (r) => r.toMap()).listen((r) async { _connectionStates[r.remoteId] = r; + if (r.connectionState == BmConnectionStateEnum.disconnected) { // push to mtu stream, if needed if (_mtuValues.containsKey(r.remoteId)) { - var resp = BmMtuChangedResponse(remoteId: r.remoteId, mtu: 23); - _methodStream.add(MethodCall("OnMtuChanged", resp.toMap())); + _onMtuChangedController.add(BmMtuChangedResponse(remoteId: r.remoteId, mtu: 23)); } // clear mtu @@ -503,88 +468,84 @@ class FlutterBluePlus { } } } - } + + if (_delayedSubscriptions.isNotEmpty) { + if (r.connectionState == BmConnectionStateEnum.disconnected) { + var remoteId = r.remoteId; + // use delayed to update the stream before we cancel it + await Future.delayed(Duration.zero).then((_) { + _delayedSubscriptions[remoteId]?.forEach((s) => s.cancel()); // cancel + _delayedSubscriptions.remove(remoteId); // delete + }); + } + } + }); // keep track of device name - if (call.method == "OnNameChanged") { - var device = BmNameChanged.fromMap(call.arguments); + FlutterBluePlusPlatform.instance.onNameChanged.log('OnNameChanged', (r) => r.toMap()).listen((r) { if (Platform.isMacOS || Platform.isIOS) { // iOS & macOS internally use the name changed callback for the platform name - _platformNames[device.remoteId] = device.name; + _platformNames[r.remoteId] = r.name; } - } + }); // keep track of services resets - if (call.method == "OnServicesReset") { - var r = BmBluetoothDevice.fromMap(call.arguments); + FlutterBluePlusPlatform.instance.onServicesReset.log('OnServicesReset', (r) => r.toMap()).listen((r) { _knownServices.remove(r.remoteId); - } + }); // keep track of bond state - if (call.method == "OnBondStateChanged") { - var r = BmBondStateResponse.fromMap(call.arguments); + FlutterBluePlusPlatform.instance.onBondStateChanged.log('OnBondStateChanged', (r) => r.toMap()).listen((r) { _bondStates[r.remoteId] = r; - } + }); // keep track of services - if (call.method == "OnDiscoveredServices") { - var r = BmDiscoverServicesResult.fromMap(call.arguments); + FlutterBluePlusPlatform.instance.onDiscoveredServices.log('OnDiscoveredServices', (r) => r.toMap()).listen((r) { if (r.success == true) { _knownServices[r.remoteId] = r; } - } + }); // keep track of mtu values - if (call.method == "OnMtuChanged") { - var r = BmMtuChangedResponse.fromMap(call.arguments); + FlutterBluePlusPlatform.instance.onMtuChanged.log('OnMtuChanged', (r) => r.toMap()).listen((r) { if (r.success == true) { _mtuValues[r.remoteId] = r; } - } + }); // keep track of characteristic values - if (call.method == "OnCharacteristicReceived" || call.method == "OnCharacteristicWritten") { - var r = BmCharacteristicData.fromMap(call.arguments); + _mergeStreams([FlutterBluePlusPlatform.instance.onCharacteristicReceived.log('OnCharacteristicReceived', (r) => r.toMap()), FlutterBluePlusPlatform.instance.onCharacteristicWritten.log('OnCharacteristicWritten', (r) => r.toMap())]).listen((r) { if (r.success == true) { _lastChrs[r.remoteId] ??= {}; _lastChrs[r.remoteId]!["${r.serviceUuid}:${r.characteristicUuid}"] = r.value; } - } + }); // keep track of descriptor values - if (call.method == "OnDescriptorRead" || call.method == "OnDescriptorWritten") { - var r = BmDescriptorData.fromMap(call.arguments); + _mergeStreams([FlutterBluePlusPlatform.instance.onDescriptorRead.log('OnDescriptorRead', (r) => r.toMap()), FlutterBluePlusPlatform.instance.onDescriptorWritten.log('OnDescriptorWritten', (r) => r.toMap())]).listen((r) { if (r.success == true) { _lastDescs[r.remoteId] ??= {}; _lastDescs[r.remoteId]!["${r.serviceUuid}:${r.characteristicUuid}:${r.descriptorUuid}"] = r.value; } - } - - _methodStream.add(call); + }); - // cancel delayed subscriptions - if (call.method == "OnConnectionStateChanged") { - if (_delayedSubscriptions.isNotEmpty) { - var r = BmConnectionStateResponse.fromMap(call.arguments); - if (r.connectionState == BmConnectionStateEnum.disconnected) { - var remoteId = r.remoteId; - // use delayed to update the stream before we cancel it - Future.delayed(Duration.zero).then((_) { - _delayedSubscriptions[remoteId]?.forEach((s) => s.cancel()); // cancel - _delayedSubscriptions.remove(remoteId); // delete - }); - } + // flutter restart - wait for all devices to disconnect + if ((await _invokeMethod(() => FlutterBluePlusPlatform.instance.flutterRestart(), 'flutterRestart')) != 0) { + await Future.delayed(Duration(milliseconds: 50)); + while ((await _invokeMethod(() => FlutterBluePlusPlatform.instance.connectedCount(), 'connectedCount')) != 0) { + await Future.delayed(Duration(milliseconds: 50)); } } } /// invoke a platform method - static Future _invokeMethod( + static Future _invokeMethod( + Future Function() invoke, String method, [ dynamic arguments, ]) async { // return value - dynamic out; + T out; // only allow 1 invocation at a time (guarantees that hot restart finishes) _Mutex mtx = _MutexFactory.getMutexForKey("invokeMethod"); @@ -606,7 +567,7 @@ class FlutterBluePlus { } // invoke - out = await _methodChannel.invokeMethod(method, arguments); + out = await invoke(); // log result if (logLevel == LogLevel.verbose) { @@ -632,7 +593,7 @@ class FlutterBluePlus { Future futureResponse = responseStream.first; // invoke - await _invokeMethod('turnOff'); + await _invokeMethod(() => FlutterBluePlusPlatform.instance.turnOff(), 'turnOff'); // wait for response await futureResponse.fbpTimeout(timeout, "turnOff"); @@ -661,16 +622,6 @@ class FlutterBluePlus { static Stream scan() => throw Exception; } -/// Log levels for FlutterBlue -enum LogLevel { - none, //0 - error, // 1 - warning, // 2 - info, // 3 - debug, // 4 - verbose, //5 -} - class AndroidScanMode { const AndroidScanMode(this.value); static const lowPower = AndroidScanMode(0); @@ -720,23 +671,6 @@ class ServiceDataFilter { } } -class DeviceIdentifier { - final String str; - const DeviceIdentifier(this.str); - - @override - String toString() => str; - - @override - int get hashCode => str.hashCode; - - @override - bool operator ==(other) => other is DeviceIdentifier && _compareAsciiLowerCase(str, other.str) == 0; - - @Deprecated('Use str instead') - String get id => str; -} - class ScanResult { final BluetoothDevice device; final AdvertisementData advertisementData; @@ -828,23 +762,6 @@ class AdvertisementData { String get localName => advName; } -class PhySupport { - /// High speed (PHY 2M) - final bool le2M; - - /// Long range (PHY codec) - final bool leCoded; - - PhySupport({required this.le2M, required this.leCoded}); - - factory PhySupport.fromMap(Map json) { - return PhySupport( - le2M: json['le_2M'], - leCoded: json['le_coded'], - ); - } -} - enum ErrorPlatform { fbp, android, diff --git a/lib/src/utils.dart b/packages/flutter_blue_plus/lib/src/utils.dart similarity index 87% rename from lib/src/utils.dart rename to packages/flutter_blue_plus/lib/src/utils.dart index f9202d9a..8c0f8da3 100644 --- a/lib/src/utils.dart +++ b/packages/flutter_blue_plus/lib/src/utils.dart @@ -1,57 +1,8 @@ -part of flutter_blue_plus; - -String _hexEncode(List numbers) { - return numbers.map((n) => (n & 0xFF).toRadixString(16).padLeft(2, '0')).join(); -} - -List? _tryHexDecode(String hex) { - List numbers = []; - for (int i = 0; i < hex.length; i += 2) { - String hexPart = hex.substring(i, i + 2); - int? num = int.tryParse(hexPart, radix: 16); - if (num == null) { - return null; - } - numbers.add(num); - } - return numbers; -} - -List _hexDecode(String hex) { - List numbers = []; - for (int i = 0; i < hex.length; i += 2) { - String hexPart = hex.substring(i, i + 2); - int num = int.parse(hexPart, radix: 16); - numbers.add(num); - } - return numbers; -} +// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. -int _compareAsciiLowerCase(String a, String b) { - const int upperCaseA = 0x41; - const int upperCaseZ = 0x5a; - const int asciiCaseBit = 0x20; - var defaultResult = 0; - for (var i = 0; i < a.length; i++) { - if (i >= b.length) return 1; - var aChar = a.codeUnitAt(i); - var bChar = b.codeUnitAt(i); - if (aChar == bChar) continue; - var aLowerCase = aChar; - var bLowerCase = bChar; - // Upper case if ASCII letters. - if (upperCaseA <= bChar && bChar <= upperCaseZ) { - bLowerCase += asciiCaseBit; - } - if (upperCaseA <= aChar && aChar <= upperCaseZ) { - aLowerCase += asciiCaseBit; - } - if (aLowerCase != bLowerCase) return (aLowerCase - bLowerCase).sign; - if (defaultResult == 0) defaultResult = aChar - bChar; - } - if (b.length > a.length) return -1; - return defaultResult.sign; -} +part of flutter_blue_plus; extension AddOrUpdate on List { /// add an item to a list, or update item if it already exists @@ -349,6 +300,26 @@ extension _StreamNewStreamWithInitialValue on Stream { } } +extension _StreamLog on Stream { + Stream log(String method, [dynamic Function(T event)? arguments]) { + return transform( + StreamTransformer.fromHandlers( + handleData: (data, sink) { + if (FlutterBluePlus._logLevel == LogLevel.verbose) { + String func = '[[ ${method} ]]'; + String? result = arguments?.call(data)?.toString(); + func = FlutterBluePlus._logColor ? _black(func) : func; + result = result != null && FlutterBluePlus._logColor ? _brown(result) : result; + print("[FBP] $func result: $result"); + } + + sink.add(data); + }, + ), + ); + } +} + // ignore: unused_element Stream _mergeStreams(List> streams) { StreamController controller = StreamController(); diff --git a/packages/flutter_blue_plus/pubspec.yaml b/packages/flutter_blue_plus/pubspec.yaml new file mode 100644 index 00000000..4758aa4c --- /dev/null +++ b/packages/flutter_blue_plus/pubspec.yaml @@ -0,0 +1,38 @@ +name: flutter_blue_plus +description: Flutter plugin for connecting and communicating with Bluetooth Low Energy devices. +version: 1.33.0 +homepage: https://github.com/boskokg/flutter_blue_plus + +environment: + sdk: ">=2.12.0 <4.0.0" + flutter: ">=2.0.0" + +dependencies: + flutter: + sdk: flutter + flutter_blue_plus_android: ^1.33.0 + flutter_blue_plus_darwin: ^1.33.0 + flutter_blue_plus_platform_interface: ^1.0.0 + +dev_dependencies: + flutter_lints: ^4.0.0 + flutter_test: + sdk: flutter + +dependency_overrides: + flutter_blue_plus_android: + path: ../flutter_blue_plus_android + flutter_blue_plus_darwin: + path: ../flutter_blue_plus_darwin + flutter_blue_plus_platform_interface: + path: ../flutter_blue_plus_platform_interface + +flutter: + plugin: + platforms: + android: + default_package: flutter_blue_plus_android + ios: + default_package: flutter_blue_plus_darwin + macos: + default_package: flutter_blue_plus_darwin diff --git a/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java b/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java index f417f2cc..5020882a 100644 --- a/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java +++ b/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java @@ -280,7 +280,7 @@ public void onDetachedFromActivity() // ██████ ██ ██ ███████ ███████ @Override - @SuppressWarnings({"deprecation", "unchecked"}) // needed for compatibility, type safety uses bluetooth_msgs.dart + @SuppressWarnings({"deprecation", "unchecked"}) // needed for compatibility, type safety uses flutter_blue_plus_platform_interface public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { @@ -2021,7 +2021,7 @@ private ScanCallback getScanCallback() scanCallback = new ScanCallback() { @Override - @SuppressWarnings("unchecked") // type safety uses bluetooth_msgs.dart + @SuppressWarnings("unchecked") // type safety uses flutter_blue_plus_platform_interface public void onScanResult(int callbackType, ScanResult result) { log(LogLevel.VERBOSE, "onScanResult"); From 3b034b55c894ae9e4fdd4743cc1210a5e386392c Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 17:30:43 +0100 Subject: [PATCH 30/90] fix: remove erroneous android package directives --- packages/flutter_blue_plus_android/android/build.gradle | 2 -- packages/flutter_blue_plus_android/android/settings.gradle | 2 -- 2 files changed, 4 deletions(-) diff --git a/packages/flutter_blue_plus_android/android/build.gradle b/packages/flutter_blue_plus_android/android/build.gradle index 04f31190..2c6f5f39 100644 --- a/packages/flutter_blue_plus_android/android/build.gradle +++ b/packages/flutter_blue_plus_android/android/build.gradle @@ -1,5 +1,3 @@ -package packages.flutter_blue_plus_android.android - group 'com.lib.flutter_blue_plus' version '1.0' diff --git a/packages/flutter_blue_plus_android/android/settings.gradle b/packages/flutter_blue_plus_android/android/settings.gradle index 902780c0..943eabda 100644 --- a/packages/flutter_blue_plus_android/android/settings.gradle +++ b/packages/flutter_blue_plus_android/android/settings.gradle @@ -1,3 +1 @@ -package packages.flutter_blue_plus_android.android - rootProject.name = 'flutter_blue_plus' From b067cd97c74cd4e6e99364a2ab10e1c611910a4d Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 17:31:18 +0100 Subject: [PATCH 31/90] fix: method channel on detached from engine stream --- .../lib/src/method_channel_flutter_blue_plus.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index 42c1dc71..3814e1d2 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -110,6 +110,8 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Stream get onDetachedFromEngine { return _calls.stream.where((call) { return call.method == 'OnDetachedFromEngine'; + }).map((_) { + return null; }); } From 23ee3ee98e33b830d972e7f495c4ff7f92c9d023 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Sun, 18 Aug 2024 17:33:37 +0100 Subject: [PATCH 32/90] refactor: align example gradle files with flutter changes --- .../example/android/app/build.gradle | 64 +++++++------------ .../example/android/build.gradle | 15 +---- .../example/android/settings.gradle | 30 ++++++--- 3 files changed, 47 insertions(+), 62 deletions(-) diff --git a/packages/flutter_blue_plus/example/android/app/build.gradle b/packages/flutter_blue_plus/example/android/app/build.gradle index 7484f6d8..cb0f88ff 100644 --- a/packages/flutter_blue_plus/example/android/app/build.gradle +++ b/packages/flutter_blue_plus/example/android/app/build.gradle @@ -1,62 +1,44 @@ -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } -} - -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - -def flutterVersionCode = localProperties.getProperty('flutter.versionCode') -if (flutterVersionCode == null) { - flutterVersionCode = '1' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' +plugins { + id "com.android.application" + id "kotlin-android" + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id "dev.flutter.flutter-gradle-plugin" } -apply plugin: 'com.android.application' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion 33 + namespace = "com.lib.flutter_blue_plus_example" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 } defaultConfig { - applicationId "com.lib.flutter_blue_plus_example" - minSdkVersion 21 - targetSdkVersion 33 - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName + applicationId = "com.lib.flutter_blue_plus_example" + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig = signingConfigs.debug // FIXME: Work-around for https://github.com/pauldemarco/flutter_blue/issues/772 - shrinkResources false - minifyEnabled false + shrinkResources = false + minifyEnabled = false } } - - // Conditional for compatibility with AGP <4.2. - if (project.android.hasProperty("namespace")) { - namespace 'com.lib.flutter_blue_plus_example' - } } flutter { - source '../..' + source = "../.." } diff --git a/packages/flutter_blue_plus/example/android/build.gradle b/packages/flutter_blue_plus/example/android/build.gradle index 22cf3b71..d2ffbffa 100644 --- a/packages/flutter_blue_plus/example/android/build.gradle +++ b/packages/flutter_blue_plus/example/android/build.gradle @@ -1,14 +1,3 @@ -buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:8.0.2' - } -} - allprojects { repositories { google() @@ -16,12 +5,12 @@ allprojects { } } -rootProject.buildDir = '../build' +rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { - project.evaluationDependsOn(':app') + project.evaluationDependsOn(":app") } tasks.register("clean", Delete) { diff --git a/packages/flutter_blue_plus/example/android/settings.gradle b/packages/flutter_blue_plus/example/android/settings.gradle index 44e62bcf..536165d3 100644 --- a/packages/flutter_blue_plus/example/android/settings.gradle +++ b/packages/flutter_blue_plus/example/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "7.3.0" apply false + id "org.jetbrains.kotlin.android" version "1.7.10" apply false +} + +include ":app" From 7dc7355bef9a80daf13c88f2009f9f4fb19cafdc Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Mon, 19 Aug 2024 08:10:23 +0100 Subject: [PATCH 33/90] test: update adapter models --- .../models/bm_bluetooth_adapter_state.dart | 11 +++ .../adapter/models/bm_turn_on_response.dart | 11 +++ .../test/bm_bluetooth_adapter_state_test.dart | 69 ++++++++++++++- .../test/bm_turn_on_response_test.dart | 84 +++++++++++++++++-- 4 files changed, 166 insertions(+), 9 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart index 699b2a2d..949178f3 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart @@ -15,6 +15,17 @@ class BmBluetoothAdapterState { ); } + @override + int get hashCode { + return adapterState.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothAdapterState && hashCode == other.hashCode; + } + Map toMap() { return { 'adapter_state': adapterState.index, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart index 524d25b6..8719a1b6 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart @@ -13,6 +13,17 @@ class BmTurnOnResponse { ); } + @override + int get hashCode { + return userAccepted.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmTurnOnResponse && hashCode == other.hashCode; + } + Map toMap() { return { 'user_accepted': userAccepted, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart index eeca9a52..4bc542ec 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart @@ -11,11 +11,13 @@ void main() { test( 'deserializes the adapter state property', () { + final adapterState = BmAdapterStateEnum.unknown; + expect( BmBluetoothAdapterState.fromMap({ - 'adapter_state': 0, + 'adapter_state': adapterState.index, }).adapterState, - equals(BmAdapterStateEnum.unknown), + equals(adapterState), ); }, ); @@ -36,17 +38,76 @@ void main() { }, ); + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final adapterState = BmAdapterStateEnum.unknown; + + expect( + BmBluetoothAdapterState( + adapterState: adapterState, + ).hashCode, + equals(adapterState.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ) == + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unavailable, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ) == + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ), + isTrue, + ); + }, + ); + }, + ); + group( 'toMap', () { test( 'serializes the adapter state property', () { + final adapterState = BmAdapterStateEnum.unknown; + expect( BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, + adapterState: adapterState, ).toMap(), - containsPair('adapter_state', 0), + containsPair( + 'adapter_state', + equals(adapterState.index), + ), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart index 1a7065bb..61fb826f 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart @@ -9,30 +9,104 @@ void main() { 'fromMap', () { test( - 'deserializes the user accepted property as false if the user accepted property is null', + 'deserializes the user accepted property', () { expect( BmTurnOnResponse.fromMap({ - 'user_accepted': null, + 'user_accepted': true, }).userAccepted, - isFalse, + isTrue, ); }, ); test( - 'deserializes the user accepted property as true if the user accepted property is true', + 'deserializes the user accepted property as false if it is null', () { expect( BmTurnOnResponse.fromMap({ - 'user_accepted': true, + 'user_accepted': null, }).userAccepted, + isFalse, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final userAccepted = true; + + expect( + BmTurnOnResponse( + userAccepted: userAccepted, + ).hashCode, + equals(userAccepted.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmTurnOnResponse( + userAccepted: true, + ) == + BmTurnOnResponse( + userAccepted: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmTurnOnResponse( + userAccepted: true, + ) == + BmTurnOnResponse( + userAccepted: true, + ), isTrue, ); }, ); }, ); + + group( + 'toMap', + () { + test( + 'serializes the user accepted property', + () { + expect( + BmTurnOnResponse( + userAccepted: true, + ).toMap(), + containsPair( + 'user_accepted', + isTrue, + ), + ); + }, + ); + }, + ); }, ); } From 07663694c248cdeac5463414c990036db07a025a Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Mon, 19 Aug 2024 09:05:49 +0100 Subject: [PATCH 34/90] test: update characteristic models --- .../models/bm_bluetooth_characteristic.dart | 18 + .../models/bm_characteristic_data.dart | 19 + .../models/bm_characteristic_properties.dart | 20 + .../bm_read_characteristic_request.dart | 14 + .../models/bm_set_notify_value_request.dart | 16 + .../bm_write_characteristic_request.dart | 18 + .../pubspec.yaml | 1 + .../bm_bluetooth_characteristic_test.dart | 545 +++++++++++++++++- .../test/bm_characteristic_data_test.dart | 392 ++++++++++++- .../bm_characteristic_properties_test.dart | 359 ++++++++---- .../bm_read_characteristic_request_test.dart | 223 ++++++- .../bm_write_characteristic_request_test.dart | 385 ++++++++++++- 12 files changed, 1805 insertions(+), 205 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart index 1fec7092..a59ed0e9 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; + import '../../common/models/device_identifier.dart'; import '../../common/models/guid.dart'; import '../../descriptor/models/bm_bluetooth_descriptor.dart'; @@ -51,6 +53,22 @@ class BmBluetoothCharacteristic { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality().hash(descriptors) ^ + properties.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothCharacteristic && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart index 3e2a97e4..df3698d4 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -43,6 +44,24 @@ class BmCharacteristicData { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmCharacteristicData && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart index 0204ab0f..30745221 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart @@ -40,6 +40,26 @@ class BmCharacteristicProperties { ); } + @override + int get hashCode { + return broadcast.hashCode ^ + read.hashCode ^ + writeWithoutResponse.hashCode ^ + write.hashCode ^ + notify.hashCode ^ + indicate.hashCode ^ + authenticatedSignedWrites.hashCode ^ + extendedProperties.hashCode ^ + notifyEncryptionRequired.hashCode ^ + indicateEncryptionRequired.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmCharacteristicProperties && hashCode == other.hashCode; + } + Map toMap() { return { 'broadcast': broadcast ? 1 : 0, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart index 3638432a..aae99675 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart @@ -27,6 +27,20 @@ class BmReadCharacteristicRequest { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmReadCharacteristicRequest && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart index 6bc2315e..4208f91c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart @@ -33,6 +33,22 @@ class BmSetNotifyValueRequest { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + forceIndications.hashCode ^ + enable.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmSetNotifyValueRequest && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart index e516eb13..95504041 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -39,6 +40,23 @@ class BmWriteCharacteristicRequest { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + writeType.hashCode ^ + allowLongWrite.hashCode ^ + const ListEquality().hash(value); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmWriteCharacteristicRequest && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index b524581a..ad5970e4 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -8,6 +8,7 @@ environment: flutter: ">=2.0.0" dependencies: + collection: ^1.15.0 convert: ^3.0.0 flutter: sdk: flutter diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart index 3092b3b8..79197271 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -8,44 +9,133 @@ void main() { group( 'fromMap', () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptors': [], + 'properties': {}, + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptors property', + () { + final descriptors = [ + { + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }, + ]; + + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptors': descriptors, + 'properties': {}, + }).descriptors, + equals( + descriptors.map( + (descriptor) { + return BmBluetoothDescriptor.fromMap(descriptor); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the descriptors property as [] if it is null', + () { + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptors': null, + 'properties': {}, + }).descriptors, + equals([]), + ); + }, + ); + test( 'deserializes the properties property properties as false if it is null', () { - final properties = BmBluetoothCharacteristic.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'properties': null, - }).properties; + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptors': [], + 'properties': null, + }).properties, + equals( + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; - expect(properties.broadcast, isFalse); - expect(properties.read, isFalse); - expect(properties.writeWithoutResponse, isFalse); - expect(properties.write, isFalse); - expect(properties.notify, isFalse); - expect(properties.indicate, isFalse); - expect(properties.authenticatedSignedWrites, isFalse); - expect(properties.extendedProperties, isFalse); - expect(properties.notifyEncryptionRequired, isFalse); - expect(properties.indicateEncryptionRequired, isFalse); + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': remoteId, + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptors': [], + 'properties': {}, + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); }, ); test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + 'deserializes the secondary service uuid property', () { + final secondaryServiceUuid = '0102'; + expect( BmBluetoothCharacteristic.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, 'characteristic_uuid': '0102', + 'descriptors': [], 'properties': {}, - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), ); }, ); @@ -55,16 +145,421 @@ void main() { () { expect( BmBluetoothCharacteristic.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', + 'descriptors': [], 'properties': {}, }).secondaryServiceUuid, isNull, ); }, ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptors': [], + 'properties': {}, + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final descriptors = []; + final properties = BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ); + + expect( + BmBluetoothCharacteristic( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + descriptors: descriptors, + properties: properties, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality() + .hash(descriptors) ^ + properties.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ) == + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ) == + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the descriptors property', + () { + final descriptors = [ + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + ]; + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: descriptors, + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'descriptors', + equals( + descriptors.map( + (descriptor) { + return descriptor.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the properties property', + () { + final properties = BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ); + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: properties, + ).toMap(), + containsPair( + 'properties', + equals(properties.toMap()), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmBluetoothCharacteristic( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); }, ); }, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart index eadc64fe..57f793d5 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,23 +11,62 @@ void main() { 'fromMap', () { test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + 'deserializes the characteristic uuid property', () { + final characteristicUuid = '0102'; + expect( BmCharacteristicData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmCharacteristicData.fromMap({ + 'remote_id': remoteId, 'service_uuid': '0102', - 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'value': '', 'success': 1, 'error_code': 0, 'error_string': '', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), ); }, ); @@ -35,7 +76,7 @@ void main() { () { expect( BmCharacteristicData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -49,14 +90,33 @@ void main() { }, ); + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'value': '', + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + test( 'deserializes the success property as false if it is 0', () { expect( BmCharacteristicData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': '', 'success': 0, @@ -73,9 +133,8 @@ void main() { () { expect( BmCharacteristicData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': '', 'success': null, @@ -92,9 +151,8 @@ void main() { () { expect( BmCharacteristicData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': '', 'success': 1, @@ -109,22 +167,19 @@ void main() { test( 'deserializes the value property', () { + final value = '010203'; + expect( BmCharacteristicData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', - 'value': '010203', + 'value': value, 'success': 1, 'error_code': 0, 'error_string': '', }).value, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), + equals(hex.decode(value)), ); }, ); @@ -134,16 +189,301 @@ void main() { () { expect( BmCharacteristicData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': null, 'success': 1, 'error_code': 0, 'error_string': '', }).value, - isEmpty, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final value = []; + final success = true; + final errorCode = 0; + final errorString = ''; + + expect( + BmCharacteristicData( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + value: value, + success: success, + errorCode: errorCode, + errorString: errorString, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: false, + errorCode: 0, + errorString: '', + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmCharacteristicData( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: false, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the value property', + () { + final value = [0x01, 0x02, 0x03]; + + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: value, + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'value', + hex.encode(value), + ), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart index 4ede2c27..75301ba1 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart @@ -11,58 +11,33 @@ void main() { test( 'deserializes the properties as false if they are not 1', () { - final properties = BmCharacteristicProperties.fromMap({ - 'broadcast': 0, - 'read': 0, - 'write_without_response': 0, - 'write': 0, - 'notify': 0, - 'indicate': 0, - 'authenticated_signed_writes': 0, - 'extended_properties': 0, - 'notify_encryption_required': 0, - 'indicate_encryption_required': 0, - }); - - expect( - properties.broadcast, - isFalse, - ); - expect( - properties.read, - isFalse, - ); - expect( - properties.writeWithoutResponse, - isFalse, - ); - expect( - properties.write, - isFalse, - ); - expect( - properties.notify, - isFalse, - ); - expect( - properties.indicate, - isFalse, - ); expect( - properties.authenticatedSignedWrites, - isFalse, - ); - expect( - properties.extendedProperties, - isFalse, - ); - expect( - properties.notifyEncryptionRequired, - isFalse, - ); - expect( - properties.indicateEncryptionRequired, - isFalse, + BmCharacteristicProperties.fromMap({ + 'broadcast': 0, + 'read': 0, + 'write_without_response': 0, + 'write': 0, + 'notify': 0, + 'indicate': 0, + 'authenticated_signed_writes': 0, + 'extended_properties': 0, + 'notify_encryption_required': 0, + 'indicate_encryption_required': 0, + }), + equals( + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), ); }, ); @@ -70,57 +45,151 @@ void main() { test( 'deserializes the properties as true if they are 1', () { - final properties = BmCharacteristicProperties.fromMap({ - 'broadcast': 1, - 'read': 1, - 'write_without_response': 1, - 'write': 1, - 'notify': 1, - 'indicate': 1, - 'authenticated_signed_writes': 1, - 'extended_properties': 1, - 'notify_encryption_required': 1, - 'indicate_encryption_required': 1, - }); - - expect( - properties.broadcast, - isTrue, - ); - expect( - properties.read, - isTrue, - ); - expect( - properties.writeWithoutResponse, - isTrue, - ); - expect( - properties.write, - isTrue, - ); - expect( - properties.notify, - isTrue, - ); expect( - properties.indicate, - isTrue, - ); - expect( - properties.authenticatedSignedWrites, - isTrue, + BmCharacteristicProperties.fromMap({ + 'broadcast': 1, + 'read': 1, + 'write_without_response': 1, + 'write': 1, + 'notify': 1, + 'indicate': 1, + 'authenticated_signed_writes': 1, + 'extended_properties': 1, + 'notify_encryption_required': 1, + 'indicate_encryption_required': 1, + }), + equals( + BmCharacteristicProperties( + broadcast: true, + read: true, + writeWithoutResponse: true, + write: true, + notify: true, + indicate: true, + authenticatedSignedWrites: true, + extendedProperties: true, + notifyEncryptionRequired: true, + indicateEncryptionRequired: true, + ), + ), ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final broadcast = false; + final read = false; + final writeWithoutResponse = false; + final write = false; + final notify = false; + final indicate = false; + final authenticatedSignedWrites = false; + final extendedProperties = false; + final notifyEncryptionRequired = false; + final indicateEncryptionRequired = false; + expect( - properties.extendedProperties, - isTrue, + BmCharacteristicProperties( + broadcast: broadcast, + read: read, + writeWithoutResponse: writeWithoutResponse, + write: write, + notify: notify, + indicate: indicate, + authenticatedSignedWrites: authenticatedSignedWrites, + extendedProperties: extendedProperties, + notifyEncryptionRequired: notifyEncryptionRequired, + indicateEncryptionRequired: indicateEncryptionRequired, + ).hashCode, + equals( + broadcast.hashCode ^ + read.hashCode ^ + writeWithoutResponse.hashCode ^ + write.hashCode ^ + notify.hashCode ^ + indicate.hashCode ^ + authenticatedSignedWrites.hashCode ^ + extendedProperties.hashCode ^ + notifyEncryptionRequired.hashCode ^ + indicateEncryptionRequired.hashCode, + ), ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { expect( - properties.notifyEncryptionRequired, - isTrue, + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ) == + BmCharacteristicProperties( + broadcast: true, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + isFalse, ); + }, + ); + + test( + 'returns true if they are equal', + () { expect( - properties.indicateEncryptionRequired, + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ) == + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), isTrue, ); }, @@ -149,43 +218,73 @@ void main() { expect( map, - containsPair('broadcast', equals(0)), + containsPair( + 'broadcast', + equals(0), + ), ); expect( map, - containsPair('read', equals(0)), + containsPair( + 'read', + equals(0), + ), ); expect( map, - containsPair('write_without_response', equals(0)), + containsPair( + 'write_without_response', + equals(0), + ), ); expect( map, - containsPair('write', equals(0)), + containsPair( + 'write', + equals(0), + ), ); expect( map, - containsPair('notify', equals(0)), + containsPair( + 'notify', + equals(0), + ), ); expect( map, - containsPair('indicate', equals(0)), + containsPair( + 'indicate', + equals(0), + ), ); expect( map, - containsPair('authenticated_signed_writes', equals(0)), + containsPair( + 'authenticated_signed_writes', + equals(0), + ), ); expect( map, - containsPair('extended_properties', equals(0)), + containsPair( + 'extended_properties', + equals(0), + ), ); expect( map, - containsPair('notify_encryption_required', equals(0)), + containsPair( + 'notify_encryption_required', + equals(0), + ), ); expect( map, - containsPair('indicate_encryption_required', equals(0)), + containsPair( + 'indicate_encryption_required', + equals(0), + ), ); }, ); @@ -208,43 +307,73 @@ void main() { expect( map, - containsPair('broadcast', equals(1)), + containsPair( + 'broadcast', + equals(1), + ), ); expect( map, - containsPair('read', equals(1)), + containsPair( + 'read', + equals(1), + ), ); expect( map, - containsPair('write_without_response', equals(1)), + containsPair( + 'write_without_response', + equals(1), + ), ); expect( map, - containsPair('write', equals(1)), + containsPair( + 'write', + equals(1), + ), ); expect( map, - containsPair('notify', equals(1)), + containsPair( + 'notify', + equals(1), + ), ); expect( map, - containsPair('indicate', equals(1)), + containsPair( + 'indicate', + equals(1), + ), ); expect( map, - containsPair('authenticated_signed_writes', equals(1)), + containsPair( + 'authenticated_signed_writes', + equals(1), + ), ); expect( map, - containsPair('extended_properties', equals(1)), + containsPair( + 'extended_properties', + equals(1), + ), ); expect( map, - containsPair('notify_encryption_required', equals(1)), + containsPair( + 'notify_encryption_required', + equals(1), + ), ); expect( map, - containsPair('indicate_encryption_required', equals(1)), + containsPair( + 'indicate_encryption_required', + equals(1), + ), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart index f3f06fb6..415d4a59 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart @@ -9,19 +9,34 @@ void main() { 'fromMap', () { test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + 'deserializes the characteristic uuid property', () { + final characteristicUuid = '0102'; + + expect( + BmReadCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + expect( BmReadCharacteristicRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, 'characteristic_uuid': '0102', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), ); }, ); @@ -31,7 +46,7 @@ void main() { () { expect( BmReadCharacteristicRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -40,6 +55,196 @@ void main() { ); }, ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmReadCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + + expect( + BmReadCharacteristicRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ) == + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ) == + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmReadCharacteristicRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); }, ); }, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart index 417274e2..c81239b2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,21 +11,40 @@ void main() { 'fromMap', () { test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + 'deserializes the characteristic uuid property', () { + final characteristicUuid = '0102'; + + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'write_type': 0, + 'allow_long_write': 0, + 'value': '', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, 'characteristic_uuid': '0102', 'write_type': 0, + 'allow_long_write': 0, 'value': '', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), ); }, ); @@ -33,11 +54,12 @@ void main() { () { expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'write_type': 0, + 'allow_long_write': 0, 'value': '', }).secondaryServiceUuid, isNull, @@ -45,23 +67,74 @@ void main() { }, ); + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 0, + 'value': '', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + + test( + 'deserializes the allow long write property as false if it is 0', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 0, + 'value': '', + }).allowLongWrite, + isFalse, + ); + }, + ); + + test( + 'deserializes the allow long write property as true if it is not 0', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 1, + 'value': '', + }).allowLongWrite, + isTrue, + ); + }, + ); + test( 'deserializes the value property', () { + final value = '010203'; + expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'write_type': 0, - 'value': '010203', + 'allow_long_write': 0, + 'value': value, }).value, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), + equals(hex.decode(value)), ); }, ); @@ -71,11 +144,11 @@ void main() { () { expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'write_type': 0, + 'allow_long_write': 0, 'value': null, }).value, isEmpty, @@ -86,16 +159,18 @@ void main() { test( 'deserializes the write type property', () { + final writeType = BmWriteType.withResponse; + expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', - 'write_type': 0, - 'value': null, + 'write_type': writeType.index, + 'allow_long_write': 0, + 'value': '', }).writeType, - equals(BmWriteType.withResponse), + equals(writeType), ); }, ); @@ -106,12 +181,12 @@ void main() { expect( () { BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'write_type': 2, - 'value': null, + 'allow_long_write': 0, + 'value': '', }); }, throwsRangeError, @@ -121,22 +196,272 @@ void main() { }, ); + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final writeType = BmWriteType.withResponse; + final allowLongWrite = false; + final value = []; + + expect( + BmWriteCharacteristicRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + writeType: writeType, + allowLongWrite: allowLongWrite, + value: value, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + writeType.hashCode ^ + allowLongWrite.hashCode ^ + const ListEquality().hash(value), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ) == + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ) == + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ), + isTrue, + ); + }, + ); + }, + ); + group( 'toMap', () { test( - 'serializes the write type property', + 'serializes the characteristic uuid property', () { + final characteristicUuid = Guid('0102'); + expect( BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmWriteCharacteristicRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, characteristicUuid: Guid('0102'), writeType: BmWriteType.withResponse, allowLongWrite: false, value: [], ).toMap(), - containsPair('write_type', 0), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'allow_long_write', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: true, + value: [], + ).toMap(), + containsPair( + 'allow_long_write', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the write type property', + () { + final writeType = BmWriteType.withResponse; + + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: writeType, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'write_type', + equals(writeType.index), + ), ); }, ); From f2fd3c3030d4990687cbf2012fea71edfbbdc090 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Mon, 19 Aug 2024 20:09:55 +0100 Subject: [PATCH 35/90] test: update service models --- .../service/models/bm_bluetooth_service.dart | 19 +- .../models/bm_discover_services_result.dart | 17 + .../test/bm_bluetooth_service_test.dart | 394 +++++++++++++++++- .../bm_discover_services_result_test.dart | 244 ++++++++++- 4 files changed, 664 insertions(+), 10 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart index 29aa7214..97551b18 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; + import '../../characteristic/models/bm_bluetooth_characteristic.dart'; import '../../common/models/device_identifier.dart'; import '../../common/models/guid.dart'; @@ -10,8 +12,8 @@ class BmBluetoothService { List includedServices; BmBluetoothService({ - required this.serviceUuid, required this.remoteId, + required this.serviceUuid, required this.isPrimary, required this.characteristics, required this.includedServices, @@ -37,6 +39,21 @@ class BmBluetoothService { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + isPrimary.hashCode ^ + const ListEquality().hash(characteristics) ^ + const ListEquality().hash(includedServices); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothService && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart index 5979e00c..689c1eed 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; + import '../../common/models/device_identifier.dart'; import 'bm_bluetooth_service.dart'; @@ -34,6 +36,21 @@ class BmDiscoverServicesResult { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + const ListEquality().hash(services) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmDiscoverServicesResult && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart index 6f1da7da..7a3f4bef 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -8,18 +9,83 @@ void main() { group( 'fromMap', () { + test( + 'deserializes the characteristics property', + () { + final characteristics = [ + { + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'descriptors': [], + 'properties': {}, + }, + ]; + + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': characteristics, + 'included_services': [], + }).characteristics, + equals( + characteristics.map( + (characteristic) { + return BmBluetoothCharacteristic.fromMap(characteristic); + }, + ), + ), + ); + }, + ); + test( 'deserializes the characteristics property as [] if it is null', () { expect( BmBluetoothService.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'is_primary': 1, 'characteristics': null, 'included_services': [], }).characteristics, - isEmpty, + equals([]), + ); + }, + ); + + test( + 'deserializes the included services property', + () { + final includedServices = [ + { + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': [], + }, + ]; + + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': includedServices, + }).includedServices, + equals( + includedServices.map( + (includedService) { + return BmBluetoothService.fromMap(includedService); + }, + ), + ), ); }, ); @@ -29,13 +95,333 @@ void main() { () { expect( BmBluetoothService.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'is_primary': 1, 'characteristics': [], 'included_services': null, }).includedServices, - isEmpty, + equals([]), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmBluetoothService.fromMap({ + 'remote_id': remoteId, + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': null, + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'is_primary': 1, + 'characteristics': [], + 'included_services': null, + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + + test( + 'deserializes the is primary property as false if it is not 1', + () { + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 0, + 'characteristics': [], + 'included_services': null, + }).isPrimary, + isFalse, + ); + }, + ); + + test( + 'deserializes the is primary property as true if it is 1', + () { + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': null, + }).isPrimary, + isTrue, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final isPrimary = true; + final characteristics = []; + final includedServices = []; + + expect( + BmBluetoothService( + remoteId: remoteId, + serviceUuid: serviceUuid, + isPrimary: isPrimary, + characteristics: characteristics, + includedServices: includedServices, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + isPrimary.hashCode ^ + const ListEquality() + .hash(characteristics) ^ + const ListEquality() + .hash(includedServices), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ) == + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: false, + characteristics: [], + includedServices: [], + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ) == + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristics property', + () { + final characteristics = [ + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + ]; + + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: characteristics, + includedServices: [], + ).toMap(), + containsPair( + 'characteristics', + equals( + characteristics.map( + (characteristic) { + return characteristic.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the included services property', + () { + final includedServices = [ + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ), + ]; + + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: includedServices, + ).toMap(), + containsPair( + 'included_services', + equals( + includedServices.map( + (includedService) { + return includedService.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the is primary property as 0 if it is false', + () { + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: false, + characteristics: [], + includedServices: [], + ).toMap(), + containsPair( + 'is_primary', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the is primary property as 1 if it is true', + () { + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ).toMap(), + containsPair( + 'is_primary', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmBluetoothService( + remoteId: remoteId, + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + isPrimary: true, + characteristics: [], + includedServices: [], + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart index 7cf5894f..42d7d8f3 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -8,18 +9,68 @@ void main() { group( 'fromMap', () { + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': remoteId, + 'services': [], + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the services property', + () { + final services = [ + { + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': [], + } + ]; + + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': 'str', + 'services': services, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).services, + equals( + services.map( + (service) { + return BmBluetoothService.fromMap(service); + }, + ), + ), + ); + }, + ); + test( 'deserializes the services property as [] if it is null', () { expect( BmDiscoverServicesResult.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'services': null, 'success': 1, 'error_code': 0, 'error_string': '', }).services, - isEmpty, + equals([]), ); }, ); @@ -29,7 +80,7 @@ void main() { () { expect( BmDiscoverServicesResult.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'services': [], 'success': 0, 'error_code': 0, @@ -45,7 +96,7 @@ void main() { () { expect( BmDiscoverServicesResult.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'services': [], 'success': null, 'error_code': 0, @@ -61,7 +112,7 @@ void main() { () { expect( BmDiscoverServicesResult.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'services': [], 'success': 1, 'error_code': 0, @@ -73,6 +124,189 @@ void main() { ); }, ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final services = []; + final success = true; + final errorCode = 0; + final errorString = ''; + + expect( + BmDiscoverServicesResult( + remoteId: remoteId, + services: services, + success: success, + errorCode: errorCode, + errorString: errorString, + ).hashCode, + equals( + remoteId.hashCode ^ + const ListEquality().hash(services) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: false, + errorCode: 0, + errorString: '', + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmDiscoverServicesResult( + remoteId: remoteId, + services: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the services property', + () { + final services = [ + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ), + ]; + + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: services, + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'services', + equals( + services.map( + (service) { + return service.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: false, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(1), + ), + ); + }, + ); + }, + ); }, ); } From c22887cf2777f9c555d8a4a22d6a6561849b573c Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Mon, 19 Aug 2024 20:10:27 +0100 Subject: [PATCH 36/90] test: update scan models --- .../lib/src/scan/models/bm_msd_filter.dart | 14 + .../scan/models/bm_scan_advertisement.dart | 21 + .../lib/src/scan/models/bm_scan_response.dart | 16 + .../lib/src/scan/models/bm_scan_settings.dart | 23 + .../scan/models/bm_service_data_filter.dart | 14 + .../test/bm_msd_filter_test.dart | 163 +++++- .../test/bm_scan_advertisement_test.dart | 436 ++++++++++++++-- .../test/bm_scan_response_test.dart | 188 ++++++- .../test/bm_scan_settings_test.dart | 470 +++++++++++++++++- .../test/bm_service_data_filter_test.dart | 168 ++++++- 10 files changed, 1423 insertions(+), 90 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart index ecd77a4f..32135816 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; class BmMsdFilter { @@ -21,6 +22,19 @@ class BmMsdFilter { ); } + @override + int get hashCode { + return manufacturerId.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmMsdFilter && hashCode == other.hashCode; + } + Map toMap() { return { 'manufacturer_id': manufacturerId, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart index 5d0e3d89..f4469fc6 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -52,6 +53,26 @@ class BmScanAdvertisement { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + platformName.hashCode ^ + advName.hashCode ^ + connectable.hashCode ^ + txPowerLevel.hashCode ^ + appearance.hashCode ^ + const MapEquality>().hash(manufacturerData) ^ + const MapEquality>().hash(serviceData) ^ + const ListEquality().hash(serviceUuids) ^ + rssi.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanAdvertisement && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart index c6053b1a..b0d86543 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; + import 'bm_scan_advertisement.dart'; class BmScanResponse { @@ -30,6 +32,20 @@ class BmScanResponse { ); } + @override + int get hashCode { + return const ListEquality().hash(advertisements) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanResponse && hashCode == other.hashCode; + } + Map toMap() { return { 'advertisements': diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart index 0f18f305..ab1eb303 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; + import '../../common/models/guid.dart'; import 'bm_msd_filter.dart'; import 'bm_service_data_filter.dart'; @@ -58,6 +60,27 @@ class BmScanSettings { ); } + @override + int get hashCode { + return const ListEquality().hash(withServices) ^ + const ListEquality().hash(withRemoteIds) ^ + const ListEquality().hash(withNames) ^ + const ListEquality().hash(withKeywords) ^ + const ListEquality().hash(withMsd) ^ + const ListEquality().hash(withServiceData) ^ + continuousUpdates.hashCode ^ + continuousDivisor.hashCode ^ + androidLegacy.hashCode ^ + androidScanMode.hashCode ^ + androidUsesFineLocation.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanSettings && hashCode == other.hashCode; + } + Map toMap() { return { 'with_services': withServices.map((uuid) => uuid.str).toList(), diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart index 4f3a9d60..09e1af6e 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/guid.dart'; @@ -23,6 +24,19 @@ class BmServiceDataFilter { ); } + @override + int get hashCode { + return service.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmServiceDataFilter && hashCode == other.hashCode; + } + Map toMap() { return { 'service': service.str, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart index de385abc..6dad4753 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -8,6 +10,24 @@ void main() { group( 'fromMap', () { + test( + 'deserializes the data property', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': '010203', + 'mask': null, + }).data, + equals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + test( 'deserializes the data property as null if it is null', () { @@ -23,15 +43,15 @@ void main() { ); test( - 'deserializes the data property', + 'deserializes the mask property', () { expect( BmMsdFilter.fromMap({ 'manufacturer_id': 0, - 'data': '010203', - 'mask': null, - }).data, - orderedEquals([ + 'data': null, + 'mask': '010203', + }).mask, + equals([ 0x01, 0x02, 0x03, @@ -53,21 +73,132 @@ void main() { ); }, ); + }, + ); + group( + 'hashCode', + () { test( - 'deserializes the mask property', + 'returns the hash code', () { + final manufacturerId = 0; + final data = []; + final mask = []; + expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': null, - 'mask': '010203', - }).mask, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), + BmMsdFilter( + manufacturerId, + data, + mask, + ).hashCode, + equals( + manufacturerId.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmMsdFilter(0, [], []) == BmMsdFilter(1, [], []), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmMsdFilter(0, [], []) == BmMsdFilter(0, [], []), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the data property', + () { + final data = [0x01, 0x02, 0x03]; + + expect( + BmMsdFilter( + 0, + data, + [], + ).toMap(), + containsPair( + 'data', + hex.encode(data), + ), + ); + }, + ); + + test( + 'serializes the data property as null if it is null', + () { + expect( + BmMsdFilter( + 0, + null, + [], + ).toMap(), + containsPair( + 'data', + isNull, + ), + ); + }, + ); + + test( + 'serializes the mask property', + () { + final mask = [0x01, 0x02, 0x03]; + + expect( + BmMsdFilter( + 0, + [], + mask, + ).toMap(), + containsPair( + 'mask', + hex.encode(mask), + ), + ); + }, + ); + + test( + 'serializes the mask property as null if it is null', + () { + expect( + BmMsdFilter( + 0, + [], + null, + ).toMap(), + containsPair( + 'mask', + isNull, + ), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart index 2a55567b..4606f5bd 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -8,26 +10,62 @@ void main() { group( 'fromMap', () { + test( + 'deserializes the connectable property as false if it is not 1', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 0, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': 0, + }).connectable, + isFalse, + ); + }, + ); + + test( + 'deserializes the connectable property as true if it is 1', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': 0, + }).connectable, + isTrue, + ); + }, + ); + test( 'deserializes the manufacturer data property', () { + final manufacturerData = { + 1: '010203', + }; + expect( BmScanAdvertisement.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connectable': 1, - 'manufacturer_data': { - 1: '010203', - }, + 'manufacturer_data': manufacturerData, 'service_data': {}, 'service_uuids': [], + 'rssi': 0, }).manufacturerData, - containsPair( - 1, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), + equals( + manufacturerData.map( + (key, value) { + return MapEntry(key, hex.decode(value)); + }, + ), ), ); }, @@ -38,13 +76,69 @@ void main() { () { expect( BmScanAdvertisement.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connectable': 1, 'manufacturer_data': null, 'service_data': {}, 'service_uuids': [], + 'rssi': 0, }).manufacturerData, - isEmpty, + equals({}), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': remoteId, + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': 0, + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the rssi property', + () { + final rssi = 0; + + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': rssi, + }).rssi, + equals(rssi), + ); + }, + ); + + test( + 'deserializes the rssi property as 0 if it is null', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': null, + }).rssi, + equals(0), ); }, ); @@ -52,23 +146,25 @@ void main() { test( 'deserializes the service data property', () { + final serviceData = { + '0102': '010203', + }; + expect( BmScanAdvertisement.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connectable': 1, 'manufacturer_data': {}, - 'service_data': { - '0102': '010203', - }, + 'service_data': serviceData, 'service_uuids': [], + 'rssi': 0, }).serviceData, - containsPair( - Guid('0102'), - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), + equals( + serviceData.map( + (key, value) { + return MapEntry(Guid(key), hex.decode(value)); + }, + ), ), ); }, @@ -79,13 +175,14 @@ void main() { () { expect( BmScanAdvertisement.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connectable': 1, 'manufacturer_data': {}, 'service_data': null, 'service_uuids': [], + 'rssi': 0, }).serviceData, - isEmpty, + equals({}), ); }, ); @@ -93,19 +190,26 @@ void main() { test( 'deserializes the service uuids property', () { + final serviceUuids = [ + '0102', + ]; + expect( BmScanAdvertisement.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connectable': 1, 'manufacturer_data': {}, 'service_data': {}, - 'service_uuids': [ - '0102', - ], + 'service_uuids': serviceUuids, + 'rssi': 0, }).serviceUuids, - orderedEquals([ - Guid('0102'), - ]), + equals( + serviceUuids.map( + (serviceUuid) { + return Guid(serviceUuid); + }, + ), + ), ); }, ); @@ -115,13 +219,275 @@ void main() { () { expect( BmScanAdvertisement.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connectable': 1, 'manufacturer_data': {}, 'service_data': {}, 'service_uuids': null, + 'rssi': 0, }).serviceUuids, - isEmpty, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final platformName = null; + final advName = null; + final connectable = true; + final txPowerLevel = 0; + final appearance = 0; + final manufacturerData = >{}; + final serviceData = >{}; + final serviceUuids = []; + final rssi = 0; + + expect( + BmScanAdvertisement( + remoteId: remoteId, + platformName: platformName, + advName: advName, + connectable: connectable, + txPowerLevel: txPowerLevel, + appearance: appearance, + manufacturerData: manufacturerData, + serviceData: serviceData, + serviceUuids: serviceUuids, + rssi: rssi, + ).hashCode, + equals( + remoteId.hashCode ^ + platformName.hashCode ^ + advName.hashCode ^ + connectable.hashCode ^ + txPowerLevel.hashCode ^ + appearance.hashCode ^ + const MapEquality>() + .hash(manufacturerData) ^ + const MapEquality>().hash(serviceData) ^ + const ListEquality().hash(serviceUuids) ^ + rssi.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ) == + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: false, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ) == + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the connectable property as 0 if it is false', + () { + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: false, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'connectable', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the connectable property as 1 if it is true', + () { + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'connectable', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the manufacturer data property', + () { + final manufacturerData = { + 0: [0x01, 0x02, 0x03], + }; + + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: manufacturerData, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'manufacturer_data', + equals( + manufacturerData.map( + (key, value) { + return MapEntry(key, hex.encode(value)); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmScanAdvertisement( + remoteId: remoteId, + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the service data property', + () { + final serviceData = { + Guid('0102'): [0x01, 0x02, 0x03], + }; + + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: serviceData, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'service_data', + equals( + serviceData.map( + (key, value) { + return MapEntry(key.str, hex.encode(value)); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the service uuids property', + () { + final serviceUuids = [ + Guid('0102'), + ]; + + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: serviceUuids, + rssi: 0, + ).toMap(), + containsPair( + 'service_uuids', + equals( + serviceUuids.map( + (serviceUuid) { + return serviceUuid.str; + }, + ), + ), + ), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart index 8636986b..c3890127 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -8,6 +9,37 @@ void main() { group( 'fromMap', () { + test( + 'deserializes the advertisements property', + () { + final advertisements = [ + { + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + } + ]; + + expect( + BmScanResponse.fromMap({ + 'advertisements': advertisements, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).advertisements, + equals( + advertisements.map( + (advertisement) { + return BmScanAdvertisement.fromMap(advertisement); + }, + ), + ), + ); + }, + ); + test( 'deserializes the advertisements property as [] if it is null', () { @@ -18,7 +50,7 @@ void main() { 'error_code': 0, 'error_string': '', }).advertisements, - isEmpty, + equals([]), ); }, ); @@ -69,6 +101,160 @@ void main() { ); }, ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final advertisements = []; + final success = true; + final errorCode = 0; + final errorString = ''; + + expect( + BmScanResponse( + advertisements: advertisements, + success: success, + errorCode: errorCode, + errorString: errorString, + ).hashCode, + equals( + const ListEquality() + .hash(advertisements) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmScanResponse( + advertisements: [], + success: false, + errorCode: 0, + errorString: '', + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the services property', + () { + final advertisements = [ + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ), + ]; + + expect( + BmScanResponse( + advertisements: advertisements, + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'advertisements', + equals( + advertisements.map( + (advertisement) { + return advertisement.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmScanResponse( + advertisements: [], + success: false, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(1), + ), + ); + }, + ); + }, + ); }, ); } diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart index fbbd6085..3132a207 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,14 +10,18 @@ void main() { 'fromMap', () { test( - 'deserializes the with services property as [] if it is null', + 'deserializes the with keywords property', () { + final withKeywords = [ + 'keyword', + ]; + expect( BmScanSettings.fromMap({ - 'with_services': null, + 'with_services': [], 'with_remote_ids': [], 'with_names': [], - 'with_keywords': [], + 'with_keywords': withKeywords, 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, @@ -24,21 +29,105 @@ void main() { 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, - }).withServices, - isEmpty, + }).withKeywords, + equals(withKeywords), ); }, ); test( - 'deserializes the with remote ids property as [] if it is null', + 'deserializes the with keywords property as [] if it is null', () { expect( BmScanSettings.fromMap({ 'with_services': [], - 'with_remote_ids': null, + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': null, + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withKeywords, + equals([]), + ); + }, + ); + + test( + 'deserializes the with msd property', + () { + final withMsd = [ + { + 'manufacturer_id': 0, + 'data': '', + 'mask': '', + }, + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': withMsd, + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withMsd, + equals( + withMsd.map( + (manufacturerData) { + return BmMsdFilter.fromMap(manufacturerData); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the with msd property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], 'with_names': [], 'with_keywords': [], + 'with_msd': null, + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withMsd, + equals([]), + ); + }, + ); + + test( + 'deserializes the with names property', + () { + final withNames = [ + 'name', + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': withNames, + 'with_keywords': [], 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, @@ -46,8 +135,8 @@ void main() { 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, - }).withRemoteIds, - isEmpty, + }).withNames, + equals(withNames), ); }, ); @@ -69,20 +158,24 @@ void main() { 'android_scan_mode': 0, 'android_uses_fine_location': false, }).withNames, - isEmpty, + equals([]), ); }, ); test( - 'deserializes the with keywords property as [] if it is null', + 'deserializes the with remote ids property', () { + final withRemoteIds = [ + 'str', + ]; + expect( BmScanSettings.fromMap({ 'with_services': [], - 'with_remote_ids': [], + 'with_remote_ids': withRemoteIds, 'with_names': [], - 'with_keywords': null, + 'with_keywords': [], 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, @@ -90,30 +183,66 @@ void main() { 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, - }).withKeywords, - isEmpty, + }).withRemoteIds, + equals(withRemoteIds), ); }, ); test( - 'deserializes the with msd property as [] if it is null', + 'deserializes the with remote ids property as [] if it is null', () { expect( BmScanSettings.fromMap({ 'with_services': [], - 'with_remote_ids': [], + 'with_remote_ids': null, 'with_names': [], 'with_keywords': [], - 'with_msd': null, + 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, - }).withMsd, - isEmpty, + }).withRemoteIds, + equals([]), + ); + }, + ); + + test( + 'deserializes the with service data property', + () { + final withServiceData = [ + { + 'service': '0102', + 'data': '010203', + 'mask': '010203', + }, + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': withServiceData, + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServiceData, + equals( + withServiceData.map( + (serviceData) { + return BmServiceDataFilter.fromMap(serviceData); + }, + ), + ), ); }, ); @@ -135,7 +264,306 @@ void main() { 'android_scan_mode': 0, 'android_uses_fine_location': false, }).withServiceData, - isEmpty, + equals([]), + ); + }, + ); + + test( + 'deserializes the with services property', + () { + final withServices = [ + '0102', + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': withServices, + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServices, + equals( + withServices.map( + (service) { + return Guid(service); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the with services property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': null, + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServices, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final withServices = []; + final withRemoteIds = []; + final withNames = []; + final withKeywords = []; + final withMsd = []; + final withServiceData = []; + final continuousUpdates = false; + final continuousDivisor = 1; + final androidLegacy = false; + final androidScanMode = 0; + final androidUsesFineLocation = false; + + expect( + BmScanSettings( + withServices: withServices, + withRemoteIds: withRemoteIds, + withNames: withNames, + withKeywords: withKeywords, + withMsd: withMsd, + withServiceData: withServiceData, + continuousUpdates: continuousUpdates, + continuousDivisor: continuousDivisor, + androidLegacy: androidLegacy, + androidScanMode: androidScanMode, + androidUsesFineLocation: androidUsesFineLocation, + ).hashCode, + equals( + const ListEquality().hash(withServices) ^ + const ListEquality().hash(withRemoteIds) ^ + const ListEquality().hash(withNames) ^ + const ListEquality().hash(withKeywords) ^ + const ListEquality().hash(withMsd) ^ + const ListEquality() + .hash(withServiceData) ^ + continuousUpdates.hashCode ^ + continuousDivisor.hashCode ^ + androidLegacy.hashCode ^ + androidScanMode.hashCode ^ + androidUsesFineLocation.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ) == + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: true, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ) == + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the with msd property', + () { + final withMsd = [ + BmMsdFilter( + 0, + [], + [], + ), + ]; + + expect( + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: withMsd, + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ).toMap(), + containsPair( + 'with_msd', + equals( + withMsd.map( + (manufacturerData) { + return manufacturerData.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the with service data property', + () { + final withServiceData = [ + BmServiceDataFilter( + Guid('0102'), + [], + [], + ), + ]; + + expect( + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: withServiceData, + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ).toMap(), + containsPair( + 'with_service_data', + equals( + withServiceData.map( + (serviceData) { + return serviceData.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the with services property', + () { + final withServices = [ + Guid('0102'), + ]; + + expect( + BmScanSettings( + withServices: withServices, + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ).toMap(), + containsPair( + 'with_services', + equals( + withServices.map( + (service) { + return service.str; + }, + ), + ), + ), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart index 1eac1ef9..fedcb704 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -8,6 +10,24 @@ void main() { group( 'fromMap', () { + test( + 'deserializes the data property', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': '010203', + 'mask': '010203', + }).data, + equals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + test( 'deserializes the data property as [] if it is null', () { @@ -15,23 +35,23 @@ void main() { BmServiceDataFilter.fromMap({ 'service': '0102', 'data': null, - 'mask': null, + 'mask': '010203', }).data, - isEmpty, + equals([]), ); }, ); test( - 'deserializes the data property', + 'deserializes the mask property', () { expect( BmServiceDataFilter.fromMap({ 'service': '0102', 'data': '010203', - 'mask': null, - }).data, - orderedEquals([ + 'mask': '010203', + }).mask, + equals([ 0x01, 0x02, 0x03, @@ -46,28 +66,142 @@ void main() { expect( BmServiceDataFilter.fromMap({ 'service': '0102', - 'data': null, + 'data': '010203', 'mask': null, }).mask, - isEmpty, + equals([]), ); }, ); test( - 'deserializes the mask property', + 'deserializes the service property', () { + final service = '0102'; + expect( BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': null, + 'service': service, + 'data': '010203', 'mask': '010203', - }).mask, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), + }).service, + equals(Guid(service)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final service = Guid('0102'); + final data = []; + final mask = []; + + expect( + BmServiceDataFilter( + service, + data, + mask, + ).hashCode, + equals( + service.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmServiceDataFilter(Guid('0102'), [], []) == + BmServiceDataFilter(Guid('0304'), [], []), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmServiceDataFilter(Guid('0102'), [], []) == + BmServiceDataFilter(Guid('0102'), [], []), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the data property', + () { + final data = [0x01, 0x02, 0x03]; + + expect( + BmServiceDataFilter( + Guid('0102'), + data, + [], + ).toMap(), + containsPair( + 'data', + hex.encode(data), + ), + ); + }, + ); + + test( + 'serializes the mask property', + () { + final mask = [0x01, 0x02, 0x03]; + + expect( + BmServiceDataFilter( + Guid('0102'), + [], + mask, + ).toMap(), + containsPair( + 'mask', + hex.encode(mask), + ), + ); + }, + ); + + test( + 'serializes the characteristic uuid property', + () { + final service = Guid('0102'); + + expect( + BmServiceDataFilter( + service, + [], + [], + ).toMap(), + containsPair( + 'service', + equals(service.str), + ), ); }, ); From 8b3b3690523d61a3a49c7a78d531830742bcb2c3 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Mon, 19 Aug 2024 20:10:56 +0100 Subject: [PATCH 37/90] test: update descriptor models --- .../models/bm_bluetooth_descriptor.dart | 14 + .../descriptor/models/bm_descriptor_data.dart | 20 + .../models/bm_read_descriptor_request.dart | 15 + .../models/bm_write_descriptor_request.dart | 17 + .../test/bm_bluetooth_descriptor_test.dart | 244 ++++++++++ .../test/bm_descriptor_data_test.dart | 457 ++++++++++++++++-- .../test/bm_read_descriptor_request_test.dart | 274 ++++++++++- .../bm_write_descriptor_request_test.dart | 331 ++++++++++++- 8 files changed, 1316 insertions(+), 56 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart index 344124b5..3c0ae230 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart @@ -25,6 +25,20 @@ class BmBluetoothDescriptor { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothDescriptor && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart index 7eb0a236..a3d1045c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -46,6 +47,25 @@ class BmDescriptorData { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmDescriptorData && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart index b6ec526e..5cb4de6f 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart @@ -30,6 +30,21 @@ class BmReadDescriptorRequest { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmReadDescriptorRequest && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart index b5449818..050cfeb5 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -35,6 +36,22 @@ class BmWriteDescriptorRequest { ); } + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmWriteDescriptorRequest && hashCode == other.hashCode; + } + Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart new file mode 100644 index 00000000..a94a835c --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart @@ -0,0 +1,244 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBluetoothDescriptor', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmBluetoothDescriptor.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptor_uuid': '0102', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptor uuid property', + () { + final descriptorUuid = '0102'; + + expect( + BmBluetoothDescriptor.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': descriptorUuid, + }).descriptorUuid, + equals(Guid(descriptorUuid)), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmBluetoothDescriptor.fromMap({ + 'remote_id': remoteId, + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmBluetoothDescriptor.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final characteristicUuid = Guid('0102'); + final descriptorUuid = Guid('0102'); + + expect( + BmBluetoothDescriptor( + remoteId: remoteId, + serviceUuid: serviceUuid, + characteristicUuid: characteristicUuid, + descriptorUuid: descriptorUuid, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str1'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ) == + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str2'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ) == + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the descriptor uuid property', + () { + final descriptorUuid = Guid('0102'); + + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: descriptorUuid, + ).toMap(), + containsPair( + 'descriptor_uuid', + equals(descriptorUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmBluetoothDescriptor( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart index 183f5a2f..f07a30eb 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart @@ -1,32 +1,96 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { group( - 'BmCharacteristicData', + 'BmDescriptorData', () { group( 'fromMap', () { test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + 'deserializes the characteristic uuid property', () { + final characteristicUuid = '0102'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptor uuid property', + () { + final descriptorUuid = '0102'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': descriptorUuid, + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).descriptorUuid, + equals(Guid(descriptorUuid)), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + expect( BmDescriptorData.fromMap({ - 'remote_id': '', + 'remote_id': remoteId, 'service_uuid': '0102', - 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', 'success': 1, 'error_code': 0, 'error_string': '', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), ); }, ); @@ -36,7 +100,7 @@ void main() { () { expect( BmDescriptorData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -51,14 +115,34 @@ void main() { }, ); + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + test( 'deserializes the success property as false if it is 0', () { expect( BmDescriptorData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', @@ -76,9 +160,8 @@ void main() { () { expect( BmDescriptorData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', @@ -96,9 +179,8 @@ void main() { () { expect( BmDescriptorData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', @@ -114,23 +196,20 @@ void main() { test( 'deserializes the value property', () { + final value = '010203'; + expect( BmDescriptorData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - 'value': '010203', + 'value': value, 'success': 1, 'error_code': 0, 'error_string': '', }).value, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), + equals(hex.decode(value)), ); }, ); @@ -140,9 +219,8 @@ void main() { () { expect( BmDescriptorData.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': null, @@ -150,7 +228,332 @@ void main() { 'error_code': 0, 'error_string': '', }).value, - isEmpty, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final descriptorUuid = Guid('0102'); + final value = []; + final success = true; + final errorCode = 0; + final errorString = ''; + + expect( + BmDescriptorData( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + descriptorUuid: descriptorUuid, + value: value, + success: success, + errorCode: errorCode, + errorString: errorString, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: false, + errorCode: 0, + errorString: '', + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the descriptor uuid property', + () { + final descriptorUuid = Guid('0102'); + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: descriptorUuid, + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'descriptor_uuid', + equals(descriptorUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmDescriptorData( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: false, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the value property', + () { + final value = [0x01, 0x02, 0x03]; + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: value, + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'value', + hex.encode(value), + ), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart index 1d600b87..2a1d1479 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart @@ -9,20 +9,53 @@ void main() { 'fromMap', () { test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + 'deserializes the characteristic uuid property', () { + final characteristicUuid = '0102'; + expect( BmReadDescriptorRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptor_uuid': '0102', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptor uuid property', + () { + final descriptorUuid = '0102'; + + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': descriptorUuid, + }).descriptorUuid, + equals(Guid(descriptorUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), ); }, ); @@ -32,7 +65,7 @@ void main() { () { expect( BmReadDescriptorRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -42,6 +75,229 @@ void main() { ); }, ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final descriptorUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + descriptorUuid: descriptorUuid, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ) == + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ) == + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the characteristic uuid property', + () { + final descriptorUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: descriptorUuid, + ).toMap(), + containsPair( + 'descriptor_uuid', + equals(descriptorUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmReadDescriptorRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); }, ); }, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart index d398ab6d..5ec1cf2c 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,21 +11,56 @@ void main() { 'fromMap', () { test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + 'deserializes the characteristic uuid property', () { + final characteristicUuid = '0102'; + expect( BmWriteDescriptorRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptor_uuid': '0102', + 'value': '', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptor uuid property', + () { + final descriptorUuid = '0102'; + + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': descriptorUuid, + 'value': '', + }).descriptorUuid, + equals(Guid(descriptorUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), ); }, ); @@ -33,7 +70,7 @@ void main() { () { expect( BmWriteDescriptorRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -45,23 +82,38 @@ void main() { }, ); + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + test( 'deserializes the value property', () { + final value = '010203'; + expect( BmWriteDescriptorRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - 'value': '010203', + 'value': value, }).value, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), + equals(hex.decode(value)), ); }, ); @@ -71,14 +123,253 @@ void main() { () { expect( BmWriteDescriptorRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'service_uuid': '0102', - 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': null, }).value, - isEmpty, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final descriptorUuid = Guid('0102'); + final value = []; + + expect( + BmWriteDescriptorRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + descriptorUuid: descriptorUuid, + value: value, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ) == + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ) == + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the characteristic uuid property', + () { + final descriptorUuid = Guid('0102'); + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: descriptorUuid, + value: [], + ).toMap(), + containsPair( + 'descriptor_uuid', + equals(descriptorUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmWriteDescriptorRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the value property', + () { + final value = [0x01, 0x02, 0x03]; + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: value, + ).toMap(), + containsPair( + 'value', + hex.encode(value), + ), ); }, ); From f23aaaa3751545fb1267cb8ec7ac99623da9f276 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Mon, 19 Aug 2024 20:11:28 +0100 Subject: [PATCH 38/90] test: update common models --- .../src/common/models/device_identifier.dart | 2 +- .../lib/src/common/models/options.dart | 11 ++ .../lib/src/common/models/phy_support.dart | 11 ++ .../test/device_identifier_test.dart | 36 ++++- .../test/guid_test.dart | 91 ++++++++++- .../test/options_test.dart | 104 +++++++++++++ .../test/phy_support_test.dart | 145 ++++++++++++++++++ 7 files changed, 389 insertions(+), 11 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/test/options_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart index 2d090b93..6206eaa4 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart @@ -19,7 +19,7 @@ class DeviceIdentifier { } @override - bool operator ==(other) { + bool operator ==(Object other) { return other is DeviceIdentifier && hashCode == other.hashCode; } } diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart index fec83483..eacd2c97 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart @@ -14,6 +14,17 @@ class Options { ); } + @override + bool operator ==(Object other) { + return identical(this, other) || + other is Options && hashCode == other.hashCode; + } + + @override + int get hashCode { + return showPowerAlert.hashCode; + } + Map toMap() { return { 'show_power_alert': showPowerAlert, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart index dc779840..f4530d4c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart @@ -19,6 +19,17 @@ class PhySupport { ); } + @override + int get hashCode { + return le2M.hashCode ^ leCoded.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is PhySupport && hashCode == other.hashCode; + } + Map toMap() { return { 'le_2M': le2M, diff --git a/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart b/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart index b08a090d..87da0ac3 100644 --- a/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart @@ -40,11 +40,26 @@ void main() { }, ); + group( + 'id', + () { + test( + 'returns the str property', + () { + expect( + DeviceIdentifier('str').id, + equals('str'), + ); + }, + ); + }, + ); + group( '==', () { test( - 'returns false if the identifiers are not equal', + 'returns false if they are not equal', () { expect( DeviceIdentifier('str1') == DeviceIdentifier('str2'), @@ -54,7 +69,7 @@ void main() { ); test( - 'returns true if the identifiers are equal', + 'returns true if they are equal', () { expect( DeviceIdentifier('str') == DeviceIdentifier('str'), @@ -64,7 +79,7 @@ void main() { ); test( - 'returns true if the identifiers are equal ignoring case', + 'returns true if they are equal ignoring case', () { expect( DeviceIdentifier('str') == DeviceIdentifier('STR'), @@ -74,6 +89,21 @@ void main() { ); }, ); + + group( + 'toString', + () { + test( + 'returns the str property', + () { + expect( + DeviceIdentifier('str').toString(), + equals('str'), + ); + }, + ); + }, + ); }, ); } diff --git a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart index 14af0716..3ec20d5a 100644 --- a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart @@ -5,6 +5,38 @@ void main() { group( 'Guid', () { + group( + 'empty', + () { + test( + 'constructs an instance', + () { + expect( + Guid.empty().bytes, + equals([ + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + ]), + ); + }, + ); + }, + ); + group( 'fromBytes', () { @@ -16,7 +48,7 @@ void main() { 0x01, 0x02, ]).bytes, - orderedEquals([ + equals([ 0x01, 0x02, ]), @@ -34,7 +66,7 @@ void main() { 0x03, 0x04, ]).bytes, - orderedEquals([ + equals([ 0x01, 0x02, 0x03, @@ -66,7 +98,7 @@ void main() { 0x34, 0xFB, ]).bytes, - orderedEquals([ + equals([ 0x01, 0x02, 0x03, @@ -114,7 +146,7 @@ void main() { () { expect( Guid.fromString('0102').bytes, - orderedEquals([ + equals([ 0x01, 0x02, ]), @@ -127,7 +159,7 @@ void main() { () { expect( Guid.fromString('01020304').bytes, - orderedEquals([ + equals([ 0x01, 0x02, 0x03, @@ -142,7 +174,7 @@ void main() { () { expect( Guid.fromString('0102030400001000800000805f9b34fb').bytes, - orderedEquals([ + equals([ 0x01, 0x02, 0x03, @@ -169,7 +201,7 @@ void main() { () { expect( Guid.fromString('01020304-0000-1000-8000-00805f9b34fb').bytes, - orderedEquals([ + equals([ 0x01, 0x02, 0x03, @@ -286,4 +318,49 @@ void main() { ); }, ); + + group( + 'uuid', + () { + test( + 'returns the str property', + () { + expect( + Guid('0102').uuid, + equals('0102'), + ); + }, + ); + }, + ); + + group( + 'uuid128', + () { + test( + 'returns the str128 property', + () { + expect( + Guid('0102').uuid128, + equals('00000102-0000-1000-8000-00805f9b34fb'), + ); + }, + ); + }, + ); + + group( + 'toString', + () { + test( + 'returns the str property', + () { + expect( + Guid('0102').toString(), + equals('0102'), + ); + }, + ); + }, + ); } diff --git a/packages/flutter_blue_plus_platform_interface/test/options_test.dart b/packages/flutter_blue_plus_platform_interface/test/options_test.dart new file mode 100644 index 00000000..9a9e4ee5 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/options_test.dart @@ -0,0 +1,104 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'Options', + () { + group( + 'fromMap', + () { + test( + 'deserializes the show power alert property', + () { + final showPowerAlert = false; + + expect( + Options.fromMap({ + 'show_power_alert': showPowerAlert, + }).showPowerAlert, + equals(showPowerAlert), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final showPowerAlert = false; + + expect( + Options( + showPowerAlert: showPowerAlert, + ).hashCode, + equals(showPowerAlert.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + Options( + showPowerAlert: false, + ) == + Options( + showPowerAlert: true, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + Options( + showPowerAlert: false, + ) == + Options( + showPowerAlert: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the show power alert property', + () { + final showPowerAlert = false; + + expect( + Options( + showPowerAlert: showPowerAlert, + ).toMap(), + containsPair( + 'show_power_alert', + equals(showPowerAlert), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart b/packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart new file mode 100644 index 00000000..97d72772 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart @@ -0,0 +1,145 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'PhySupport', + () { + group( + 'fromMap', + () { + test( + 'deserializes the le 2m property', + () { + final le2M = false; + + expect( + PhySupport.fromMap({ + 'le_2M': le2M, + 'le_coded': false, + }).le2M, + equals(le2M), + ); + }, + ); + + test( + 'deserializes the le coded property', + () { + final leCoded = false; + + expect( + PhySupport.fromMap({ + 'le_2M': false, + 'le_coded': leCoded, + }).leCoded, + equals(leCoded), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final le2M = false; + final leCoded = false; + + expect( + PhySupport( + le2M: le2M, + leCoded: leCoded, + ).hashCode, + equals(le2M.hashCode ^ leCoded.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + PhySupport( + le2M: false, + leCoded: false, + ) == + PhySupport( + le2M: true, + leCoded: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + PhySupport( + le2M: false, + leCoded: false, + ) == + PhySupport( + le2M: false, + leCoded: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the le 2m property', + () { + final le2M = false; + + expect( + PhySupport( + le2M: le2M, + leCoded: false, + ).toMap(), + containsPair( + 'le_2M', + equals(le2M), + ), + ); + }, + ); + + test( + 'serializes the le coded property', + () { + final leCoded = false; + + expect( + PhySupport( + le2M: false, + leCoded: leCoded, + ).toMap(), + containsPair( + 'le_coded', + equals(leCoded), + ), + ); + }, + ); + }, + ); + }, + ); +} From cf1667dfa8e9dd90caf63ba87ecaa068956ac35a Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Tue, 20 Aug 2024 07:12:22 +0100 Subject: [PATCH 39/90] refactor: reorganize based on conventions https://github.com/flutter/packages --- .../flutter_blue_plus_platform_interface.dart | 43 +-- .../method_channel_flutter_blue_plus.dart | 30 +- .../flutter_blue_plus_platform.dart | 32 +- .../bm_adapter_state_enum.dart | 0 .../bm_bluetooth_adapter_state.dart | 2 +- .../bm_bluetooth_characteristic.dart | 6 +- .../bm_bluetooth_descriptor.dart | 4 +- .../models => types}/bm_bluetooth_device.dart | 2 +- .../bm_bluetooth_service.dart | 6 +- .../enums => types}/bm_bond_state_enum.dart | 0 .../bm_bond_state_response.dart | 4 +- .../bm_characteristic_data.dart | 4 +- .../bm_characteristic_properties.dart | 0 .../models => types}/bm_connect_request.dart | 2 +- .../bm_connection_priority_enum.dart | 0 .../bm_connection_priority_request.dart | 4 +- .../bm_connection_state_enum.dart | 0 .../bm_connection_state_response.dart | 4 +- .../models => types}/bm_descriptor_data.dart | 4 +- .../models => types}/bm_devices_list.dart | 0 .../bm_discover_services_result.dart | 2 +- .../{scan/models => types}/bm_msd_filter.dart | 0 .../bm_mtu_change_request.dart | 2 +- .../bm_mtu_changed_response.dart | 2 +- .../models => types}/bm_name_changed.dart | 2 +- .../models => types}/bm_preferred_phy.dart | 2 +- .../bm_read_characteristic_request.dart | 4 +- .../bm_read_descriptor_request.dart | 4 +- .../models => types}/bm_read_rssi_result.dart | 2 +- .../bm_scan_advertisement.dart | 4 +- .../models => types}/bm_scan_response.dart | 0 .../models => types}/bm_scan_settings.dart | 2 +- .../bm_service_data_filter.dart | 2 +- .../bm_set_notify_value_request.dart | 4 +- .../models => types}/bm_turn_on_response.dart | 0 .../bm_write_characteristic_request.dart | 6 +- .../bm_write_descriptor_request.dart | 4 +- .../enums => types}/bm_write_type.dart | 0 .../models => types}/device_identifier.dart | 0 .../src/{common/models => types}/guid.dart | 0 .../{common/enums => types}/log_level.dart | 0 .../src/{common/models => types}/options.dart | 0 .../{common/models => types}/phy_support.dart | 0 .../lib/src/types/types.dart | 40 +++ .../bm_set_notify_value_request_test.dart | 51 ---- ...method_channel_flutter_blue_plus_test.dart | 152 +++++----- .../bm_bluetooth_adapter_state_test.dart | 0 .../bm_bluetooth_characteristic_test.dart | 0 .../bm_bluetooth_descriptor_test.dart | 0 .../bm_bluetooth_service_test.dart | 0 .../bm_bond_state_response_test.dart | 12 +- .../bm_characteristic_data_test.dart | 0 .../bm_characteristic_properties_test.dart | 0 .../bm_connection_priority_request_test.dart | 6 +- .../bm_connection_state_response_test.dart | 6 +- .../{ => types}/bm_descriptor_data_test.dart | 0 .../{ => types}/bm_devices_list_test.dart | 2 +- .../bm_discover_services_result_test.dart | 0 .../test/{ => types}/bm_msd_filter_test.dart | 0 .../bm_mtu_changed_response_test.dart | 6 +- .../bm_read_characteristic_request_test.dart | 0 .../bm_read_descriptor_request_test.dart | 0 .../{ => types}/bm_read_rssi_result_test.dart | 6 +- .../bm_scan_advertisement_test.dart | 0 .../{ => types}/bm_scan_response_test.dart | 0 .../{ => types}/bm_scan_settings_test.dart | 0 .../bm_service_data_filter_test.dart | 0 .../bm_set_notify_value_request_test.dart | 284 ++++++++++++++++++ .../{ => types}/bm_turn_on_response_test.dart | 0 .../bm_write_characteristic_request_test.dart | 2 +- .../bm_write_descriptor_request_test.dart | 0 .../{ => types}/device_identifier_test.dart | 0 .../test/{ => types}/guid_test.dart | 0 .../test/{ => types}/options_test.dart | 0 .../test/{ => types}/phy_support_test.dart | 0 75 files changed, 470 insertions(+), 286 deletions(-) rename packages/flutter_blue_plus_platform_interface/lib/src/{ => method_channel}/method_channel_flutter_blue_plus.dart (87%) rename packages/flutter_blue_plus_platform_interface/lib/src/{ => platform_interface}/flutter_blue_plus_platform.dart (86%) rename packages/flutter_blue_plus_platform_interface/lib/src/{adapter/enums => types}/bm_adapter_state_enum.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{adapter/models => types}/bm_bluetooth_adapter_state.dart (93%) rename packages/flutter_blue_plus_platform_interface/lib/src/{characteristic/models => types}/bm_bluetooth_characteristic.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{descriptor/models => types}/bm_bluetooth_descriptor.dart (92%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_bluetooth_device.dart (90%) rename packages/flutter_blue_plus_platform_interface/lib/src/{service/models => types}/bm_bluetooth_service.dart (92%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/enums => types}/bm_bond_state_enum.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_bond_state_response.dart (89%) rename packages/flutter_blue_plus_platform_interface/lib/src/{characteristic/models => types}/bm_characteristic_data.dart (95%) rename packages/flutter_blue_plus_platform_interface/lib/src/{characteristic/models => types}/bm_characteristic_properties.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_connect_request.dart (90%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/enums => types}/bm_connection_priority_enum.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_connection_priority_request.dart (86%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/enums => types}/bm_connection_state_enum.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_connection_state_response.dart (90%) rename packages/flutter_blue_plus_platform_interface/lib/src/{descriptor/models => types}/bm_descriptor_data.dart (96%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_devices_list.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{service/models => types}/bm_discover_services_result.dart (96%) rename packages/flutter_blue_plus_platform_interface/lib/src/{scan/models => types}/bm_msd_filter.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_mtu_change_request.dart (89%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_mtu_changed_response.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_name_changed.dart (89%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_preferred_phy.dart (92%) rename packages/flutter_blue_plus_platform_interface/lib/src/{characteristic/models => types}/bm_read_characteristic_request.dart (93%) rename packages/flutter_blue_plus_platform_interface/lib/src/{descriptor/models => types}/bm_read_descriptor_request.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{device/models => types}/bm_read_rssi_result.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{scan/models => types}/bm_scan_advertisement.dart (96%) rename packages/flutter_blue_plus_platform_interface/lib/src/{scan/models => types}/bm_scan_response.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{scan/models => types}/bm_scan_settings.dart (98%) rename packages/flutter_blue_plus_platform_interface/lib/src/{scan/models => types}/bm_service_data_filter.dart (96%) rename packages/flutter_blue_plus_platform_interface/lib/src/{characteristic/models => types}/bm_set_notify_value_request.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{adapter/models => types}/bm_turn_on_response.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{characteristic/models => types}/bm_write_characteristic_request.dart (93%) rename packages/flutter_blue_plus_platform_interface/lib/src/{descriptor/models => types}/bm_write_descriptor_request.dart (95%) rename packages/flutter_blue_plus_platform_interface/lib/src/{characteristic/enums => types}/bm_write_type.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{common/models => types}/device_identifier.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{common/models => types}/guid.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{common/enums => types}/log_level.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{common/models => types}/options.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{common/models => types}/phy_support.dart (100%) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart rename packages/flutter_blue_plus_platform_interface/test/{ => method_channel}/method_channel_flutter_blue_plus_test.dart (93%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_bluetooth_adapter_state_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_bluetooth_characteristic_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_bluetooth_descriptor_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_bluetooth_service_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_bond_state_response_test.dart (90%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_characteristic_data_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_characteristic_properties_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_connection_priority_request_test.dart (91%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_connection_state_response_test.dart (91%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_descriptor_data_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_devices_list_test.dart (95%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_discover_services_result_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_msd_filter_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_mtu_changed_response_test.dart (92%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_read_characteristic_request_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_read_descriptor_request_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_read_rssi_result_test.dart (92%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_scan_advertisement_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_scan_response_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_scan_settings_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_service_data_filter_test.dart (100%) create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_turn_on_response_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_write_characteristic_request_test.dart (99%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/bm_write_descriptor_request_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/device_identifier_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/guid_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/options_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{ => types}/phy_support_test.dart (100%) diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index e5a9820c..1a25e3b6 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -1,44 +1,5 @@ -export 'src/adapter/enums/bm_adapter_state_enum.dart'; -export 'src/adapter/models/bm_bluetooth_adapter_state.dart'; -export 'src/adapter/models/bm_turn_on_response.dart'; -export 'src/characteristic/enums/bm_write_type.dart'; -export 'src/characteristic/models/bm_bluetooth_characteristic.dart'; -export 'src/characteristic/models/bm_characteristic_data.dart'; -export 'src/characteristic/models/bm_characteristic_properties.dart'; -export 'src/characteristic/models/bm_read_characteristic_request.dart'; -export 'src/characteristic/models/bm_set_notify_value_request.dart'; -export 'src/characteristic/models/bm_write_characteristic_request.dart'; -export 'src/common/enums/log_level.dart'; -export 'src/common/models/device_identifier.dart'; -export 'src/common/models/guid.dart'; -export 'src/common/models/options.dart'; -export 'src/common/models/phy_support.dart'; -export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; -export 'src/descriptor/models/bm_descriptor_data.dart'; -export 'src/descriptor/models/bm_read_descriptor_request.dart'; -export 'src/descriptor/models/bm_write_descriptor_request.dart'; -export 'src/device/enums/bm_bond_state_enum.dart'; -export 'src/device/enums/bm_connection_priority_enum.dart'; -export 'src/device/enums/bm_connection_state_enum.dart'; -export 'src/device/models/bm_bluetooth_device.dart'; -export 'src/device/models/bm_bond_state_response.dart'; -export 'src/device/models/bm_connect_request.dart'; -export 'src/device/models/bm_connection_priority_request.dart'; -export 'src/device/models/bm_connection_state_response.dart'; -export 'src/device/models/bm_devices_list.dart'; -export 'src/device/models/bm_mtu_change_request.dart'; -export 'src/device/models/bm_mtu_changed_response.dart'; -export 'src/device/models/bm_name_changed.dart'; -export 'src/device/models/bm_preferred_phy.dart'; -export 'src/device/models/bm_read_rssi_result.dart'; -export 'src/flutter_blue_plus_platform.dart'; -export 'src/scan/models/bm_msd_filter.dart'; -export 'src/scan/models/bm_scan_advertisement.dart'; -export 'src/scan/models/bm_scan_response.dart'; -export 'src/scan/models/bm_scan_settings.dart'; -export 'src/scan/models/bm_service_data_filter.dart'; -export 'src/service/models/bm_bluetooth_service.dart'; -export 'src/service/models/bm_discover_services_result.dart'; +export 'src/platform_interface/flutter_blue_plus_platform.dart'; +export 'src/types/types.dart'; // random number defined by flutter blue plus int bmUserCanceledErrorCode = 23789258; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart similarity index 87% rename from packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart index 3814e1d2..f30e1111 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart @@ -3,34 +3,8 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; -import 'adapter/models/bm_bluetooth_adapter_state.dart'; -import 'adapter/models/bm_turn_on_response.dart'; -import 'characteristic/models/bm_characteristic_data.dart'; -import 'characteristic/models/bm_read_characteristic_request.dart'; -import 'characteristic/models/bm_set_notify_value_request.dart'; -import 'characteristic/models/bm_write_characteristic_request.dart'; -import 'common/enums/log_level.dart'; -import 'common/models/device_identifier.dart'; -import 'common/models/options.dart'; -import 'common/models/phy_support.dart'; -import 'descriptor/models/bm_descriptor_data.dart'; -import 'descriptor/models/bm_read_descriptor_request.dart'; -import 'descriptor/models/bm_write_descriptor_request.dart'; -import 'device/models/bm_bluetooth_device.dart'; -import 'device/models/bm_bond_state_response.dart'; -import 'device/models/bm_connect_request.dart'; -import 'device/models/bm_connection_priority_request.dart'; -import 'device/models/bm_connection_state_response.dart'; -import 'device/models/bm_devices_list.dart'; -import 'device/models/bm_mtu_change_request.dart'; -import 'device/models/bm_mtu_changed_response.dart'; -import 'device/models/bm_name_changed.dart'; -import 'device/models/bm_preferred_phy.dart'; -import 'device/models/bm_read_rssi_result.dart'; -import 'flutter_blue_plus_platform.dart'; -import 'scan/models/bm_scan_response.dart'; -import 'scan/models/bm_scan_settings.dart'; -import 'service/models/bm_discover_services_result.dart'; +import '../platform_interface/flutter_blue_plus_platform.dart'; +import '../types/types.dart'; /// An implementation of [FlutterBluePlusPlatform] that uses method channels. class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart similarity index 86% rename from packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart index 31deb750..d99a4de9 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart @@ -1,33 +1,9 @@ +// coverage:ignore-file + import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'adapter/models/bm_bluetooth_adapter_state.dart'; -import 'adapter/models/bm_turn_on_response.dart'; -import 'characteristic/models/bm_characteristic_data.dart'; -import 'characteristic/models/bm_read_characteristic_request.dart'; -import 'characteristic/models/bm_set_notify_value_request.dart'; -import 'characteristic/models/bm_write_characteristic_request.dart'; -import 'common/enums/log_level.dart'; -import 'common/models/device_identifier.dart'; -import 'common/models/options.dart'; -import 'common/models/phy_support.dart'; -import 'descriptor/models/bm_descriptor_data.dart'; -import 'descriptor/models/bm_read_descriptor_request.dart'; -import 'descriptor/models/bm_write_descriptor_request.dart'; -import 'device/models/bm_bluetooth_device.dart'; -import 'device/models/bm_bond_state_response.dart'; -import 'device/models/bm_connect_request.dart'; -import 'device/models/bm_connection_priority_request.dart'; -import 'device/models/bm_connection_state_response.dart'; -import 'device/models/bm_devices_list.dart'; -import 'device/models/bm_mtu_change_request.dart'; -import 'device/models/bm_mtu_changed_response.dart'; -import 'device/models/bm_name_changed.dart'; -import 'device/models/bm_preferred_phy.dart'; -import 'device/models/bm_read_rssi_result.dart'; -import 'method_channel_flutter_blue_plus.dart'; -import 'scan/models/bm_scan_response.dart'; -import 'scan/models/bm_scan_settings.dart'; -import 'service/models/bm_discover_services_result.dart'; +import '../method_channel/method_channel_flutter_blue_plus.dart'; +import '../types/types.dart'; /// The interface that implementations of flutter_blue_plus must implement. abstract class FlutterBluePlusPlatform extends PlatformInterface { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart similarity index 93% rename from packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart index 949178f3..f6dbbc8e 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart @@ -1,4 +1,4 @@ -import '../enums/bm_adapter_state_enum.dart'; +import 'bm_adapter_state_enum.dart'; class BmBluetoothAdapterState { BmAdapterStateEnum adapterState; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart index a59ed0e9..ca244583 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart @@ -1,9 +1,9 @@ import 'package:collection/collection.dart'; -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; -import '../../descriptor/models/bm_bluetooth_descriptor.dart'; +import 'guid.dart'; +import 'bm_bluetooth_descriptor.dart'; import 'bm_characteristic_properties.dart'; +import 'device_identifier.dart'; class BmBluetoothCharacteristic { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart index 3c0ae230..9a0160ae 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart @@ -1,5 +1,5 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'guid.dart'; +import 'device_identifier.dart'; class BmBluetoothDescriptor { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart similarity index 90% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart index 73ccb88b..6a16229e 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart @@ -1,4 +1,4 @@ -import '../../common/models/device_identifier.dart'; +import 'device_identifier.dart'; class BmBluetoothDevice { DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart index 97551b18..f527820d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; -import '../../characteristic/models/bm_bluetooth_characteristic.dart'; -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'guid.dart'; +import 'bm_bluetooth_characteristic.dart'; +import 'device_identifier.dart'; class BmBluetoothService { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart similarity index 89% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart index c2258855..bacb627e 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart @@ -1,5 +1,5 @@ -import '../../common/models/device_identifier.dart'; -import '../enums/bm_bond_state_enum.dart'; +import 'bm_bond_state_enum.dart'; +import 'device_identifier.dart'; class BmBondStateResponse { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart similarity index 95% rename from packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart index df3698d4..f837cf35 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; class BmCharacteristicData { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart similarity index 90% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart index ad0407d8..b56394c8 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart @@ -1,4 +1,4 @@ -import '../../common/models/device_identifier.dart'; +import 'device_identifier.dart'; class BmConnectRequest { DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart similarity index 86% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart index d9d0c1da..118080c1 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart @@ -1,5 +1,5 @@ -import '../../common/models/device_identifier.dart'; -import '../enums/bm_connection_priority_enum.dart'; +import 'bm_connection_priority_enum.dart'; +import 'device_identifier.dart'; class BmConnectionPriorityRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart similarity index 90% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart index 084deb10..43553e89 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart @@ -1,5 +1,5 @@ -import '../../common/models/device_identifier.dart'; -import '../enums/bm_connection_state_enum.dart'; +import 'bm_connection_state_enum.dart'; +import 'device_identifier.dart'; class BmConnectionStateResponse { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart similarity index 96% rename from packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart index a3d1045c..ae9999db 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'guid.dart'; +import 'device_identifier.dart'; class BmDescriptorData { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart similarity index 96% rename from packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart index 689c1eed..b82d5b43 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart @@ -1,7 +1,7 @@ import 'package:collection/collection.dart'; -import '../../common/models/device_identifier.dart'; import 'bm_bluetooth_service.dart'; +import 'device_identifier.dart'; class BmDiscoverServicesResult { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart similarity index 89% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart index 86138397..4c03df5f 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart @@ -1,4 +1,4 @@ -import '../../common/models/device_identifier.dart'; +import 'device_identifier.dart'; class BmMtuChangeRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart index ccd1c2ff..2ffbc90b 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart @@ -1,4 +1,4 @@ -import '../../common/models/device_identifier.dart'; +import 'device_identifier.dart'; class BmMtuChangedResponse { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart similarity index 89% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart index 75fe4d8b..54597f3d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart @@ -1,4 +1,4 @@ -import '../../common/models/device_identifier.dart'; +import 'device_identifier.dart'; class BmNameChanged { DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart index d2c0b630..b8accc11 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart @@ -1,4 +1,4 @@ -import '../../common/models/device_identifier.dart'; +import 'device_identifier.dart'; class BmPreferredPhy { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart similarity index 93% rename from packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart index aae99675..9c706891 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart @@ -1,5 +1,5 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; class BmReadCharacteristicRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart index 5cb4de6f..dec81238 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart @@ -1,5 +1,5 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'guid.dart'; +import 'device_identifier.dart'; class BmReadDescriptorRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart index 81aa5822..b2436d63 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart @@ -1,4 +1,4 @@ -import '../../common/models/device_identifier.dart'; +import 'device_identifier.dart'; class BmReadRssiResult { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart similarity index 96% rename from packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart index f4469fc6..4c51b4d3 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'guid.dart'; +import 'device_identifier.dart'; class BmScanAdvertisement { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart similarity index 98% rename from packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart index ab1eb303..978beed3 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; -import '../../common/models/guid.dart'; import 'bm_msd_filter.dart'; import 'bm_service_data_filter.dart'; +import 'guid.dart'; class BmScanSettings { final List withServices; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart similarity index 96% rename from packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart index 09e1af6e..489bc570 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart @@ -1,7 +1,7 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import '../../common/models/guid.dart'; +import 'guid.dart'; class BmServiceDataFilter { Guid service; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart index 4208f91c..9d831817 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart @@ -1,5 +1,5 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; class BmSetNotifyValueRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart similarity index 93% rename from packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart index 95504041..35482049 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart @@ -1,9 +1,9 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; -import '../enums/bm_write_type.dart'; +import 'bm_write_type.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; class BmWriteCharacteristicRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart similarity index 95% rename from packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart index 050cfeb5..6634b1de 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; +import 'guid.dart'; +import 'device_identifier.dart'; class BmWriteDescriptorRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/device_identifier.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/device_identifier.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/log_level.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/log_level.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/options.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/options.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/phy_support.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/types/phy_support.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart new file mode 100644 index 00000000..7c3913d1 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart @@ -0,0 +1,40 @@ +export 'bm_adapter_state_enum.dart'; +export 'bm_bluetooth_adapter_state.dart'; +export 'bm_bluetooth_characteristic.dart'; +export 'bm_bluetooth_descriptor.dart'; +export 'bm_bluetooth_device.dart'; +export 'bm_bluetooth_service.dart'; +export 'bm_bond_state_enum.dart'; +export 'bm_bond_state_response.dart'; +export 'bm_characteristic_data.dart'; +export 'bm_characteristic_properties.dart'; +export 'bm_connect_request.dart'; +export 'bm_connection_priority_enum.dart'; +export 'bm_connection_priority_request.dart'; +export 'bm_connection_state_enum.dart'; +export 'bm_connection_state_response.dart'; +export 'bm_descriptor_data.dart'; +export 'bm_devices_list.dart'; +export 'bm_discover_services_result.dart'; +export 'bm_msd_filter.dart'; +export 'bm_mtu_change_request.dart'; +export 'bm_mtu_changed_response.dart'; +export 'bm_name_changed.dart'; +export 'bm_preferred_phy.dart'; +export 'bm_read_characteristic_request.dart'; +export 'bm_read_descriptor_request.dart'; +export 'bm_read_rssi_result.dart'; +export 'bm_scan_advertisement.dart'; +export 'bm_scan_response.dart'; +export 'bm_scan_settings.dart'; +export 'bm_service_data_filter.dart'; +export 'bm_set_notify_value_request.dart'; +export 'bm_turn_on_response.dart'; +export 'bm_write_characteristic_request.dart'; +export 'bm_write_descriptor_request.dart'; +export 'bm_write_type.dart'; +export 'device_identifier.dart'; +export 'guid.dart'; +export 'log_level.dart'; +export 'options.dart'; +export 'phy_support.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart deleted file mode 100644 index 2dcb0ae7..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmSetNotifyValueRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).secondaryServiceUuid, - isNull, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart similarity index 93% rename from packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart rename to packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart index 39b821b2..c799341b 100644 --- a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart @@ -1,6 +1,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/method_channel_flutter_blue_plus.dart'; +import 'package:flutter_blue_plus_platform_interface/src/method_channel/method_channel_flutter_blue_plus.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -72,7 +72,7 @@ void main() { 'deserializes the event', () async { final arguments = BmBondStateResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), bondState: BmBondStateEnum.none, ).toMap(); @@ -98,7 +98,7 @@ void main() { 'handles the method call', () async { final arguments = BmBondStateResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), bondState: BmBondStateEnum.none, ).toMap(); @@ -125,7 +125,7 @@ void main() { 'deserializes the event', () async { final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), value: [], @@ -156,7 +156,7 @@ void main() { 'handles the method call', () async { final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), value: [], @@ -188,7 +188,7 @@ void main() { 'deserializes the event', () async { final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), value: [], @@ -219,7 +219,7 @@ void main() { 'handles the method call', () async { final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), value: [], @@ -251,7 +251,7 @@ void main() { 'deserializes the event', () async { final arguments = BmConnectionStateResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), connectionState: BmConnectionStateEnum.disconnected, ).toMap(); @@ -277,7 +277,7 @@ void main() { 'handles the method call', () async { final arguments = BmConnectionStateResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), connectionState: BmConnectionStateEnum.disconnected, ).toMap(); @@ -304,7 +304,7 @@ void main() { 'deserializes the event', () async { final arguments = BmDescriptorData( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -336,7 +336,7 @@ void main() { 'handles the method call', () async { final arguments = BmDescriptorData( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -369,7 +369,7 @@ void main() { 'deserializes the event', () async { final arguments = BmDescriptorData( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -401,7 +401,7 @@ void main() { 'handles the method call', () async { final arguments = BmDescriptorData( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -455,7 +455,7 @@ void main() { 'deserializes the event', () async { final arguments = BmDiscoverServicesResult( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), services: [], success: true, errorCode: 0, @@ -484,7 +484,7 @@ void main() { 'handles the method call', () async { final arguments = BmDiscoverServicesResult( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), services: [], success: true, errorCode: 0, @@ -514,7 +514,7 @@ void main() { 'deserializes the event', () async { final arguments = BmMtuChangedResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), mtu: 0, success: true, errorCode: 0, @@ -543,7 +543,7 @@ void main() { 'handles the method call', () async { final arguments = BmMtuChangedResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), mtu: 0, success: true, errorCode: 0, @@ -573,7 +573,7 @@ void main() { 'deserializes the event', () async { final arguments = BmNameChanged( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), name: '', ).toMap(); @@ -599,7 +599,7 @@ void main() { 'handles the method call', () async { final arguments = BmNameChanged( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), name: '', ).toMap(); @@ -626,7 +626,7 @@ void main() { 'deserializes the event', () async { final arguments = BmReadRssiResult( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), rssi: 0, success: true, errorCode: 0, @@ -655,7 +655,7 @@ void main() { 'handles the method call', () async { final arguments = BmReadRssiResult( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), rssi: 0, success: true, errorCode: 0, @@ -742,7 +742,7 @@ void main() { 'deserializes the event', () async { final arguments = BmBluetoothDevice( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), ).toMap(); expectLater( @@ -767,7 +767,7 @@ void main() { 'handles the method call', () async { final arguments = BmBluetoothDevice( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), ).toMap(); expectLater( @@ -843,13 +843,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); await flutterBluePlus.clearGattCache(device); expect( log, - orderedEquals([ + equals([ isMethodCall( 'clearGattCache', arguments: device.str, @@ -884,7 +884,7 @@ void main() { 'deserializes the result', () async { final request = BmConnectRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), autoConnect: false, ); @@ -899,7 +899,7 @@ void main() { 'invokes the method', () async { final request = BmConnectRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), autoConnect: false, ); @@ -907,7 +907,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'connect', arguments: request.toMap(), @@ -955,7 +955,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'connectedCount', arguments: null, @@ -989,7 +989,7 @@ void main() { test( 'deserializes the result', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); expect( await flutterBluePlus.createBond(device), @@ -1001,13 +1001,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); await flutterBluePlus.createBond(device); expect( log, - orderedEquals([ + equals([ isMethodCall( 'createBond', arguments: device.str, @@ -1041,7 +1041,7 @@ void main() { test( 'deserializes the result', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); expect( await flutterBluePlus.disconnect(device), @@ -1053,13 +1053,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); await flutterBluePlus.disconnect(device); expect( log, - orderedEquals([ + equals([ isMethodCall( 'disconnect', arguments: device.str, @@ -1077,13 +1077,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); await flutterBluePlus.discoverServices(device); expect( log, - orderedEquals([ + equals([ isMethodCall( 'discoverServices', arguments: device.str, @@ -1131,7 +1131,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'flutterRestart', arguments: null, @@ -1179,7 +1179,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'getAdapterName', arguments: null, @@ -1229,7 +1229,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'getAdapterState', arguments: null, @@ -1245,7 +1245,7 @@ void main() { 'getBondState', () { final result = BmBondStateResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), bondState: BmBondStateEnum.none, ); @@ -1266,7 +1266,7 @@ void main() { test( 'deserializes the result', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); expect( (await flutterBluePlus.getBondState(device)).toMap(), @@ -1278,13 +1278,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); await flutterBluePlus.getBondState(device); expect( log, - orderedEquals([ + equals([ isMethodCall( 'getBondState', arguments: device.str, @@ -1334,7 +1334,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'getBondedDevices', arguments: null, @@ -1385,7 +1385,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'getPhySupport', arguments: null, @@ -1435,7 +1435,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'getSystemDevices', arguments: null, @@ -1483,7 +1483,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'isSupported', arguments: null, @@ -1502,7 +1502,7 @@ void main() { 'invokes the method', () async { final request = BmReadCharacteristicRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), ); @@ -1511,7 +1511,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'readCharacteristic', arguments: request.toMap(), @@ -1530,7 +1530,7 @@ void main() { 'invokes the method', () async { final request = BmReadDescriptorRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -1540,7 +1540,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'readDescriptor', arguments: request.toMap(), @@ -1558,13 +1558,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); await flutterBluePlus.readRssi(device); expect( log, - orderedEquals([ + equals([ isMethodCall( 'readRssi', arguments: device.str, @@ -1598,7 +1598,7 @@ void main() { test( 'deserializes the result', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); expect( await flutterBluePlus.removeBond(device), @@ -1610,13 +1610,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier(''); + final device = DeviceIdentifier('str'); await flutterBluePlus.removeBond(device); expect( log, - orderedEquals([ + equals([ isMethodCall( 'removeBond', arguments: device.str, @@ -1635,7 +1635,7 @@ void main() { 'invokes the method', () async { final request = BmConnectionPriorityRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), connectionPriority: BmConnectionPriorityEnum.balanced, ); @@ -1643,7 +1643,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'requestConnectionPriority', arguments: request.toMap(), @@ -1662,7 +1662,7 @@ void main() { 'invokes the method', () async { final request = BmMtuChangeRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), mtu: 0, ); @@ -1670,7 +1670,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'requestMtu', arguments: request.toMap(), @@ -1694,7 +1694,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'setLogLevel', arguments: level.index, @@ -1729,7 +1729,7 @@ void main() { 'deserializes the result', () async { final request = BmSetNotifyValueRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), forceIndications: false, @@ -1747,7 +1747,7 @@ void main() { 'invokes the method', () async { final request = BmSetNotifyValueRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), forceIndications: false, @@ -1758,7 +1758,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'setNotifyValue', arguments: request.toMap(), @@ -1784,7 +1784,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'setOptions', arguments: options.toMap(), @@ -1803,7 +1803,7 @@ void main() { 'invokes the method', () async { final preferredPhy = BmPreferredPhy( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), txPhy: 0, rxPhy: 0, phyOptions: 0, @@ -1813,7 +1813,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'setPreferredPhy', arguments: preferredPhy.toMap(), @@ -1849,7 +1849,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'startScan', arguments: settings.toMap(), @@ -1871,7 +1871,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'stopScan', arguments: null, @@ -1893,7 +1893,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'turnOff', arguments: null, @@ -1941,7 +1941,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'turnOn', arguments: null, @@ -1960,7 +1960,7 @@ void main() { 'invokes the method', () async { final request = BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), writeType: BmWriteType.withResponse, @@ -1972,7 +1972,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'writeCharacteristic', arguments: request.toMap(), @@ -1991,7 +1991,7 @@ void main() { 'invokes the method', () async { final request = BmWriteDescriptorRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -2002,7 +2002,7 @@ void main() { expect( log, - orderedEquals([ + equals([ isMethodCall( 'writeDescriptor', arguments: request.toMap(), diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart similarity index 90% rename from packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart index e03e9c5a..b3d893c2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmBondStateResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'bond_state': 0, }).bondState, equals(BmBondStateEnum.none), @@ -26,7 +26,7 @@ void main() { () { expect( BmBondStateResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'bond_state': 0, 'prev_state': 0, }).prevState, @@ -41,7 +41,7 @@ void main() { expect( () { BmBondStateResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'bond_state': 3, }); }, @@ -56,7 +56,7 @@ void main() { expect( () { BmBondStateResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'bond_state': 0, 'prev_state': 3, }); @@ -76,7 +76,7 @@ void main() { () { expect( BmBondStateResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), bondState: BmBondStateEnum.none, ).toMap(), containsPair('bond_state', 0), @@ -89,7 +89,7 @@ void main() { () { expect( BmBondStateResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), bondState: BmBondStateEnum.none, prevState: BmBondStateEnum.none, ).toMap(), diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart similarity index 91% rename from packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart index 03ed371f..46d33333 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmConnectionPriorityRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connection_priority': 0, }).connectionPriority, equals(BmConnectionPriorityEnum.balanced), @@ -27,7 +27,7 @@ void main() { expect( () { BmConnectionPriorityRequest.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connection_priority': 3, }); }, @@ -46,7 +46,7 @@ void main() { () { expect( BmConnectionPriorityRequest( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), connectionPriority: BmConnectionPriorityEnum.balanced, ).toMap(), containsPair('connection_priority', 0), diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart similarity index 91% rename from packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart index c9425121..4a33d69c 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmConnectionStateResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connection_state': 0, }).connectionState, equals(BmConnectionStateEnum.disconnected), @@ -27,7 +27,7 @@ void main() { expect( () { BmConnectionStateResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'connection_state': 2, }); }, @@ -46,7 +46,7 @@ void main() { () { expect( BmConnectionStateResponse( - remoteId: DeviceIdentifier(''), + remoteId: DeviceIdentifier('str'), connectionState: BmConnectionStateEnum.disconnected, ).toMap(), containsPair('connection_state', 0), diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart similarity index 95% rename from packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart index e1edfa34..0beef270 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart @@ -15,7 +15,7 @@ void main() { BmDevicesList.fromMap({ 'devices': null, }).devices, - isEmpty, + equals([]), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart index 4b92659e..b2386ec5 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmMtuChangedResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'mtu': 0, 'success': 0, 'error_code': 0, @@ -29,7 +29,7 @@ void main() { () { expect( BmMtuChangedResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'mtu': 0, 'success': null, 'error_code': 0, @@ -45,7 +45,7 @@ void main() { () { expect( BmMtuChangedResponse.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'mtu': 0, 'success': 1, 'error_code': 0, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart index 851a4c10..4af76ce0 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmReadRssiResult.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'rssi': 0, 'success': 0, 'error_code': 0, @@ -29,7 +29,7 @@ void main() { () { expect( BmReadRssiResult.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'rssi': 0, 'success': null, 'error_code': 0, @@ -45,7 +45,7 @@ void main() { () { expect( BmReadRssiResult.fromMap({ - 'remote_id': '', + 'remote_id': 'str', 'rssi': 0, 'success': 1, 'error_code': 0, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart new file mode 100644 index 00000000..4ce9ebe5 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart @@ -0,0 +1,284 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmSetNotifyValueRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'force_indications': false, + 'enable': false, + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final forceIndications = false; + final enable = false; + + expect( + BmSetNotifyValueRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + forceIndications: forceIndications, + enable: enable, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + forceIndications.hashCode ^ + enable.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ) == + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ) == + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmSetNotifyValueRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart similarity index 99% rename from packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart index c81239b2..4b5c169b 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart @@ -151,7 +151,7 @@ void main() { 'allow_long_write': 0, 'value': null, }).value, - isEmpty, + equals([]), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/guid_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/options_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/options_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/options_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/options_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart rename to packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart From 202356b8172091e639f9ac381dc310163e9ce193 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Tue, 20 Aug 2024 07:40:04 +0100 Subject: [PATCH 40/90] refactor: copy implementations from dependencies --- .../types/bm_bluetooth_characteristic.dart | 5 +- .../lib/src/types/bm_bluetooth_service.dart | 2 +- .../lib/src/types/bm_characteristic_data.dart | 4 +- .../lib/src/types/bm_descriptor_data.dart | 6 +- .../types/bm_discover_services_result.dart | 3 +- .../lib/src/types/bm_msd_filter.dart | 3 +- .../lib/src/types/bm_scan_advertisement.dart | 6 +- .../lib/src/types/bm_scan_response.dart | 3 +- .../lib/src/types/bm_scan_settings.dart | 3 +- .../lib/src/types/bm_service_data_filter.dart | 4 +- .../bm_write_characteristic_request.dart | 4 +- .../types/bm_write_descriptor_request.dart | 6 +- .../lib/src/types/guid.dart | 2 +- .../lib/src/utils/equality.dart | 501 ++++++++++++++++++ .../lib/src/utils/hex.dart | 363 +++++++++++++ .../lib/src/utils/utils.dart | 2 + .../pubspec.yaml | 2 - .../bm_bluetooth_characteristic_test.dart | 2 +- .../test/types/bm_bluetooth_service_test.dart | 2 +- .../types/bm_characteristic_data_test.dart | 3 +- .../test/types/bm_descriptor_data_test.dart | 3 +- .../bm_discover_services_result_test.dart | 2 +- .../test/types/bm_msd_filter_test.dart | 3 +- .../types/bm_scan_advertisement_test.dart | 3 +- .../test/types/bm_scan_response_test.dart | 2 +- .../test/types/bm_scan_settings_test.dart | 2 +- .../types/bm_service_data_filter_test.dart | 3 +- .../bm_write_characteristic_request_test.dart | 3 +- .../bm_write_descriptor_request_test.dart | 3 +- 29 files changed, 895 insertions(+), 55 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/utils/equality.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/utils/hex.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/utils/utils.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart index ca244583..2bfcf66c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart @@ -1,9 +1,8 @@ -import 'package:collection/collection.dart'; - -import 'guid.dart'; +import '../utils/utils.dart'; import 'bm_bluetooth_descriptor.dart'; import 'bm_characteristic_properties.dart'; import 'device_identifier.dart'; +import 'guid.dart'; class BmBluetoothCharacteristic { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart index f527820d..f0102cfe 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; -import 'guid.dart'; import 'bm_bluetooth_characteristic.dart'; import 'device_identifier.dart'; +import 'guid.dart'; class BmBluetoothService { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart index f837cf35..076ccee1 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart @@ -1,6 +1,4 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; - +import '../utils/utils.dart'; import 'device_identifier.dart'; import 'guid.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart index ae9999db..0f7cae55 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart @@ -1,8 +1,6 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; - -import 'guid.dart'; +import '../utils/utils.dart'; import 'device_identifier.dart'; +import 'guid.dart'; class BmDescriptorData { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart index b82d5b43..30017f94 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart @@ -1,5 +1,4 @@ -import 'package:collection/collection.dart'; - +import '../utils/utils.dart'; import 'bm_bluetooth_service.dart'; import 'device_identifier.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart index 32135816..89424bdb 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart @@ -1,5 +1,4 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; +import '../utils/utils.dart'; class BmMsdFilter { int manufacturerId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart index 4c51b4d3..4d238e27 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart @@ -1,8 +1,6 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; - -import 'guid.dart'; +import '../utils/utils.dart'; import 'device_identifier.dart'; +import 'guid.dart'; class BmScanAdvertisement { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart index b0d86543..3a9170b2 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart @@ -1,5 +1,4 @@ -import 'package:collection/collection.dart'; - +import '../utils/utils.dart'; import 'bm_scan_advertisement.dart'; class BmScanResponse { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart index 978beed3..9b090c53 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart @@ -1,5 +1,4 @@ -import 'package:collection/collection.dart'; - +import '../utils/utils.dart'; import 'bm_msd_filter.dart'; import 'bm_service_data_filter.dart'; import 'guid.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart index 489bc570..afb665a5 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart @@ -1,6 +1,4 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; - +import '../utils/utils.dart'; import 'guid.dart'; class BmServiceDataFilter { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart index 35482049..1e034cdf 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart @@ -1,6 +1,4 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; - +import '../utils/utils.dart'; import 'bm_write_type.dart'; import 'device_identifier.dart'; import 'guid.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart index 6634b1de..5e4ff0ea 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart @@ -1,8 +1,6 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; - -import 'guid.dart'; +import '../utils/utils.dart'; import 'device_identifier.dart'; +import 'guid.dart'; class BmWriteDescriptorRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart index 4a244914..f18df9a2 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart @@ -1,4 +1,4 @@ -import 'package:convert/convert.dart'; +import '../utils/utils.dart'; class Guid { static const _suffix = '-0000-1000-8000-00805f9b34fb'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/utils/equality.dart b/packages/flutter_blue_plus_platform_interface/lib/src/utils/equality.dart new file mode 100644 index 00000000..2328d5f0 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/utils/equality.dart @@ -0,0 +1,501 @@ +// Copyright 2015, the Dart project authors. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google LLC nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// coverage:ignore-file + +import 'dart:collection'; + +const int _hashMask = 0x7fffffff; + +/// A generic equality relation on objects. +abstract class Equality { + const factory Equality() = DefaultEquality; + + /// Compare two elements for being equal. + /// + /// This should be a proper equality relation. + bool equals(E e1, E e2); + + /// Get a hashcode of an element. + /// + /// The hashcode should be compatible with [equals], so that if + /// `equals(a, b)` then `hash(a) == hash(b)`. + int hash(E e); + + /// Test whether an object is a valid argument to [equals] and [hash]. + /// + /// Some implementations may be restricted to only work on specific types + /// of objects. + bool isValidKey(Object? o); +} + +/// Equality of objects based on derived values. +/// +/// For example, given the class: +/// ```dart +/// abstract class Employee { +/// int get employmentId; +/// } +/// ``` +/// +/// The following [Equality] considers employees with the same IDs to be equal: +/// ```dart +/// EqualityBy((Employee e) => e.employmentId); +/// ``` +/// +/// It's also possible to pass an additional equality instance that should be +/// used to compare the value itself. +class EqualityBy implements Equality { + final F Function(E) _comparisonKey; + + final Equality _inner; + + EqualityBy(F Function(E) comparisonKey, + [Equality inner = const DefaultEquality()]) + : _comparisonKey = comparisonKey, + _inner = inner; + + @override + bool equals(E e1, E e2) => + _inner.equals(_comparisonKey(e1), _comparisonKey(e2)); + + @override + int hash(E e) => _inner.hash(_comparisonKey(e)); + + @override + bool isValidKey(Object? o) { + if (o is E) { + final value = _comparisonKey(o); + return _inner.isValidKey(value); + } + return false; + } +} + +/// Equality of objects that compares only the natural equality of the objects. +/// +/// This equality uses the objects' own [Object.==] and [Object.hashCode] for +/// the equality. +/// +/// Note that [equals] and [hash] take `Object`s rather than `E`s. This allows +/// `E` to be inferred as `Null` in const contexts where `E` wouldn't be a +/// compile-time constant, while still allowing the class to be used at runtime. +class DefaultEquality implements Equality { + const DefaultEquality(); + @override + bool equals(Object? e1, Object? e2) => e1 == e2; + @override + int hash(Object? e) => e.hashCode; + @override + bool isValidKey(Object? o) => true; +} + +/// Equality of objects that compares only the identity of the objects. +class IdentityEquality implements Equality { + const IdentityEquality(); + @override + bool equals(E e1, E e2) => identical(e1, e2); + @override + int hash(E e) => identityHashCode(e); + @override + bool isValidKey(Object? o) => true; +} + +/// Equality on iterables. +/// +/// Two iterables are equal if they have the same elements in the same order. +/// +/// The [equals] and [hash] methods accepts `null` values, +/// even if the [isValidKey] returns `false` for `null`. +/// The [hash] of `null` is `null.hashCode`. +class IterableEquality implements Equality> { + final Equality _elementEquality; + const IterableEquality( + [Equality elementEquality = const DefaultEquality()]) + : _elementEquality = elementEquality; + + @override + bool equals(Iterable? elements1, Iterable? elements2) { + if (identical(elements1, elements2)) return true; + if (elements1 == null || elements2 == null) return false; + var it1 = elements1.iterator; + var it2 = elements2.iterator; + while (true) { + var hasNext = it1.moveNext(); + if (hasNext != it2.moveNext()) return false; + if (!hasNext) return true; + if (!_elementEquality.equals(it1.current, it2.current)) return false; + } + } + + @override + int hash(Iterable? elements) { + if (elements == null) return null.hashCode; + // Jenkins's one-at-a-time hash function. + var hash = 0; + for (var element in elements) { + var c = _elementEquality.hash(element); + hash = (hash + c) & _hashMask; + hash = (hash + (hash << 10)) & _hashMask; + hash ^= hash >> 6; + } + hash = (hash + (hash << 3)) & _hashMask; + hash ^= hash >> 11; + hash = (hash + (hash << 15)) & _hashMask; + return hash; + } + + @override + bool isValidKey(Object? o) => o is Iterable; +} + +/// Equality on lists. +/// +/// Two lists are equal if they have the same length and their elements +/// at each index are equal. +/// +/// This is effectively the same as [IterableEquality] except that it +/// accesses elements by index instead of through iteration. +/// +/// The [equals] and [hash] methods accepts `null` values, +/// even if the [isValidKey] returns `false` for `null`. +/// The [hash] of `null` is `null.hashCode`. +class ListEquality implements Equality> { + final Equality _elementEquality; + const ListEquality( + [Equality elementEquality = const DefaultEquality()]) + : _elementEquality = elementEquality; + + @override + bool equals(List? list1, List? list2) { + if (identical(list1, list2)) return true; + if (list1 == null || list2 == null) return false; + var length = list1.length; + if (length != list2.length) return false; + for (var i = 0; i < length; i++) { + if (!_elementEquality.equals(list1[i], list2[i])) return false; + } + return true; + } + + @override + int hash(List? list) { + if (list == null) return null.hashCode; + // Jenkins's one-at-a-time hash function. + // This code is almost identical to the one in IterableEquality, except + // that it uses indexing instead of iterating to get the elements. + var hash = 0; + for (var i = 0; i < list.length; i++) { + var c = _elementEquality.hash(list[i]); + hash = (hash + c) & _hashMask; + hash = (hash + (hash << 10)) & _hashMask; + hash ^= hash >> 6; + } + hash = (hash + (hash << 3)) & _hashMask; + hash ^= hash >> 11; + hash = (hash + (hash << 15)) & _hashMask; + return hash; + } + + @override + bool isValidKey(Object? o) => o is List; +} + +abstract class _UnorderedEquality> + implements Equality { + final Equality _elementEquality; + + const _UnorderedEquality(this._elementEquality); + + @override + bool equals(T? elements1, T? elements2) { + if (identical(elements1, elements2)) return true; + if (elements1 == null || elements2 == null) return false; + var counts = HashMap( + equals: _elementEquality.equals, + hashCode: _elementEquality.hash, + isValidKey: _elementEquality.isValidKey); + var length = 0; + for (var e in elements1) { + var count = counts[e] ?? 0; + counts[e] = count + 1; + length++; + } + for (var e in elements2) { + var count = counts[e]; + if (count == null || count == 0) return false; + counts[e] = count - 1; + length--; + } + return length == 0; + } + + @override + int hash(T? elements) { + if (elements == null) return null.hashCode; + var hash = 0; + for (E element in elements) { + var c = _elementEquality.hash(element); + hash = (hash + c) & _hashMask; + } + hash = (hash + (hash << 3)) & _hashMask; + hash ^= hash >> 11; + hash = (hash + (hash << 15)) & _hashMask; + return hash; + } +} + +/// Equality of the elements of two iterables without considering order. +/// +/// Two iterables are considered equal if they have the same number of elements, +/// and the elements of one set can be paired with the elements +/// of the other iterable, so that each pair are equal. +class UnorderedIterableEquality extends _UnorderedEquality> { + const UnorderedIterableEquality( + [Equality elementEquality = const DefaultEquality()]) + : super(elementEquality); + + @override + bool isValidKey(Object? o) => o is Iterable; +} + +/// Equality of sets. +/// +/// Two sets are considered equal if they have the same number of elements, +/// and the elements of one set can be paired with the elements +/// of the other set, so that each pair are equal. +/// +/// This equality behaves the same as [UnorderedIterableEquality] except that +/// it expects sets instead of iterables as arguments. +/// +/// The [equals] and [hash] methods accepts `null` values, +/// even if the [isValidKey] returns `false` for `null`. +/// The [hash] of `null` is `null.hashCode`. +class SetEquality extends _UnorderedEquality> { + const SetEquality( + [Equality elementEquality = const DefaultEquality()]) + : super(elementEquality); + + @override + bool isValidKey(Object? o) => o is Set; +} + +/// Internal class used by [MapEquality]. +/// +/// The class represents a map entry as a single object, +/// using a combined hashCode and equality of the key and value. +class _MapEntry { + final MapEquality equality; + final Object? key; + final Object? value; + _MapEntry(this.equality, this.key, this.value); + + @override + int get hashCode => + (3 * equality._keyEquality.hash(key) + + 7 * equality._valueEquality.hash(value)) & + _hashMask; + + @override + bool operator ==(Object other) => + other is _MapEntry && + equality._keyEquality.equals(key, other.key) && + equality._valueEquality.equals(value, other.value); +} + +/// Equality on maps. +/// +/// Two maps are equal if they have the same number of entries, and if the +/// entries of the two maps are pairwise equal on both key and value. +/// +/// The [equals] and [hash] methods accepts `null` values, +/// even if the [isValidKey] returns `false` for `null`. +/// The [hash] of `null` is `null.hashCode`. +class MapEquality implements Equality> { + final Equality _keyEquality; + final Equality _valueEquality; + const MapEquality( + {Equality keys = const DefaultEquality(), + Equality values = const DefaultEquality()}) + : _keyEquality = keys, + _valueEquality = values; + + @override + bool equals(Map? map1, Map? map2) { + if (identical(map1, map2)) return true; + if (map1 == null || map2 == null) return false; + var length = map1.length; + if (length != map2.length) return false; + Map<_MapEntry, int> equalElementCounts = HashMap(); + for (var key in map1.keys) { + var entry = _MapEntry(this, key, map1[key]); + var count = equalElementCounts[entry] ?? 0; + equalElementCounts[entry] = count + 1; + } + for (var key in map2.keys) { + var entry = _MapEntry(this, key, map2[key]); + var count = equalElementCounts[entry]; + if (count == null || count == 0) return false; + equalElementCounts[entry] = count - 1; + } + return true; + } + + @override + int hash(Map? map) { + if (map == null) return null.hashCode; + var hash = 0; + for (var key in map.keys) { + var keyHash = _keyEquality.hash(key); + var valueHash = _valueEquality.hash(map[key] as V); + hash = (hash + 3 * keyHash + 7 * valueHash) & _hashMask; + } + hash = (hash + (hash << 3)) & _hashMask; + hash ^= hash >> 11; + hash = (hash + (hash << 15)) & _hashMask; + return hash; + } + + @override + bool isValidKey(Object? o) => o is Map; +} + +/// Combines several equalities into a single equality. +/// +/// Tries each equality in order, using [Equality.isValidKey], and returns +/// the result of the first equality that applies to the argument or arguments. +/// +/// For `equals`, the first equality that matches the first argument is used, +/// and if the second argument of `equals` is not valid for that equality, +/// it returns false. +/// +/// Because the equalities are tried in order, they should generally work on +/// disjoint types. Otherwise the multi-equality may give inconsistent results +/// for `equals(e1, e2)` and `equals(e2, e1)`. This can happen if one equality +/// considers only `e1` a valid key, and not `e2`, but an equality which is +/// checked later, allows both. +class MultiEquality implements Equality { + final Iterable> _equalities; + + const MultiEquality(Iterable> equalities) + : _equalities = equalities; + + @override + bool equals(E e1, E e2) { + for (var eq in _equalities) { + if (eq.isValidKey(e1)) return eq.isValidKey(e2) && eq.equals(e1, e2); + } + return false; + } + + @override + int hash(E e) { + for (var eq in _equalities) { + if (eq.isValidKey(e)) return eq.hash(e); + } + return 0; + } + + @override + bool isValidKey(Object? o) { + for (var eq in _equalities) { + if (eq.isValidKey(o)) return true; + } + return false; + } +} + +/// Deep equality on collections. +/// +/// Recognizes lists, sets, iterables and maps and compares their elements using +/// deep equality as well. +/// +/// Non-iterable/map objects are compared using a configurable base equality. +/// +/// Works in one of two modes: ordered or unordered. +/// +/// In ordered mode, lists and iterables are required to have equal elements +/// in the same order. In unordered mode, the order of elements in iterables +/// and lists are not important. +/// +/// A list is only equal to another list, likewise for sets and maps. All other +/// iterables are compared as iterables only. +class DeepCollectionEquality implements Equality { + final Equality _base; + final bool _unordered; + const DeepCollectionEquality([Equality base = const DefaultEquality()]) + : _base = base, + _unordered = false; + + /// Creates a deep equality on collections where the order of lists and + /// iterables are not considered important. That is, lists and iterables are + /// treated as unordered iterables. + const DeepCollectionEquality.unordered( + [Equality base = const DefaultEquality()]) + : _base = base, + _unordered = true; + + @override + bool equals(Object? e1, Object? e2) { + if (e1 is Set) { + return e2 is Set && SetEquality(this).equals(e1, e2); + } + if (e1 is Map) { + return e2 is Map && MapEquality(keys: this, values: this).equals(e1, e2); + } + if (!_unordered) { + if (e1 is List) { + return e2 is List && ListEquality(this).equals(e1, e2); + } + if (e1 is Iterable) { + return e2 is Iterable && IterableEquality(this).equals(e1, e2); + } + } else if (e1 is Iterable) { + if (e1 is List != e2 is List) return false; + return e2 is Iterable && UnorderedIterableEquality(this).equals(e1, e2); + } + return _base.equals(e1, e2); + } + + @override + int hash(Object? o) { + if (o is Set) return SetEquality(this).hash(o); + if (o is Map) return MapEquality(keys: this, values: this).hash(o); + if (!_unordered) { + if (o is List) return ListEquality(this).hash(o); + if (o is Iterable) return IterableEquality(this).hash(o); + } else if (o is Iterable) { + return UnorderedIterableEquality(this).hash(o); + } + return _base.hash(o); + } + + @override + bool isValidKey(Object? o) => + o is Iterable || o is Map || _base.isValidKey(o); +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/utils/hex.dart b/packages/flutter_blue_plus_platform_interface/lib/src/utils/hex.dart new file mode 100644 index 00000000..0db508f8 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/utils/hex.dart @@ -0,0 +1,363 @@ +// Copyright 2015, the Dart project authors. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google LLC nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// coverage:ignore-file + +import 'dart:convert'; +import 'dart:typed_data'; + +/// The canonical instance of [HexCodec]. +const hex = HexCodec._(); + +/// A codec that converts byte arrays to and from hexadecimal strings, following +/// [the Base16 spec](https://tools.ietf.org/html/rfc4648#section-8). +/// +/// This should be used via the [hex] field. +class HexCodec extends Codec, String> { + const HexCodec._(); + + @override + HexEncoder get encoder { + return const HexEncoder._(); + } + + @override + HexDecoder get decoder { + return const HexDecoder._(); + } +} + +/// A converter that encodes byte arrays into hexadecimal strings. +/// +/// This will throw a [RangeError] if the byte array has any digits that don't +/// fit in the gamut of a byte. +class HexEncoder extends Converter, String> { + const HexEncoder._(); + + @override + String convert(List input) { + return _convert(input, 0, input.length); + } + + @override + ByteConversionSink startChunkedConversion(Sink sink) { + return _HexEncoderSink(sink); + } +} + +/// A conversion sink for chunked hexadecimal encoding. +class _HexEncoderSink extends ByteConversionSinkBase { + /// The underlying sink to which decoded byte arrays will be passed. + final Sink _sink; + + _HexEncoderSink(this._sink); + + @override + void add(List chunk) { + _sink.add(_convert(chunk, 0, chunk.length)); + } + + @override + void addSlice(List chunk, int start, int end, bool isLast) { + RangeError.checkValidRange(start, end, chunk.length); + _sink.add(_convert(chunk, start, end)); + if (isLast) _sink.close(); + } + + @override + void close() { + _sink.close(); + } +} + +String _convert(List bytes, int start, int end) { + // A Uint8List is more efficient than a StringBuffer given that we know that + // we're only emitting ASCII-compatible characters, and that we know the + // length ahead of time. + var buffer = Uint8List((end - start) * 2); + var bufferIndex = 0; + + // A bitwise OR of all bytes in [bytes]. This allows us to check for + // out-of-range bytes without adding more branches than necessary to the + // core loop. + var byteOr = 0; + for (var i = start; i < end; i++) { + var byte = bytes[i]; + byteOr |= byte; + + // The bitwise arithmetic here is equivalent to `byte ~/ 16` and `byte % 16` + // for valid byte values, but is easier for dart2js to optimize given that + // it can't prove that [byte] will always be positive. + buffer[bufferIndex++] = _codeUnitForDigit((byte & 0xF0) >> 4); + buffer[bufferIndex++] = _codeUnitForDigit(byte & 0x0F); + } + + if (byteOr >= 0 && byteOr <= 255) return String.fromCharCodes(buffer); + + // If there was an invalid byte, find it and throw an exception. + for (var i = start; i < end; i++) { + var byte = bytes[i]; + if (byte >= 0 && byte <= 0xff) continue; + throw FormatException( + "Invalid byte ${byte < 0 ? "-" : ""}0x${byte.abs().toRadixString(16)}.", + bytes, + i, + ); + } + + throw StateError('unreachable'); +} + +/// Returns the ASCII/Unicode code unit corresponding to the hexadecimal digit +/// [digit]. +int _codeUnitForDigit(int digit) { + return digit < 10 ? digit + 0x30 : digit + 0x61 - 10; +} + +/// A converter that decodes hexadecimal strings into byte arrays. +/// +/// Because two hexadecimal digits correspond to a single byte, this will throw +/// a [FormatException] if given an odd-length string. It will also throw a +/// [FormatException] if given a string containing non-hexadecimal code units. +class HexDecoder extends Converter> { + const HexDecoder._(); + + @override + Uint8List convert(String input) { + if (!input.length.isEven) { + throw FormatException( + 'Invalid input length, must be even.', + input, + input.length, + ); + } + + var bytes = Uint8List(input.length ~/ 2); + _decode(input.codeUnits, 0, input.length, bytes, 0); + return bytes; + } + + @override + StringConversionSink startChunkedConversion(Sink> sink) { + return _HexDecoderSink(sink); + } +} + +/// A conversion sink for chunked hexadecimal decoding. +class _HexDecoderSink extends StringConversionSinkBase { + /// The underlying sink to which decoded byte arrays will be passed. + final Sink> _sink; + + /// The trailing digit from the previous string. + /// + /// This will be non-`null` if the most recent string had an odd number of + /// hexadecimal digits. Since it's the most significant digit, it's always a + /// multiple of 16. + int? _lastDigit; + + _HexDecoderSink(this._sink); + + @override + void addSlice(String string, int start, int end, bool isLast) { + RangeError.checkValidRange(start, end, string.length); + + if (start == end) { + if (isLast) _close(string, end); + return; + } + + var codeUnits = string.codeUnits; + Uint8List bytes; + int bytesStart; + if (_lastDigit == null) { + bytes = Uint8List((end - start) ~/ 2); + bytesStart = 0; + } else { + var hexPairs = (end - start - 1) ~/ 2; + bytes = Uint8List(1 + hexPairs); + bytes[0] = _lastDigit! + _digitForCodeUnit(codeUnits, start); + start++; + bytesStart = 1; + } + + _lastDigit = _decode(codeUnits, start, end, bytes, bytesStart); + + _sink.add(bytes); + if (isLast) _close(string, end); + } + + @override + ByteConversionSink asUtf8Sink(bool allowMalformed) { + return _HexDecoderByteSink(_sink); + } + + @override + void close() => _close(); + + /// Like [close], but includes [string] and [index] in the [FormatException] + /// if one is thrown. + void _close([String? string, int? index]) { + if (_lastDigit != null) { + throw FormatException( + 'Input ended with incomplete encoded byte.', + string, + index, + ); + } + + _sink.close(); + } +} + +/// A conversion sink for chunked hexadecimal decoding from UTF-8 bytes. +class _HexDecoderByteSink extends ByteConversionSinkBase { + /// The underlying sink to which decoded byte arrays will be passed. + final Sink> _sink; + + /// The trailing digit from the previous string. + /// + /// This will be non-`null` if the most recent string had an odd number of + /// hexadecimal digits. Since it's the most significant digit, it's always a + /// multiple of 16. + int? _lastDigit; + + _HexDecoderByteSink(this._sink); + + @override + void add(List chunk) { + addSlice(chunk, 0, chunk.length, false); + } + + @override + void addSlice(List chunk, int start, int end, bool isLast) { + RangeError.checkValidRange(start, end, chunk.length); + + if (start == end) { + if (isLast) _close(chunk, end); + return; + } + + Uint8List bytes; + int bytesStart; + if (_lastDigit == null) { + bytes = Uint8List((end - start) ~/ 2); + bytesStart = 0; + } else { + var hexPairs = (end - start - 1) ~/ 2; + bytes = Uint8List(1 + hexPairs); + bytes[0] = _lastDigit! + _digitForCodeUnit(chunk, start); + start++; + bytesStart = 1; + } + + _lastDigit = _decode(chunk, start, end, bytes, bytesStart); + + _sink.add(bytes); + if (isLast) _close(chunk, end); + } + + @override + void close() { + _close(); + } + + /// Like [close], but includes [chunk] and [index] in the [FormatException] + /// if one is thrown. + void _close([List? chunk, int? index]) { + if (_lastDigit != null) { + throw FormatException( + 'Input ended with incomplete encoded byte.', + chunk, + index, + ); + } + + _sink.close(); + } +} + +/// Decodes [codeUnits] and writes the result into [destination]. +/// +/// This reads from [codeUnits] between [sourceStart] and [sourceEnd]. It writes +/// the result into [destination] starting at [destinationStart]. +/// +/// If there's a leftover digit at the end of the decoding, this returns that +/// digit. Otherwise it returns `null`. +int? _decode( + List codeUnits, + int sourceStart, + int sourceEnd, + List destination, + int destinationStart, +) { + var destinationIndex = destinationStart; + for (var i = sourceStart; i < sourceEnd - 1; i += 2) { + var firstDigit = _digitForCodeUnit(codeUnits, i); + var secondDigit = _digitForCodeUnit(codeUnits, i + 1); + destination[destinationIndex++] = 16 * firstDigit + secondDigit; + } + + if ((sourceEnd - sourceStart).isEven) return null; + return 16 * _digitForCodeUnit(codeUnits, sourceEnd - 1); +} + +/// Returns the digit (0 through 15) corresponding to the hexadecimal code unit +/// at index [index] in [codeUnits]. +/// +/// If the given code unit isn't valid hexadecimal, throws a [FormatException]. +int _digitForCodeUnit( + List codeUnits, + int index, +) { + // If the code unit is a numeral, get its value. XOR works because 0 in ASCII + // is `0b110000` and the other numerals come after it in ascending order and + // take up at most four bits. + // + // We check for digits first because it ensures there's only a single branch + // for 10 out of 16 of the expected cases. We don't count the `digit >= 0` + // check because branch prediction will always work on it for valid data. + var codeUnit = codeUnits[index]; + var digit = 0x30 ^ codeUnit; + if (digit <= 9) { + if (digit >= 0) return digit; + } else { + // If the code unit is an uppercase letter, convert it to lowercase. This + // works because uppercase letters in ASCII are exactly `0b100000 = 0x20` + // less than lowercase letters, so if we ensure that that bit is 1 we ensure + // that the letter is lowercase. + var letter = 0x20 | codeUnit; + if (0x61 <= letter && letter <= 0x66) return letter - 0x61 + 10; + } + + throw FormatException( + 'Invalid hexadecimal code unit ' + "U+${codeUnit.toRadixString(16).padLeft(4, '0')}.", + codeUnits, + index, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/utils/utils.dart b/packages/flutter_blue_plus_platform_interface/lib/src/utils/utils.dart new file mode 100644 index 00000000..94a44200 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/utils/utils.dart @@ -0,0 +1,2 @@ +export 'equality.dart'; +export 'hex.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index ad5970e4..b2952616 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -8,8 +8,6 @@ environment: flutter: ">=2.0.0" dependencies: - collection: ^1.15.0 - convert: ^3.0.0 flutter: sdk: flutter plugin_platform_interface: ^2.0.0 diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart index 79197271..48f71e75 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart @@ -1,5 +1,5 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart index 7a3f4bef..98c18c2c 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart @@ -1,5 +1,5 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart index 57f793d5..5b07e287 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart @@ -1,6 +1,5 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart index f07a30eb..e7096be4 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart @@ -1,6 +1,5 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart index 42d7d8f3..d7df6914 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart @@ -1,5 +1,5 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart index 6dad4753..6c482e77 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart @@ -1,6 +1,5 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart index 4606f5bd..75200dd3 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart @@ -1,6 +1,5 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart index c3890127..34bc770e 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart @@ -1,5 +1,5 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart index 3132a207..c90dbcc3 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart @@ -1,5 +1,5 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart index fedcb704..1e241a8d 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart @@ -1,6 +1,5 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart index 4b5c169b..f4ef3688 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart @@ -1,6 +1,5 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart index 5ec1cf2c..4a2c8d79 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart @@ -1,6 +1,5 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { From c3c98633e025eb5f833e1a1e5bea1b3f9c359ac7 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Tue, 20 Aug 2024 11:28:32 +0100 Subject: [PATCH 41/90] build: remove plugin platform interface --- packages/flutter_blue_plus/pubspec.yaml | 4 ++-- packages/flutter_blue_plus_android/pubspec.yaml | 4 ++-- packages/flutter_blue_plus_darwin/pubspec.yaml | 4 ++-- .../method_channel/method_channel_flutter_blue_plus.dart | 2 +- .../platform_interface/flutter_blue_plus_platform.dart | 9 +-------- .../flutter_blue_plus_platform_interface/pubspec.yaml | 5 ++--- 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/flutter_blue_plus/pubspec.yaml b/packages/flutter_blue_plus/pubspec.yaml index 4758aa4c..33b81ed9 100644 --- a/packages/flutter_blue_plus/pubspec.yaml +++ b/packages/flutter_blue_plus/pubspec.yaml @@ -4,8 +4,8 @@ version: 1.33.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=2.0.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: flutter: diff --git a/packages/flutter_blue_plus_android/pubspec.yaml b/packages/flutter_blue_plus_android/pubspec.yaml index 761ec1a0..a054daaa 100644 --- a/packages/flutter_blue_plus_android/pubspec.yaml +++ b/packages/flutter_blue_plus_android/pubspec.yaml @@ -4,8 +4,8 @@ version: 1.33.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=2.0.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: flutter: diff --git a/packages/flutter_blue_plus_darwin/pubspec.yaml b/packages/flutter_blue_plus_darwin/pubspec.yaml index 3392cb0f..7435458e 100644 --- a/packages/flutter_blue_plus_darwin/pubspec.yaml +++ b/packages/flutter_blue_plus_darwin/pubspec.yaml @@ -4,8 +4,8 @@ version: 1.33.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=3.7.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: flutter: diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart index f30e1111..42f27e68 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart @@ -7,7 +7,7 @@ import '../platform_interface/flutter_blue_plus_platform.dart'; import '../types/types.dart'; /// An implementation of [FlutterBluePlusPlatform] that uses method channels. -class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { +final class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @visibleForTesting final channel = const MethodChannel('flutter_blue_plus/methods'); diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart index d99a4de9..7b5786ae 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart @@ -1,18 +1,12 @@ // coverage:ignore-file -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - import '../method_channel/method_channel_flutter_blue_plus.dart'; import '../types/types.dart'; /// The interface that implementations of flutter_blue_plus must implement. -abstract class FlutterBluePlusPlatform extends PlatformInterface { - static final _token = Object(); - +abstract base class FlutterBluePlusPlatform { static FlutterBluePlusPlatform _instance = MethodChannelFlutterBluePlus(); - FlutterBluePlusPlatform() : super(token: _token); - /// The default instance of [FlutterBluePlusPlatform] to use. /// /// Defaults to [MethodChannelFlutterBluePlus]. @@ -24,7 +18,6 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { static set instance( FlutterBluePlusPlatform instance, ) { - PlatformInterface.verify(instance, _token); _instance = instance; } diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index b2952616..ec5fe6e4 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -4,13 +4,12 @@ version: 1.0.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=2.0.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: flutter: sdk: flutter - plugin_platform_interface: ^2.0.0 dev_dependencies: flutter_lints: ^4.0.0 From b87e8002fd3c676f7b2575fad9fb81d9c7ed8157 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Tue, 20 Aug 2024 13:21:52 +0100 Subject: [PATCH 42/90] build: remove flutter lints and analysis options --- packages/flutter_blue_plus/analysis_options.yaml | 1 - packages/flutter_blue_plus/pubspec.yaml | 1 - packages/flutter_blue_plus_android/analysis_options.yaml | 1 - packages/flutter_blue_plus_android/pubspec.yaml | 1 - packages/flutter_blue_plus_darwin/analysis_options.yaml | 1 - packages/flutter_blue_plus_darwin/pubspec.yaml | 1 - .../flutter_blue_plus_platform_interface/analysis_options.yaml | 1 - packages/flutter_blue_plus_platform_interface/pubspec.yaml | 1 - 8 files changed, 8 deletions(-) delete mode 100644 packages/flutter_blue_plus/analysis_options.yaml delete mode 100644 packages/flutter_blue_plus_android/analysis_options.yaml delete mode 100644 packages/flutter_blue_plus_darwin/analysis_options.yaml delete mode 100644 packages/flutter_blue_plus_platform_interface/analysis_options.yaml diff --git a/packages/flutter_blue_plus/analysis_options.yaml b/packages/flutter_blue_plus/analysis_options.yaml deleted file mode 100644 index f9b30346..00000000 --- a/packages/flutter_blue_plus/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus/pubspec.yaml b/packages/flutter_blue_plus/pubspec.yaml index 33b81ed9..5fe78f10 100644 --- a/packages/flutter_blue_plus/pubspec.yaml +++ b/packages/flutter_blue_plus/pubspec.yaml @@ -15,7 +15,6 @@ dependencies: flutter_blue_plus_platform_interface: ^1.0.0 dev_dependencies: - flutter_lints: ^4.0.0 flutter_test: sdk: flutter diff --git a/packages/flutter_blue_plus_android/analysis_options.yaml b/packages/flutter_blue_plus_android/analysis_options.yaml deleted file mode 100644 index f9b30346..00000000 --- a/packages/flutter_blue_plus_android/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_android/pubspec.yaml b/packages/flutter_blue_plus_android/pubspec.yaml index a054daaa..f3cf56ed 100644 --- a/packages/flutter_blue_plus_android/pubspec.yaml +++ b/packages/flutter_blue_plus_android/pubspec.yaml @@ -13,7 +13,6 @@ dependencies: flutter_blue_plus_platform_interface: ^1.0.0 dev_dependencies: - flutter_lints: ^4.0.0 flutter_test: sdk: flutter diff --git a/packages/flutter_blue_plus_darwin/analysis_options.yaml b/packages/flutter_blue_plus_darwin/analysis_options.yaml deleted file mode 100644 index f9b30346..00000000 --- a/packages/flutter_blue_plus_darwin/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_darwin/pubspec.yaml b/packages/flutter_blue_plus_darwin/pubspec.yaml index 7435458e..366342b9 100644 --- a/packages/flutter_blue_plus_darwin/pubspec.yaml +++ b/packages/flutter_blue_plus_darwin/pubspec.yaml @@ -13,7 +13,6 @@ dependencies: flutter_blue_plus_platform_interface: ^1.0.0 dev_dependencies: - flutter_lints: ^4.0.0 flutter_test: sdk: flutter diff --git a/packages/flutter_blue_plus_platform_interface/analysis_options.yaml b/packages/flutter_blue_plus_platform_interface/analysis_options.yaml deleted file mode 100644 index f9b30346..00000000 --- a/packages/flutter_blue_plus_platform_interface/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index ec5fe6e4..053e17d8 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -12,6 +12,5 @@ dependencies: sdk: flutter dev_dependencies: - flutter_lints: ^4.0.0 flutter_test: sdk: flutter From 11c781f3f3ed99ab002d07b76589faac0c640b8b Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Tue, 20 Aug 2024 13:28:54 +0100 Subject: [PATCH 43/90] refactor: add single bluetooth_msgs file --- .../lib/src/types/bluetooth_msgs.dart | 1550 +++++++++++++++++ .../lib/src/types/bm_adapter_state_enum.dart | 9 - .../src/types/bm_bluetooth_adapter_state.dart | 34 - .../types/bm_bluetooth_characteristic.dart | 82 - .../src/types/bm_bluetooth_descriptor.dart | 50 - .../lib/src/types/bm_bluetooth_device.dart | 27 - .../lib/src/types/bm_bluetooth_service.dart | 70 - .../lib/src/types/bm_bond_state_enum.dart | 5 - .../lib/src/types/bm_bond_state_response.dart | 34 - .../lib/src/types/bm_characteristic_data.dart | 75 - .../types/bm_characteristic_properties.dart | 77 - .../lib/src/types/bm_connect_request.dart | 27 - .../types/bm_connection_priority_enum.dart | 5 - .../types/bm_connection_priority_request.dart | 29 - .../src/types/bm_connection_state_enum.dart | 4 - .../types/bm_connection_state_response.dart | 37 - .../lib/src/types/bm_descriptor_data.dart | 80 - .../lib/src/types/bm_devices_list.dart | 48 - .../types/bm_discover_services_result.dart | 62 - .../lib/src/types/bm_msd_filter.dart | 44 - .../lib/src/types/bm_mtu_change_request.dart | 27 - .../src/types/bm_mtu_changed_response.dart | 41 - .../lib/src/types/bm_name_changed.dart | 27 - .../lib/src/types/bm_preferred_phy.dart | 35 - .../types/bm_read_characteristic_request.dart | 52 - .../src/types/bm_read_descriptor_request.dart | 57 - .../lib/src/types/bm_read_rssi_result.dart | 41 - .../lib/src/types/bm_scan_advertisement.dart | 90 - .../lib/src/types/bm_scan_response.dart | 57 - .../lib/src/types/bm_scan_settings.dart | 100 -- .../lib/src/types/bm_service_data_filter.dart | 45 - .../types/bm_set_notify_value_request.dart | 62 - .../lib/src/types/bm_turn_on_response.dart | 32 - .../bm_write_characteristic_request.dart | 69 - .../types/bm_write_descriptor_request.dart | 63 - .../lib/src/types/bm_write_type.dart | 4 - .../lib/src/types/types.dart | 36 +- 37 files changed, 1551 insertions(+), 1636 deletions(-) create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bluetooth_msgs.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bluetooth_msgs.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bluetooth_msgs.dart new file mode 100644 index 00000000..48753ad3 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bluetooth_msgs.dart @@ -0,0 +1,1550 @@ +import 'dart:collection'; + +import '../utils/utils.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; + +enum BmAdapterStateEnum { + unknown, // 0 + unavailable, // 1 + unauthorized, // 2 + turningOn, // 3 + on, // 4 + turningOff, // 5 + off, // 6 +} + +class BmBluetoothAdapterState { + BmAdapterStateEnum adapterState; + + BmBluetoothAdapterState({ + required this.adapterState, + }); + + factory BmBluetoothAdapterState.fromMap( + Map json, + ) { + return BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.values[json['adapter_state'] as int], + ); + } + + @override + int get hashCode { + return adapterState.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothAdapterState && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'adapter_state': adapterState.index, + }; + } +} + +class BmBluetoothCharacteristic { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + List descriptors; + BmCharacteristicProperties properties; + + BmBluetoothCharacteristic({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptors, + required this.properties, + }); + + factory BmBluetoothCharacteristic.fromMap( + Map json, + ) { + return BmBluetoothCharacteristic( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptors: (json['descriptors'] as List?) + ?.map((descriptor) => BmBluetoothDescriptor.fromMap(descriptor)) + .toList() ?? + [], + properties: json['properties'] != null + ? BmCharacteristicProperties.fromMap(json['properties']) + : BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality().hash(descriptors) ^ + properties.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothCharacteristic && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptors': + descriptors.map((descriptor) => descriptor.toMap()).toList(), + 'properties': properties.toMap(), + }; + } +} + +class BmBluetoothDescriptor { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + + BmBluetoothDescriptor({ + required this.remoteId, + required this.serviceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + }); + + factory BmBluetoothDescriptor.fromMap( + Map json, + ) { + return BmBluetoothDescriptor( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothDescriptor && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + }; + } +} + +class BmBluetoothDevice { + DeviceIdentifier remoteId; + String? platformName; + + BmBluetoothDevice({ + required this.remoteId, + this.platformName, + }); + + factory BmBluetoothDevice.fromMap( + Map json, + ) { + return BmBluetoothDevice( + remoteId: DeviceIdentifier(json['remote_id']), + platformName: json['platform_name'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'platform_name': platformName, + }; + } +} + +class BmBluetoothService { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + bool isPrimary; + List characteristics; + List includedServices; + + BmBluetoothService({ + required this.remoteId, + required this.serviceUuid, + required this.isPrimary, + required this.characteristics, + required this.includedServices, + }); + + factory BmBluetoothService.fromMap( + Map json, + ) { + return BmBluetoothService( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + isPrimary: json['is_primary'] == 1, + characteristics: (json['characteristics'] as List?) + ?.map((characteristic) => + BmBluetoothCharacteristic.fromMap(characteristic)) + .toList() ?? + [], + includedServices: (json['included_services'] as List?) + ?.map((includedService) => + BmBluetoothService.fromMap(includedService)) + .toList() ?? + [], + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + isPrimary.hashCode ^ + const ListEquality().hash(characteristics) ^ + const ListEquality().hash(includedServices); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothService && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'is_primary': isPrimary ? 1 : 0, + 'characteristics': characteristics + .map((characteristic) => characteristic.toMap()) + .toList(), + 'included_services': includedServices + .map((includedService) => includedService.toMap()) + .toList(), + }; + } +} + +enum BmBondStateEnum { + none, // 0 + bonding, // 1 + bonded, // 2 +} + +class BmBondStateResponse { + final DeviceIdentifier remoteId; + final BmBondStateEnum bondState; + final BmBondStateEnum? prevState; + + BmBondStateResponse({ + required this.remoteId, + required this.bondState, + this.prevState, + }); + + factory BmBondStateResponse.fromMap( + Map json, + ) { + return BmBondStateResponse( + remoteId: DeviceIdentifier(json['remote_id']), + bondState: BmBondStateEnum.values[json['bond_state'] as int], + prevState: json['prev_state'] != null + ? BmBondStateEnum.values[json['prev_state'] as int] + : null, + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'bond_state': bondState.index, + 'prev_state': prevState?.index, + }; + } +} + +class BmCharacteristicData { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final List value; + final bool success; + final int errorCode; + final String errorString; + + BmCharacteristicData({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.value, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmCharacteristicData.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmCharacteristicData( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmCharacteristicData && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'value': hex.encode(value), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} + +class BmCharacteristicProperties { + bool broadcast; + bool read; + bool writeWithoutResponse; + bool write; + bool notify; + bool indicate; + bool authenticatedSignedWrites; + bool extendedProperties; + bool notifyEncryptionRequired; + bool indicateEncryptionRequired; + + BmCharacteristicProperties({ + required this.broadcast, + required this.read, + required this.writeWithoutResponse, + required this.write, + required this.notify, + required this.indicate, + required this.authenticatedSignedWrites, + required this.extendedProperties, + required this.notifyEncryptionRequired, + required this.indicateEncryptionRequired, + }); + + factory BmCharacteristicProperties.fromMap( + Map json, + ) { + return BmCharacteristicProperties( + broadcast: json['broadcast'] == 1, + read: json['read'] == 1, + writeWithoutResponse: json['write_without_response'] == 1, + write: json['write'] == 1, + notify: json['notify'] == 1, + indicate: json['indicate'] == 1, + authenticatedSignedWrites: json['authenticated_signed_writes'] == 1, + extendedProperties: json['extended_properties'] == 1, + notifyEncryptionRequired: json['notify_encryption_required'] == 1, + indicateEncryptionRequired: json['indicate_encryption_required'] == 1, + ); + } + + @override + int get hashCode { + return broadcast.hashCode ^ + read.hashCode ^ + writeWithoutResponse.hashCode ^ + write.hashCode ^ + notify.hashCode ^ + indicate.hashCode ^ + authenticatedSignedWrites.hashCode ^ + extendedProperties.hashCode ^ + notifyEncryptionRequired.hashCode ^ + indicateEncryptionRequired.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmCharacteristicProperties && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'broadcast': broadcast ? 1 : 0, + 'read': read ? 1 : 0, + 'write_without_response': writeWithoutResponse ? 1 : 0, + 'write': write ? 1 : 0, + 'notify': notify ? 1 : 0, + 'indicate': indicate ? 1 : 0, + 'authenticated_signed_writes': authenticatedSignedWrites ? 1 : 0, + 'extended_properties': extendedProperties ? 1 : 0, + 'notify_encryption_required': notifyEncryptionRequired ? 1 : 0, + 'indicate_encryption_required': indicateEncryptionRequired ? 1 : 0, + }; + } +} + +class BmConnectRequest { + DeviceIdentifier remoteId; + bool autoConnect; + + BmConnectRequest({ + required this.remoteId, + required this.autoConnect, + }); + + factory BmConnectRequest.fromMap( + Map json, + ) { + return BmConnectRequest( + remoteId: DeviceIdentifier(json['remote_id']), + autoConnect: json['auto_connect'] == 1, + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'auto_connect': autoConnect ? 1 : 0, + }; + } +} + +enum BmConnectionPriorityEnum { + balanced, // 0 + high, // 1 + lowPower, // 2 +} + +class BmConnectionPriorityRequest { + final DeviceIdentifier remoteId; + final BmConnectionPriorityEnum connectionPriority; + + BmConnectionPriorityRequest({ + required this.remoteId, + required this.connectionPriority, + }); + + factory BmConnectionPriorityRequest.fromMap( + Map json, + ) { + return BmConnectionPriorityRequest( + remoteId: DeviceIdentifier(json['remote_id']), + connectionPriority: + BmConnectionPriorityEnum.values[json['connection_priority'] as int], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'connection_priority': connectionPriority.index, + }; + } +} + +enum BmConnectionStateEnum { + disconnected, // 0 + connected, // 1 +} + +class BmConnectionStateResponse { + final DeviceIdentifier remoteId; + final BmConnectionStateEnum connectionState; + final int? disconnectReasonCode; + final String? disconnectReasonString; + + BmConnectionStateResponse({ + required this.remoteId, + required this.connectionState, + this.disconnectReasonCode, + this.disconnectReasonString, + }); + + factory BmConnectionStateResponse.fromMap( + Map json, + ) { + return BmConnectionStateResponse( + remoteId: DeviceIdentifier(json['remote_id']), + connectionState: + BmConnectionStateEnum.values[json['connection_state'] as int], + disconnectReasonCode: json['disconnect_reason_code'], + disconnectReasonString: json['disconnect_reason_string'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'connection_state': connectionState.index, + 'disconnectReasonCode': disconnectReasonCode, + 'disconnectReasonString': disconnectReasonString, + }; + } +} + +class BmDescriptorData { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + final List value; + final bool success; + final int errorCode; + final String errorString; + + BmDescriptorData({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + required this.value, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmDescriptorData.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmDescriptorData( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmDescriptorData && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + 'value': hex.encode(value), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} + +class BmDevicesList extends ListBase { + final List devices; + + BmDevicesList({ + required this.devices, + }); + + factory BmDevicesList.fromMap( + Map json, + ) { + return BmDevicesList( + devices: (json['devices'] as List?) + ?.map((device) => BmBluetoothDevice.fromMap(device)) + .toList() ?? + [], + ); + } + + Map toMap() { + return { + 'devices': devices.map((device) => device.toMap()).toList(), + }; + } + + @override + int get length { + return devices.length; + } + + @override + set length(int newLength) { + devices.length = newLength; + } + + @override + BmBluetoothDevice operator [](int index) { + return devices[index]; + } + + @override + void operator []=(int index, BmBluetoothDevice value) { + devices[index] = value; + } +} + +class BmDiscoverServicesResult { + final DeviceIdentifier remoteId; + final List services; + final bool success; + final int errorCode; + final String errorString; + + BmDiscoverServicesResult({ + required this.remoteId, + required this.services, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmDiscoverServicesResult.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmDiscoverServicesResult( + remoteId: DeviceIdentifier(json['remote_id']), + services: (json['services'] as List?) + ?.map((service) => + BmBluetoothService.fromMap(service as Map)) + .toList() ?? + [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + const ListEquality().hash(services) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmDiscoverServicesResult && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'services': services.map((service) => service.toMap()).toList(), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} + +class BmMsdFilter { + int manufacturerId; + List? data; + List? mask; + + BmMsdFilter( + this.manufacturerId, + this.data, + this.mask, + ); + + factory BmMsdFilter.fromMap( + Map json, + ) { + return BmMsdFilter( + json['manufacturer_id'], + json['data'] != null ? hex.decode(json['data']) : null, + json['mask'] != null ? hex.decode(json['mask']) : null, + ); + } + + @override + int get hashCode { + return manufacturerId.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmMsdFilter && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'manufacturer_id': manufacturerId, + 'data': data != null ? hex.encode(data!) : null, + 'mask': mask != null ? hex.encode(mask!) : null, + }; + } +} + +class BmMtuChangeRequest { + final DeviceIdentifier remoteId; + final int mtu; + + BmMtuChangeRequest({ + required this.remoteId, + required this.mtu, + }); + + factory BmMtuChangeRequest.fromMap( + Map json, + ) { + return BmMtuChangeRequest( + remoteId: DeviceIdentifier(json['remote_id']), + mtu: json['mtu'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'mtu': mtu, + }; + } +} + +class BmMtuChangedResponse { + final DeviceIdentifier remoteId; + final int mtu; + final bool success; + final int errorCode; + final String errorString; + + BmMtuChangedResponse({ + required this.remoteId, + required this.mtu, + this.success = true, + this.errorCode = 0, + this.errorString = '', + }); + + factory BmMtuChangedResponse.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmMtuChangedResponse( + remoteId: DeviceIdentifier(json['remote_id']), + mtu: json['mtu'], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'mtu': mtu, + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} + +class BmNameChanged { + DeviceIdentifier remoteId; + String name; + + BmNameChanged({ + required this.remoteId, + required this.name, + }); + + factory BmNameChanged.fromMap( + Map json, + ) { + return BmNameChanged( + remoteId: DeviceIdentifier(json['remote_id']), + name: json['name'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'name': name, + }; + } +} + +class BmPreferredPhy { + final DeviceIdentifier remoteId; + final int txPhy; + final int rxPhy; + final int phyOptions; + + BmPreferredPhy({ + required this.remoteId, + required this.txPhy, + required this.rxPhy, + required this.phyOptions, + }); + + factory BmPreferredPhy.fromMap( + Map json, + ) { + return BmPreferredPhy( + remoteId: DeviceIdentifier(json['remote_id']), + txPhy: json['tx_phy'], + rxPhy: json['rx_phy'], + phyOptions: json['phy_options'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'tx_phy': txPhy, + 'rx_phy': rxPhy, + 'phy_options': phyOptions, + }; + } +} + +class BmReadCharacteristicRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + + BmReadCharacteristicRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + }); + + factory BmReadCharacteristicRequest.fromMap( + Map json, + ) { + return BmReadCharacteristicRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmReadCharacteristicRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + }; + } +} + +class BmReadDescriptorRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + + BmReadDescriptorRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + }); + + factory BmReadDescriptorRequest.fromMap( + Map json, + ) { + return BmReadDescriptorRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmReadDescriptorRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + }; + } +} + +class BmReadRssiResult { + final DeviceIdentifier remoteId; + final int rssi; + final bool success; + final int errorCode; + final String errorString; + + BmReadRssiResult({ + required this.remoteId, + required this.rssi, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmReadRssiResult.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmReadRssiResult( + remoteId: DeviceIdentifier(json['remote_id']), + rssi: json['rssi'], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'rssi': rssi, + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} + +class BmScanAdvertisement { + final DeviceIdentifier remoteId; + final String? platformName; + final String? advName; + final bool connectable; + final int? txPowerLevel; + final int? appearance; // not supported on iOS / macOS + final Map> manufacturerData; + final Map> serviceData; + final List serviceUuids; + final int rssi; + + BmScanAdvertisement({ + required this.remoteId, + this.platformName, + this.advName, + required this.connectable, + this.txPowerLevel, + this.appearance, + required this.manufacturerData, + required this.serviceData, + required this.serviceUuids, + required this.rssi, + }); + + factory BmScanAdvertisement.fromMap( + Map json, + ) { + return BmScanAdvertisement( + remoteId: DeviceIdentifier(json['remote_id']), + platformName: json['platform_name'], + advName: json['adv_name'], + connectable: json['connectable'] == 1, + txPowerLevel: json['tx_power_level'], + appearance: json['appearance'], + manufacturerData: (json['manufacturer_data'] as Map?) + ?.map((key, value) => MapEntry(key, hex.decode(value))) ?? + {}, + serviceData: (json['service_data'] as Map?) + ?.map((key, value) => MapEntry(Guid(key), hex.decode(value))) ?? + {}, + serviceUuids: (json['service_uuids'] as List?) + ?.map((str) => Guid(str)) + .toList() ?? + [], + rssi: json['rssi'] ?? 0, + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + platformName.hashCode ^ + advName.hashCode ^ + connectable.hashCode ^ + txPowerLevel.hashCode ^ + appearance.hashCode ^ + const MapEquality>().hash(manufacturerData) ^ + const MapEquality>().hash(serviceData) ^ + const ListEquality().hash(serviceUuids) ^ + rssi.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanAdvertisement && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'platform_name': platformName, + 'adv_name': advName, + 'connectable': connectable ? 1 : 0, + 'tx_power_level': txPowerLevel, + 'appearance': appearance, + 'manufacturer_data': manufacturerData + .map((key, value) => MapEntry(key, hex.encode(value))), + 'service_data': + serviceData.map((key, value) => MapEntry(key.str, hex.encode(value))), + 'service_uuids': serviceUuids.map((uuid) => uuid.str).toList(), + 'rssi': rssi, + }; + } +} + +class BmScanResponse { + final List advertisements; + final bool success; + final int errorCode; + final String errorString; + + BmScanResponse({ + required this.advertisements, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmScanResponse.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmScanResponse( + advertisements: (json['advertisements'] as List?) + ?.map( + (advertisement) => BmScanAdvertisement.fromMap(advertisement)) + .toList() ?? + [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + @override + int get hashCode { + return const ListEquality().hash(advertisements) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanResponse && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'advertisements': + advertisements.map((advertisement) => advertisement.toMap()).toList(), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} + +class BmScanSettings { + final List withServices; + final List withRemoteIds; + final List withNames; + final List withKeywords; + final List withMsd; + final List withServiceData; + final bool continuousUpdates; + final int continuousDivisor; + final bool androidLegacy; + final int androidScanMode; + final bool androidUsesFineLocation; + + BmScanSettings({ + required this.withServices, + required this.withRemoteIds, + required this.withNames, + required this.withKeywords, + required this.withMsd, + required this.withServiceData, + required this.continuousUpdates, + required this.continuousDivisor, + required this.androidLegacy, + required this.androidScanMode, + required this.androidUsesFineLocation, + }); + + factory BmScanSettings.fromMap( + Map json, + ) { + return BmScanSettings( + withServices: (json['with_services'] as List?) + ?.map((str) => Guid(str)) + .toList() ?? + [], + withRemoteIds: + (json['with_remote_ids'] as List?)?.cast() ?? [], + withNames: (json['with_names'] as List?)?.cast() ?? [], + withKeywords: + (json['with_keywords'] as List?)?.cast() ?? [], + withMsd: (json['with_msd'] as List?) + ?.map((manufacturerData) => BmMsdFilter.fromMap(manufacturerData)) + .toList() ?? + [], + withServiceData: (json['with_service_data'] as List?) + ?.map((serviceData) => BmServiceDataFilter.fromMap(serviceData)) + .toList() ?? + [], + continuousUpdates: json['continuous_updates'], + continuousDivisor: json['continuous_divisor'], + androidLegacy: json['android_legacy'], + androidScanMode: json['android_scan_mode'], + androidUsesFineLocation: json['android_uses_fine_location'], + ); + } + + @override + int get hashCode { + return const ListEquality().hash(withServices) ^ + const ListEquality().hash(withRemoteIds) ^ + const ListEquality().hash(withNames) ^ + const ListEquality().hash(withKeywords) ^ + const ListEquality().hash(withMsd) ^ + const ListEquality().hash(withServiceData) ^ + continuousUpdates.hashCode ^ + continuousDivisor.hashCode ^ + androidLegacy.hashCode ^ + androidScanMode.hashCode ^ + androidUsesFineLocation.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanSettings && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'with_services': withServices.map((uuid) => uuid.str).toList(), + 'with_remote_ids': withRemoteIds, + 'with_names': withNames, + 'with_keywords': withKeywords, + 'with_msd': + withMsd.map((manufacturerData) => manufacturerData.toMap()).toList(), + 'with_service_data': + withServiceData.map((serviceData) => serviceData.toMap()).toList(), + 'continuous_updates': continuousUpdates, + 'continuous_divisor': continuousDivisor, + 'android_legacy': androidLegacy, + 'android_scan_mode': androidScanMode, + 'android_uses_fine_location': androidUsesFineLocation, + }; + } +} + +class BmServiceDataFilter { + Guid service; + List data; + List mask; + + BmServiceDataFilter( + this.service, + this.data, + this.mask, + ); + + factory BmServiceDataFilter.fromMap( + Map json, + ) { + return BmServiceDataFilter( + Guid(json['service']), + json['data'] != null ? hex.decode(json['data']) : [], + json['mask'] != null ? hex.decode(json['mask']) : [], + ); + } + + @override + int get hashCode { + return service.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmServiceDataFilter && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'service': service.str, + 'data': hex.encode(data), + 'mask': hex.encode(mask), + }; + } +} + +class BmSetNotifyValueRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final bool forceIndications; + final bool enable; + + BmSetNotifyValueRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.forceIndications, + required this.enable, + }); + + factory BmSetNotifyValueRequest.fromMap( + Map json, + ) { + return BmSetNotifyValueRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + forceIndications: json['force_indications'], + enable: json['enable'], + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + forceIndications.hashCode ^ + enable.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmSetNotifyValueRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'force_indications': forceIndications, + 'enable': enable, + }; + } +} + +class BmTurnOnResponse { + bool userAccepted; + + BmTurnOnResponse({ + required this.userAccepted, + }); + + factory BmTurnOnResponse.fromMap( + Map json, + ) { + return BmTurnOnResponse( + userAccepted: json['user_accepted'] ?? false, + ); + } + + @override + int get hashCode { + return userAccepted.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmTurnOnResponse && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'user_accepted': userAccepted, + }; + } +} + +class BmWriteCharacteristicRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final BmWriteType writeType; + final bool allowLongWrite; + final List value; + + BmWriteCharacteristicRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.writeType, + required this.allowLongWrite, + required this.value, + }); + + factory BmWriteCharacteristicRequest.fromMap( + Map json, + ) { + return BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + writeType: BmWriteType.values[json['write_type'] as int], + allowLongWrite: json['allow_long_write'] != 0, + value: json['value'] != null ? hex.decode(json['value']) : [], + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + writeType.hashCode ^ + allowLongWrite.hashCode ^ + const ListEquality().hash(value); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmWriteCharacteristicRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'write_type': writeType.index, + 'allow_long_write': allowLongWrite ? 1 : 0, + 'value': hex.encode(value), + }; + } +} + +class BmWriteDescriptorRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + final List value; + + BmWriteDescriptorRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + required this.value, + }); + + factory BmWriteDescriptorRequest.fromMap( + Map json, + ) { + return BmWriteDescriptorRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmWriteDescriptorRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + 'value': hex.encode(value), + }; + } +} + +enum BmWriteType { + withResponse, // 0 + withoutResponse, // 1 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart deleted file mode 100644 index 68ea06ab..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart +++ /dev/null @@ -1,9 +0,0 @@ -enum BmAdapterStateEnum { - unknown, // 0 - unavailable, // 1 - unauthorized, // 2 - turningOn, // 3 - on, // 4 - turningOff, // 5 - off, // 6 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart deleted file mode 100644 index f6dbbc8e..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'bm_adapter_state_enum.dart'; - -class BmBluetoothAdapterState { - BmAdapterStateEnum adapterState; - - BmBluetoothAdapterState({ - required this.adapterState, - }); - - factory BmBluetoothAdapterState.fromMap( - Map json, - ) { - return BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.values[json['adapter_state'] as int], - ); - } - - @override - int get hashCode { - return adapterState.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothAdapterState && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'adapter_state': adapterState.index, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart deleted file mode 100644 index 2bfcf66c..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart +++ /dev/null @@ -1,82 +0,0 @@ -import '../utils/utils.dart'; -import 'bm_bluetooth_descriptor.dart'; -import 'bm_characteristic_properties.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmBluetoothCharacteristic { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - List descriptors; - BmCharacteristicProperties properties; - - BmBluetoothCharacteristic({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptors, - required this.properties, - }); - - factory BmBluetoothCharacteristic.fromMap( - Map json, - ) { - return BmBluetoothCharacteristic( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptors: (json['descriptors'] as List?) - ?.map((descriptor) => BmBluetoothDescriptor.fromMap(descriptor)) - .toList() ?? - [], - properties: json['properties'] != null - ? BmCharacteristicProperties.fromMap(json['properties']) - : BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality().hash(descriptors) ^ - properties.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothCharacteristic && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptors': - descriptors.map((descriptor) => descriptor.toMap()).toList(), - 'properties': properties.toMap(), - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart deleted file mode 100644 index 9a0160ae..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart +++ /dev/null @@ -1,50 +0,0 @@ -import 'guid.dart'; -import 'device_identifier.dart'; - -class BmBluetoothDescriptor { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - - BmBluetoothDescriptor({ - required this.remoteId, - required this.serviceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - }); - - factory BmBluetoothDescriptor.fromMap( - Map json, - ) { - return BmBluetoothDescriptor( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothDescriptor && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart deleted file mode 100644 index 6a16229e..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'device_identifier.dart'; - -class BmBluetoothDevice { - DeviceIdentifier remoteId; - String? platformName; - - BmBluetoothDevice({ - required this.remoteId, - this.platformName, - }); - - factory BmBluetoothDevice.fromMap( - Map json, - ) { - return BmBluetoothDevice( - remoteId: DeviceIdentifier(json['remote_id']), - platformName: json['platform_name'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'platform_name': platformName, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart deleted file mode 100644 index f0102cfe..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart +++ /dev/null @@ -1,70 +0,0 @@ -import 'package:collection/collection.dart'; - -import 'bm_bluetooth_characteristic.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmBluetoothService { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - bool isPrimary; - List characteristics; - List includedServices; - - BmBluetoothService({ - required this.remoteId, - required this.serviceUuid, - required this.isPrimary, - required this.characteristics, - required this.includedServices, - }); - - factory BmBluetoothService.fromMap( - Map json, - ) { - return BmBluetoothService( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - isPrimary: json['is_primary'] == 1, - characteristics: (json['characteristics'] as List?) - ?.map((characteristic) => - BmBluetoothCharacteristic.fromMap(characteristic)) - .toList() ?? - [], - includedServices: (json['included_services'] as List?) - ?.map((includedService) => - BmBluetoothService.fromMap(includedService)) - .toList() ?? - [], - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - isPrimary.hashCode ^ - const ListEquality().hash(characteristics) ^ - const ListEquality().hash(includedServices); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothService && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'is_primary': isPrimary ? 1 : 0, - 'characteristics': characteristics - .map((characteristic) => characteristic.toMap()) - .toList(), - 'included_services': includedServices - .map((includedService) => includedService.toMap()) - .toList(), - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart deleted file mode 100644 index 4e9756b1..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart +++ /dev/null @@ -1,5 +0,0 @@ -enum BmBondStateEnum { - none, // 0 - bonding, // 1 - bonded, // 2 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart deleted file mode 100644 index bacb627e..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'bm_bond_state_enum.dart'; -import 'device_identifier.dart'; - -class BmBondStateResponse { - final DeviceIdentifier remoteId; - final BmBondStateEnum bondState; - final BmBondStateEnum? prevState; - - BmBondStateResponse({ - required this.remoteId, - required this.bondState, - this.prevState, - }); - - factory BmBondStateResponse.fromMap( - Map json, - ) { - return BmBondStateResponse( - remoteId: DeviceIdentifier(json['remote_id']), - bondState: BmBondStateEnum.values[json['bond_state'] as int], - prevState: json['prev_state'] != null - ? BmBondStateEnum.values[json['prev_state'] as int] - : null, - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'bond_state': bondState.index, - 'prev_state': prevState?.index, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart deleted file mode 100644 index 076ccee1..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart +++ /dev/null @@ -1,75 +0,0 @@ -import '../utils/utils.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmCharacteristicData { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final List value; - final bool success; - final int errorCode; - final String errorString; - - BmCharacteristicData({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.value, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmCharacteristicData.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmCharacteristicData( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmCharacteristicData && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'value': hex.encode(value), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart deleted file mode 100644 index 30745221..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart +++ /dev/null @@ -1,77 +0,0 @@ -class BmCharacteristicProperties { - bool broadcast; - bool read; - bool writeWithoutResponse; - bool write; - bool notify; - bool indicate; - bool authenticatedSignedWrites; - bool extendedProperties; - bool notifyEncryptionRequired; - bool indicateEncryptionRequired; - - BmCharacteristicProperties({ - required this.broadcast, - required this.read, - required this.writeWithoutResponse, - required this.write, - required this.notify, - required this.indicate, - required this.authenticatedSignedWrites, - required this.extendedProperties, - required this.notifyEncryptionRequired, - required this.indicateEncryptionRequired, - }); - - factory BmCharacteristicProperties.fromMap( - Map json, - ) { - return BmCharacteristicProperties( - broadcast: json['broadcast'] == 1, - read: json['read'] == 1, - writeWithoutResponse: json['write_without_response'] == 1, - write: json['write'] == 1, - notify: json['notify'] == 1, - indicate: json['indicate'] == 1, - authenticatedSignedWrites: json['authenticated_signed_writes'] == 1, - extendedProperties: json['extended_properties'] == 1, - notifyEncryptionRequired: json['notify_encryption_required'] == 1, - indicateEncryptionRequired: json['indicate_encryption_required'] == 1, - ); - } - - @override - int get hashCode { - return broadcast.hashCode ^ - read.hashCode ^ - writeWithoutResponse.hashCode ^ - write.hashCode ^ - notify.hashCode ^ - indicate.hashCode ^ - authenticatedSignedWrites.hashCode ^ - extendedProperties.hashCode ^ - notifyEncryptionRequired.hashCode ^ - indicateEncryptionRequired.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmCharacteristicProperties && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'broadcast': broadcast ? 1 : 0, - 'read': read ? 1 : 0, - 'write_without_response': writeWithoutResponse ? 1 : 0, - 'write': write ? 1 : 0, - 'notify': notify ? 1 : 0, - 'indicate': indicate ? 1 : 0, - 'authenticated_signed_writes': authenticatedSignedWrites ? 1 : 0, - 'extended_properties': extendedProperties ? 1 : 0, - 'notify_encryption_required': notifyEncryptionRequired ? 1 : 0, - 'indicate_encryption_required': indicateEncryptionRequired ? 1 : 0, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart deleted file mode 100644 index b56394c8..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'device_identifier.dart'; - -class BmConnectRequest { - DeviceIdentifier remoteId; - bool autoConnect; - - BmConnectRequest({ - required this.remoteId, - required this.autoConnect, - }); - - factory BmConnectRequest.fromMap( - Map json, - ) { - return BmConnectRequest( - remoteId: DeviceIdentifier(json['remote_id']), - autoConnect: json['auto_connect'] == 1, - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'auto_connect': autoConnect ? 1 : 0, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart deleted file mode 100644 index e205abcb..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart +++ /dev/null @@ -1,5 +0,0 @@ -enum BmConnectionPriorityEnum { - balanced, // 0 - high, // 1 - lowPower, // 2 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart deleted file mode 100644 index 118080c1..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'bm_connection_priority_enum.dart'; -import 'device_identifier.dart'; - -class BmConnectionPriorityRequest { - final DeviceIdentifier remoteId; - final BmConnectionPriorityEnum connectionPriority; - - BmConnectionPriorityRequest({ - required this.remoteId, - required this.connectionPriority, - }); - - factory BmConnectionPriorityRequest.fromMap( - Map json, - ) { - return BmConnectionPriorityRequest( - remoteId: DeviceIdentifier(json['remote_id']), - connectionPriority: - BmConnectionPriorityEnum.values[json['connection_priority'] as int], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'connection_priority': connectionPriority.index, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart deleted file mode 100644 index e254b9e9..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart +++ /dev/null @@ -1,4 +0,0 @@ -enum BmConnectionStateEnum { - disconnected, // 0 - connected, // 1 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart deleted file mode 100644 index 43553e89..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'bm_connection_state_enum.dart'; -import 'device_identifier.dart'; - -class BmConnectionStateResponse { - final DeviceIdentifier remoteId; - final BmConnectionStateEnum connectionState; - final int? disconnectReasonCode; - final String? disconnectReasonString; - - BmConnectionStateResponse({ - required this.remoteId, - required this.connectionState, - this.disconnectReasonCode, - this.disconnectReasonString, - }); - - factory BmConnectionStateResponse.fromMap( - Map json, - ) { - return BmConnectionStateResponse( - remoteId: DeviceIdentifier(json['remote_id']), - connectionState: - BmConnectionStateEnum.values[json['connection_state'] as int], - disconnectReasonCode: json['disconnect_reason_code'], - disconnectReasonString: json['disconnect_reason_string'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'connection_state': connectionState.index, - 'disconnectReasonCode': disconnectReasonCode, - 'disconnectReasonString': disconnectReasonString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart deleted file mode 100644 index 0f7cae55..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart +++ /dev/null @@ -1,80 +0,0 @@ -import '../utils/utils.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmDescriptorData { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - final List value; - final bool success; - final int errorCode; - final String errorString; - - BmDescriptorData({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - required this.value, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmDescriptorData.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmDescriptorData( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmDescriptorData && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - 'value': hex.encode(value), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart deleted file mode 100644 index 4fa7460e..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'dart:collection'; - -import 'bm_bluetooth_device.dart'; - -class BmDevicesList extends ListBase { - final List devices; - - BmDevicesList({ - required this.devices, - }); - - factory BmDevicesList.fromMap( - Map json, - ) { - return BmDevicesList( - devices: (json['devices'] as List?) - ?.map((device) => BmBluetoothDevice.fromMap(device)) - .toList() ?? - [], - ); - } - - Map toMap() { - return { - 'devices': devices.map((device) => device.toMap()).toList(), - }; - } - - @override - int get length { - return devices.length; - } - - @override - set length(int newLength) { - devices.length = newLength; - } - - @override - BmBluetoothDevice operator [](int index) { - return devices[index]; - } - - @override - void operator []=(int index, BmBluetoothDevice value) { - devices[index] = value; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart deleted file mode 100644 index 30017f94..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart +++ /dev/null @@ -1,62 +0,0 @@ -import '../utils/utils.dart'; -import 'bm_bluetooth_service.dart'; -import 'device_identifier.dart'; - -class BmDiscoverServicesResult { - final DeviceIdentifier remoteId; - final List services; - final bool success; - final int errorCode; - final String errorString; - - BmDiscoverServicesResult({ - required this.remoteId, - required this.services, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmDiscoverServicesResult.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmDiscoverServicesResult( - remoteId: DeviceIdentifier(json['remote_id']), - services: (json['services'] as List?) - ?.map((service) => - BmBluetoothService.fromMap(service as Map)) - .toList() ?? - [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - const ListEquality().hash(services) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmDiscoverServicesResult && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'services': services.map((service) => service.toMap()).toList(), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart deleted file mode 100644 index 89424bdb..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart +++ /dev/null @@ -1,44 +0,0 @@ -import '../utils/utils.dart'; - -class BmMsdFilter { - int manufacturerId; - List? data; - List? mask; - - BmMsdFilter( - this.manufacturerId, - this.data, - this.mask, - ); - - factory BmMsdFilter.fromMap( - Map json, - ) { - return BmMsdFilter( - json['manufacturer_id'], - json['data'] != null ? hex.decode(json['data']) : null, - json['mask'] != null ? hex.decode(json['mask']) : null, - ); - } - - @override - int get hashCode { - return manufacturerId.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmMsdFilter && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'manufacturer_id': manufacturerId, - 'data': data != null ? hex.encode(data!) : null, - 'mask': mask != null ? hex.encode(mask!) : null, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart deleted file mode 100644 index 4c03df5f..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'device_identifier.dart'; - -class BmMtuChangeRequest { - final DeviceIdentifier remoteId; - final int mtu; - - BmMtuChangeRequest({ - required this.remoteId, - required this.mtu, - }); - - factory BmMtuChangeRequest.fromMap( - Map json, - ) { - return BmMtuChangeRequest( - remoteId: DeviceIdentifier(json['remote_id']), - mtu: json['mtu'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'mtu': mtu, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart deleted file mode 100644 index 2ffbc90b..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'device_identifier.dart'; - -class BmMtuChangedResponse { - final DeviceIdentifier remoteId; - final int mtu; - final bool success; - final int errorCode; - final String errorString; - - BmMtuChangedResponse({ - required this.remoteId, - required this.mtu, - this.success = true, - this.errorCode = 0, - this.errorString = '', - }); - - factory BmMtuChangedResponse.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmMtuChangedResponse( - remoteId: DeviceIdentifier(json['remote_id']), - mtu: json['mtu'], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'mtu': mtu, - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart deleted file mode 100644 index 54597f3d..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'device_identifier.dart'; - -class BmNameChanged { - DeviceIdentifier remoteId; - String name; - - BmNameChanged({ - required this.remoteId, - required this.name, - }); - - factory BmNameChanged.fromMap( - Map json, - ) { - return BmNameChanged( - remoteId: DeviceIdentifier(json['remote_id']), - name: json['name'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'name': name, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart deleted file mode 100644 index b8accc11..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'device_identifier.dart'; - -class BmPreferredPhy { - final DeviceIdentifier remoteId; - final int txPhy; - final int rxPhy; - final int phyOptions; - - BmPreferredPhy({ - required this.remoteId, - required this.txPhy, - required this.rxPhy, - required this.phyOptions, - }); - - factory BmPreferredPhy.fromMap( - Map json, - ) { - return BmPreferredPhy( - remoteId: DeviceIdentifier(json['remote_id']), - txPhy: json['tx_phy'], - rxPhy: json['rx_phy'], - phyOptions: json['phy_options'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'tx_phy': txPhy, - 'rx_phy': rxPhy, - 'phy_options': phyOptions, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart deleted file mode 100644 index 9c706891..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmReadCharacteristicRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - - BmReadCharacteristicRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - }); - - factory BmReadCharacteristicRequest.fromMap( - Map json, - ) { - return BmReadCharacteristicRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmReadCharacteristicRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart deleted file mode 100644 index dec81238..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'guid.dart'; -import 'device_identifier.dart'; - -class BmReadDescriptorRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - - BmReadDescriptorRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - }); - - factory BmReadDescriptorRequest.fromMap( - Map json, - ) { - return BmReadDescriptorRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmReadDescriptorRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart deleted file mode 100644 index b2436d63..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'device_identifier.dart'; - -class BmReadRssiResult { - final DeviceIdentifier remoteId; - final int rssi; - final bool success; - final int errorCode; - final String errorString; - - BmReadRssiResult({ - required this.remoteId, - required this.rssi, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmReadRssiResult.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmReadRssiResult( - remoteId: DeviceIdentifier(json['remote_id']), - rssi: json['rssi'], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'rssi': rssi, - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart deleted file mode 100644 index 4d238e27..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart +++ /dev/null @@ -1,90 +0,0 @@ -import '../utils/utils.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmScanAdvertisement { - final DeviceIdentifier remoteId; - final String? platformName; - final String? advName; - final bool connectable; - final int? txPowerLevel; - final int? appearance; // not supported on iOS / macOS - final Map> manufacturerData; - final Map> serviceData; - final List serviceUuids; - final int rssi; - - BmScanAdvertisement({ - required this.remoteId, - this.platformName, - this.advName, - required this.connectable, - this.txPowerLevel, - this.appearance, - required this.manufacturerData, - required this.serviceData, - required this.serviceUuids, - required this.rssi, - }); - - factory BmScanAdvertisement.fromMap( - Map json, - ) { - return BmScanAdvertisement( - remoteId: DeviceIdentifier(json['remote_id']), - platformName: json['platform_name'], - advName: json['adv_name'], - connectable: json['connectable'] == 1, - txPowerLevel: json['tx_power_level'], - appearance: json['appearance'], - manufacturerData: (json['manufacturer_data'] as Map?) - ?.map((key, value) => MapEntry(key, hex.decode(value))) ?? - {}, - serviceData: (json['service_data'] as Map?) - ?.map((key, value) => MapEntry(Guid(key), hex.decode(value))) ?? - {}, - serviceUuids: (json['service_uuids'] as List?) - ?.map((str) => Guid(str)) - .toList() ?? - [], - rssi: json['rssi'] ?? 0, - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - platformName.hashCode ^ - advName.hashCode ^ - connectable.hashCode ^ - txPowerLevel.hashCode ^ - appearance.hashCode ^ - const MapEquality>().hash(manufacturerData) ^ - const MapEquality>().hash(serviceData) ^ - const ListEquality().hash(serviceUuids) ^ - rssi.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanAdvertisement && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'platform_name': platformName, - 'adv_name': advName, - 'connectable': connectable ? 1 : 0, - 'tx_power_level': txPowerLevel, - 'appearance': appearance, - 'manufacturer_data': manufacturerData - .map((key, value) => MapEntry(key, hex.encode(value))), - 'service_data': - serviceData.map((key, value) => MapEntry(key.str, hex.encode(value))), - 'service_uuids': serviceUuids.map((uuid) => uuid.str).toList(), - 'rssi': rssi, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart deleted file mode 100644 index 3a9170b2..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart +++ /dev/null @@ -1,57 +0,0 @@ -import '../utils/utils.dart'; -import 'bm_scan_advertisement.dart'; - -class BmScanResponse { - final List advertisements; - final bool success; - final int errorCode; - final String errorString; - - BmScanResponse({ - required this.advertisements, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmScanResponse.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmScanResponse( - advertisements: (json['advertisements'] as List?) - ?.map( - (advertisement) => BmScanAdvertisement.fromMap(advertisement)) - .toList() ?? - [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - @override - int get hashCode { - return const ListEquality().hash(advertisements) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanResponse && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'advertisements': - advertisements.map((advertisement) => advertisement.toMap()).toList(), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart deleted file mode 100644 index 9b090c53..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart +++ /dev/null @@ -1,100 +0,0 @@ -import '../utils/utils.dart'; -import 'bm_msd_filter.dart'; -import 'bm_service_data_filter.dart'; -import 'guid.dart'; - -class BmScanSettings { - final List withServices; - final List withRemoteIds; - final List withNames; - final List withKeywords; - final List withMsd; - final List withServiceData; - final bool continuousUpdates; - final int continuousDivisor; - final bool androidLegacy; - final int androidScanMode; - final bool androidUsesFineLocation; - - BmScanSettings({ - required this.withServices, - required this.withRemoteIds, - required this.withNames, - required this.withKeywords, - required this.withMsd, - required this.withServiceData, - required this.continuousUpdates, - required this.continuousDivisor, - required this.androidLegacy, - required this.androidScanMode, - required this.androidUsesFineLocation, - }); - - factory BmScanSettings.fromMap( - Map json, - ) { - return BmScanSettings( - withServices: (json['with_services'] as List?) - ?.map((str) => Guid(str)) - .toList() ?? - [], - withRemoteIds: - (json['with_remote_ids'] as List?)?.cast() ?? [], - withNames: (json['with_names'] as List?)?.cast() ?? [], - withKeywords: - (json['with_keywords'] as List?)?.cast() ?? [], - withMsd: (json['with_msd'] as List?) - ?.map((manufacturerData) => BmMsdFilter.fromMap(manufacturerData)) - .toList() ?? - [], - withServiceData: (json['with_service_data'] as List?) - ?.map((serviceData) => BmServiceDataFilter.fromMap(serviceData)) - .toList() ?? - [], - continuousUpdates: json['continuous_updates'], - continuousDivisor: json['continuous_divisor'], - androidLegacy: json['android_legacy'], - androidScanMode: json['android_scan_mode'], - androidUsesFineLocation: json['android_uses_fine_location'], - ); - } - - @override - int get hashCode { - return const ListEquality().hash(withServices) ^ - const ListEquality().hash(withRemoteIds) ^ - const ListEquality().hash(withNames) ^ - const ListEquality().hash(withKeywords) ^ - const ListEquality().hash(withMsd) ^ - const ListEquality().hash(withServiceData) ^ - continuousUpdates.hashCode ^ - continuousDivisor.hashCode ^ - androidLegacy.hashCode ^ - androidScanMode.hashCode ^ - androidUsesFineLocation.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanSettings && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'with_services': withServices.map((uuid) => uuid.str).toList(), - 'with_remote_ids': withRemoteIds, - 'with_names': withNames, - 'with_keywords': withKeywords, - 'with_msd': - withMsd.map((manufacturerData) => manufacturerData.toMap()).toList(), - 'with_service_data': - withServiceData.map((serviceData) => serviceData.toMap()).toList(), - 'continuous_updates': continuousUpdates, - 'continuous_divisor': continuousDivisor, - 'android_legacy': androidLegacy, - 'android_scan_mode': androidScanMode, - 'android_uses_fine_location': androidUsesFineLocation, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart deleted file mode 100644 index afb665a5..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart +++ /dev/null @@ -1,45 +0,0 @@ -import '../utils/utils.dart'; -import 'guid.dart'; - -class BmServiceDataFilter { - Guid service; - List data; - List mask; - - BmServiceDataFilter( - this.service, - this.data, - this.mask, - ); - - factory BmServiceDataFilter.fromMap( - Map json, - ) { - return BmServiceDataFilter( - Guid(json['service']), - json['data'] != null ? hex.decode(json['data']) : [], - json['mask'] != null ? hex.decode(json['mask']) : [], - ); - } - - @override - int get hashCode { - return service.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmServiceDataFilter && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'service': service.str, - 'data': hex.encode(data), - 'mask': hex.encode(mask), - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart deleted file mode 100644 index 9d831817..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmSetNotifyValueRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final bool forceIndications; - final bool enable; - - BmSetNotifyValueRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.forceIndications, - required this.enable, - }); - - factory BmSetNotifyValueRequest.fromMap( - Map json, - ) { - return BmSetNotifyValueRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - forceIndications: json['force_indications'], - enable: json['enable'], - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - forceIndications.hashCode ^ - enable.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmSetNotifyValueRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'force_indications': forceIndications, - 'enable': enable, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart deleted file mode 100644 index 8719a1b6..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart +++ /dev/null @@ -1,32 +0,0 @@ -class BmTurnOnResponse { - bool userAccepted; - - BmTurnOnResponse({ - required this.userAccepted, - }); - - factory BmTurnOnResponse.fromMap( - Map json, - ) { - return BmTurnOnResponse( - userAccepted: json['user_accepted'] ?? false, - ); - } - - @override - int get hashCode { - return userAccepted.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmTurnOnResponse && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'user_accepted': userAccepted, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart deleted file mode 100644 index 1e034cdf..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart +++ /dev/null @@ -1,69 +0,0 @@ -import '../utils/utils.dart'; -import 'bm_write_type.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmWriteCharacteristicRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final BmWriteType writeType; - final bool allowLongWrite; - final List value; - - BmWriteCharacteristicRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.writeType, - required this.allowLongWrite, - required this.value, - }); - - factory BmWriteCharacteristicRequest.fromMap( - Map json, - ) { - return BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - writeType: BmWriteType.values[json['write_type'] as int], - allowLongWrite: json['allow_long_write'] != 0, - value: json['value'] != null ? hex.decode(json['value']) : [], - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - writeType.hashCode ^ - allowLongWrite.hashCode ^ - const ListEquality().hash(value); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmWriteCharacteristicRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'write_type': writeType.index, - 'allow_long_write': allowLongWrite ? 1 : 0, - 'value': hex.encode(value), - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart deleted file mode 100644 index 5e4ff0ea..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart +++ /dev/null @@ -1,63 +0,0 @@ -import '../utils/utils.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; - -class BmWriteDescriptorRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - final List value; - - BmWriteDescriptorRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - required this.value, - }); - - factory BmWriteDescriptorRequest.fromMap( - Map json, - ) { - return BmWriteDescriptorRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmWriteDescriptorRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - 'value': hex.encode(value), - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart deleted file mode 100644 index 2ffb5318..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart +++ /dev/null @@ -1,4 +0,0 @@ -enum BmWriteType { - withResponse, // 0 - withoutResponse, // 1 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart index 7c3913d1..5840a539 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart @@ -1,38 +1,4 @@ -export 'bm_adapter_state_enum.dart'; -export 'bm_bluetooth_adapter_state.dart'; -export 'bm_bluetooth_characteristic.dart'; -export 'bm_bluetooth_descriptor.dart'; -export 'bm_bluetooth_device.dart'; -export 'bm_bluetooth_service.dart'; -export 'bm_bond_state_enum.dart'; -export 'bm_bond_state_response.dart'; -export 'bm_characteristic_data.dart'; -export 'bm_characteristic_properties.dart'; -export 'bm_connect_request.dart'; -export 'bm_connection_priority_enum.dart'; -export 'bm_connection_priority_request.dart'; -export 'bm_connection_state_enum.dart'; -export 'bm_connection_state_response.dart'; -export 'bm_descriptor_data.dart'; -export 'bm_devices_list.dart'; -export 'bm_discover_services_result.dart'; -export 'bm_msd_filter.dart'; -export 'bm_mtu_change_request.dart'; -export 'bm_mtu_changed_response.dart'; -export 'bm_name_changed.dart'; -export 'bm_preferred_phy.dart'; -export 'bm_read_characteristic_request.dart'; -export 'bm_read_descriptor_request.dart'; -export 'bm_read_rssi_result.dart'; -export 'bm_scan_advertisement.dart'; -export 'bm_scan_response.dart'; -export 'bm_scan_settings.dart'; -export 'bm_service_data_filter.dart'; -export 'bm_set_notify_value_request.dart'; -export 'bm_turn_on_response.dart'; -export 'bm_write_characteristic_request.dart'; -export 'bm_write_descriptor_request.dart'; -export 'bm_write_type.dart'; +export 'bluetooth_msgs.dart'; export 'device_identifier.dart'; export 'guid.dart'; export 'log_level.dart'; From 28f2e96fc079bb750e7910b263b2498e7529f402 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Tue, 20 Aug 2024 13:32:04 +0100 Subject: [PATCH 44/90] test: remove tests from platform interface --- ...method_channel_flutter_blue_plus_test.dart | 2038 ----------------- .../bm_bluetooth_adapter_state_test.dart | 118 - .../bm_bluetooth_characteristic_test.dart | 567 ----- .../types/bm_bluetooth_descriptor_test.dart | 244 -- .../test/types/bm_bluetooth_service_test.dart | 432 ---- .../types/bm_bond_state_response_test.dart | 104 - .../types/bm_characteristic_data_test.dart | 493 ---- .../bm_characteristic_properties_test.dart | 384 ---- .../bm_connection_priority_request_test.dart | 60 - .../bm_connection_state_response_test.dart | 60 - .../test/types/bm_descriptor_data_test.dart | 563 ----- .../test/types/bm_devices_list_test.dart | 26 - .../bm_discover_services_result_test.dart | 312 --- .../test/types/bm_msd_filter_test.dart | 208 -- .../types/bm_mtu_changed_response_test.dart | 62 - .../bm_read_characteristic_request_test.dart | 252 -- .../bm_read_descriptor_request_test.dart | 305 --- .../test/types/bm_read_rssi_result_test.dart | 62 - .../types/bm_scan_advertisement_test.dart | 497 ---- .../test/types/bm_scan_response_test.dart | 260 --- .../test/types/bm_scan_settings_test.dart | 574 ----- .../types/bm_service_data_filter_test.dart | 211 -- .../bm_set_notify_value_request_test.dart | 284 --- .../test/types/bm_turn_on_response_test.dart | 112 - .../bm_write_characteristic_request_test.dart | 471 ---- .../bm_write_descriptor_request_test.dart | 379 --- .../test/types/device_identifier_test.dart | 109 - .../test/types/guid_test.dart | 366 --- .../test/types/options_test.dart | 104 - .../test/types/phy_support_test.dart | 145 -- 30 files changed, 9802 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/options_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart deleted file mode 100644 index c799341b..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart +++ /dev/null @@ -1,2038 +0,0 @@ -import 'package:flutter/services.dart'; -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/method_channel/method_channel_flutter_blue_plus.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group( - 'MethodChannelFlutterBluePlus', - () { - final flutterBluePlus = MethodChannelFlutterBluePlus(); - final log = []; - - Future? Function(MethodCall call)? methodCallHandler; - - group( - 'onAdapterStateChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ).toMap(); - - expectLater( - flutterBluePlus.onAdapterStateChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnAdapterStateChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ).toMap(); - - expectLater( - flutterBluePlus.onAdapterStateChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnAdapterStateChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onBondStateChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmBondStateResponse( - remoteId: DeviceIdentifier('str'), - bondState: BmBondStateEnum.none, - ).toMap(); - - expectLater( - flutterBluePlus.onBondStateChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnBondStateChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmBondStateResponse( - remoteId: DeviceIdentifier('str'), - bondState: BmBondStateEnum.none, - ).toMap(); - - expectLater( - flutterBluePlus.onBondStateChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnBondStateChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onCharacteristicReceived', - () { - test( - 'deserializes the event', - () async { - final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onCharacteristicReceived.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnCharacteristicReceived', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onCharacteristicReceived, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnCharacteristicReceived', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onCharacteristicWritten', - () { - test( - 'deserializes the event', - () async { - final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onCharacteristicWritten.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnCharacteristicWritten', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onCharacteristicWritten, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnCharacteristicWritten', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onConnectionStateChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmConnectionStateResponse( - remoteId: DeviceIdentifier('str'), - connectionState: BmConnectionStateEnum.disconnected, - ).toMap(); - - expectLater( - flutterBluePlus.onConnectionStateChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnConnectionStateChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmConnectionStateResponse( - remoteId: DeviceIdentifier('str'), - connectionState: BmConnectionStateEnum.disconnected, - ).toMap(); - - expectLater( - flutterBluePlus.onConnectionStateChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnConnectionStateChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onDescriptorRead', - () { - test( - 'deserializes the event', - () async { - final arguments = BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDescriptorRead.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDescriptorRead', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDescriptorRead, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDescriptorRead', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onDescriptorWritten', - () { - test( - 'deserializes the event', - () async { - final arguments = BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDescriptorWritten.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDescriptorWritten', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDescriptorWritten, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDescriptorWritten', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onDetachedFromEngine', - () { - test( - 'handles the method call', - () async { - expectLater( - flutterBluePlus.onDetachedFromEngine, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDetachedFromEngine', - ), - ); - }, - ); - }, - ); - - group( - 'onDiscoveredServices', - () { - test( - 'deserializes the event', - () async { - final arguments = BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDiscoveredServices.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDiscoveredServices', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDiscoveredServices, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDiscoveredServices', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onMtuChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmMtuChangedResponse( - remoteId: DeviceIdentifier('str'), - mtu: 0, - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onMtuChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnMtuChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmMtuChangedResponse( - remoteId: DeviceIdentifier('str'), - mtu: 0, - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onMtuChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnMtuChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onNameChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmNameChanged( - remoteId: DeviceIdentifier('str'), - name: '', - ).toMap(); - - expectLater( - flutterBluePlus.onNameChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnNameChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmNameChanged( - remoteId: DeviceIdentifier('str'), - name: '', - ).toMap(); - - expectLater( - flutterBluePlus.onNameChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnNameChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onReadRssi', - () { - test( - 'deserializes the event', - () async { - final arguments = BmReadRssiResult( - remoteId: DeviceIdentifier('str'), - rssi: 0, - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onReadRssi.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnReadRssi', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmReadRssiResult( - remoteId: DeviceIdentifier('str'), - rssi: 0, - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onReadRssi, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnReadRssi', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onScanResponse', - () { - test( - 'deserializes the event', - () async { - final arguments = BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onScanResponse.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnScanResponse', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onScanResponse, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnScanResponse', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onServicesReset', - () { - test( - 'deserializes the event', - () async { - final arguments = BmBluetoothDevice( - remoteId: DeviceIdentifier('str'), - ).toMap(); - - expectLater( - flutterBluePlus.onServicesReset.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnServicesReset', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmBluetoothDevice( - remoteId: DeviceIdentifier('str'), - ).toMap(); - - expectLater( - flutterBluePlus.onServicesReset, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnServicesReset', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onServicesReset', - () { - test( - 'deserializes the event', - () async { - final arguments = BmTurnOnResponse( - userAccepted: true, - ).toMap(); - - expectLater( - flutterBluePlus.onTurnOnResponse.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnTurnOnResponse', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmTurnOnResponse( - userAccepted: true, - ).toMap(); - - expectLater( - flutterBluePlus.onTurnOnResponse, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnTurnOnResponse', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'clearGattCache', - () { - test( - 'invokes the method', - () async { - final device = DeviceIdentifier('str'); - - await flutterBluePlus.clearGattCache(device); - - expect( - log, - equals([ - isMethodCall( - 'clearGattCache', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'connect', - () { - final result = true; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final request = BmConnectRequest( - remoteId: DeviceIdentifier('str'), - autoConnect: false, - ); - - expect( - await flutterBluePlus.connect(request), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final request = BmConnectRequest( - remoteId: DeviceIdentifier('str'), - autoConnect: false, - ); - - await flutterBluePlus.connect(request); - - expect( - log, - equals([ - isMethodCall( - 'connect', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'connectedCount', - () { - final result = 0; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.connectedCount(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.connectedCount(); - - expect( - log, - equals([ - isMethodCall( - 'connectedCount', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'createBond', - () { - final result = true; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final device = DeviceIdentifier('str'); - - expect( - await flutterBluePlus.createBond(device), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final device = DeviceIdentifier('str'); - - await flutterBluePlus.createBond(device); - - expect( - log, - equals([ - isMethodCall( - 'createBond', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'disconnect', - () { - final result = true; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final device = DeviceIdentifier('str'); - - expect( - await flutterBluePlus.disconnect(device), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final device = DeviceIdentifier('str'); - - await flutterBluePlus.disconnect(device); - - expect( - log, - equals([ - isMethodCall( - 'disconnect', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'discoverServices', - () { - test( - 'invokes the method', - () async { - final device = DeviceIdentifier('str'); - - await flutterBluePlus.discoverServices(device); - - expect( - log, - equals([ - isMethodCall( - 'discoverServices', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'flutterRestart', - () { - final result = 0; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.flutterRestart(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.flutterRestart(); - - expect( - log, - equals([ - isMethodCall( - 'flutterRestart', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getAdapterName', - () { - final result = ''; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.getAdapterName(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getAdapterName(); - - expect( - log, - equals([ - isMethodCall( - 'getAdapterName', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getAdapterState', - () { - final result = BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ); - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - (await flutterBluePlus.getAdapterState()).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getAdapterState(); - - expect( - log, - equals([ - isMethodCall( - 'getAdapterState', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getBondState', - () { - final result = BmBondStateResponse( - remoteId: DeviceIdentifier('str'), - bondState: BmBondStateEnum.none, - ); - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final device = DeviceIdentifier('str'); - - expect( - (await flutterBluePlus.getBondState(device)).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - final device = DeviceIdentifier('str'); - - await flutterBluePlus.getBondState(device); - - expect( - log, - equals([ - isMethodCall( - 'getBondState', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getBondedDevices', - () { - final result = BmDevicesList( - devices: [], - ); - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - (await flutterBluePlus.getBondedDevices()).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getBondedDevices(); - - expect( - log, - equals([ - isMethodCall( - 'getBondedDevices', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getPhySupport', - () { - final result = PhySupport( - le2M: false, - leCoded: false, - ); - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - (await flutterBluePlus.getPhySupport()).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getPhySupport(); - - expect( - log, - equals([ - isMethodCall( - 'getPhySupport', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getSystemDevices', - () { - final result = BmDevicesList( - devices: [], - ); - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - (await flutterBluePlus.getSystemDevices()).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getSystemDevices(); - - expect( - log, - equals([ - isMethodCall( - 'getSystemDevices', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'isSupported', - () { - final result = true; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.isSupported(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.isSupported(); - - expect( - log, - equals([ - isMethodCall( - 'isSupported', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'readCharacteristic', - () { - test( - 'invokes the method', - () async { - final request = BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ); - - await flutterBluePlus.readCharacteristic(request); - - expect( - log, - equals([ - isMethodCall( - 'readCharacteristic', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'readDescriptor', - () { - test( - 'invokes the method', - () async { - final request = BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ); - - await flutterBluePlus.readDescriptor(request); - - expect( - log, - equals([ - isMethodCall( - 'readDescriptor', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'readRssi', - () { - test( - 'invokes the method', - () async { - final device = DeviceIdentifier('str'); - - await flutterBluePlus.readRssi(device); - - expect( - log, - equals([ - isMethodCall( - 'readRssi', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'removeBond', - () { - final result = true; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final device = DeviceIdentifier('str'); - - expect( - await flutterBluePlus.removeBond(device), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final device = DeviceIdentifier('str'); - - await flutterBluePlus.removeBond(device); - - expect( - log, - equals([ - isMethodCall( - 'removeBond', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'requestConnectionPriority', - () { - test( - 'invokes the method', - () async { - final request = BmConnectionPriorityRequest( - remoteId: DeviceIdentifier('str'), - connectionPriority: BmConnectionPriorityEnum.balanced, - ); - - await flutterBluePlus.requestConnectionPriority(request); - - expect( - log, - equals([ - isMethodCall( - 'requestConnectionPriority', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'requestMtu', - () { - test( - 'invokes the method', - () async { - final request = BmMtuChangeRequest( - remoteId: DeviceIdentifier('str'), - mtu: 0, - ); - - await flutterBluePlus.requestMtu(request); - - expect( - log, - equals([ - isMethodCall( - 'requestMtu', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'setLogLevel', - () { - test( - 'invokes the method', - () async { - final level = LogLevel.none; - - await flutterBluePlus.setLogLevel(level); - - expect( - log, - equals([ - isMethodCall( - 'setLogLevel', - arguments: level.index, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'setNotifyValue', - () { - final result = true; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final request = BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ); - - expect( - await flutterBluePlus.setNotifyValue(request), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final request = BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ); - - await flutterBluePlus.setNotifyValue(request); - - expect( - log, - equals([ - isMethodCall( - 'setNotifyValue', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'setOptions', - () { - test( - 'invokes the method', - () async { - final options = Options( - showPowerAlert: false, - ); - - await flutterBluePlus.setOptions(options); - - expect( - log, - equals([ - isMethodCall( - 'setOptions', - arguments: options.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'setPreferredPhy', - () { - test( - 'invokes the method', - () async { - final preferredPhy = BmPreferredPhy( - remoteId: DeviceIdentifier('str'), - txPhy: 0, - rxPhy: 0, - phyOptions: 0, - ); - - await flutterBluePlus.setPreferredPhy(preferredPhy); - - expect( - log, - equals([ - isMethodCall( - 'setPreferredPhy', - arguments: preferredPhy.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'startScan', - () { - test( - 'invokes the method', - () async { - final settings = BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ); - - await flutterBluePlus.startScan(settings); - - expect( - log, - equals([ - isMethodCall( - 'startScan', - arguments: settings.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'stopScan', - () { - test( - 'invokes the method', - () async { - await flutterBluePlus.stopScan(); - - expect( - log, - equals([ - isMethodCall( - 'stopScan', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'turnOff', - () { - test( - 'invokes the method', - () async { - await flutterBluePlus.turnOff(); - - expect( - log, - equals([ - isMethodCall( - 'turnOff', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'turnOn', - () { - final result = true; - - setUp( - () { - methodCallHandler = (call) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - methodCallHandler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.turnOn(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.turnOn(); - - expect( - log, - equals([ - isMethodCall( - 'turnOn', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'writeCharacteristic', - () { - test( - 'invokes the method', - () async { - final request = BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ); - - await flutterBluePlus.writeCharacteristic(request); - - expect( - log, - equals([ - isMethodCall( - 'writeCharacteristic', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'writeDescriptor', - () { - test( - 'invokes the method', - () async { - final request = BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ); - - await flutterBluePlus.writeDescriptor(request); - - expect( - log, - equals([ - isMethodCall( - 'writeDescriptor', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - setUp( - () { - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler( - flutterBluePlus.channel, - (call) { - log.add(call); - - return methodCallHandler?.call(call); - }, - ); - }, - ); - - tearDown( - () { - log.clear(); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart deleted file mode 100644 index 4bc542ec..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart +++ /dev/null @@ -1,118 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBluetoothAdapterState', - () { - group( - 'fromMap', - () { - test( - 'deserializes the adapter state property', - () { - final adapterState = BmAdapterStateEnum.unknown; - - expect( - BmBluetoothAdapterState.fromMap({ - 'adapter_state': adapterState.index, - }).adapterState, - equals(adapterState), - ); - }, - ); - - test( - 'throws a range error if the adapter state property index is out of range', - () { - expect( - () { - BmBluetoothAdapterState.fromMap({ - 'adapter_state': 7, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final adapterState = BmAdapterStateEnum.unknown; - - expect( - BmBluetoothAdapterState( - adapterState: adapterState, - ).hashCode, - equals(adapterState.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ) == - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unavailable, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ) == - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the adapter state property', - () { - final adapterState = BmAdapterStateEnum.unknown; - - expect( - BmBluetoothAdapterState( - adapterState: adapterState, - ).toMap(), - containsPair( - 'adapter_state', - equals(adapterState.index), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart deleted file mode 100644 index 48f71e75..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart +++ /dev/null @@ -1,567 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBluetoothCharacteristic', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptors': [], - 'properties': {}, - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptors property', - () { - final descriptors = [ - { - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }, - ]; - - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptors': descriptors, - 'properties': {}, - }).descriptors, - equals( - descriptors.map( - (descriptor) { - return BmBluetoothDescriptor.fromMap(descriptor); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the descriptors property as [] if it is null', - () { - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptors': null, - 'properties': {}, - }).descriptors, - equals([]), - ); - }, - ); - - test( - 'deserializes the properties property properties as false if it is null', - () { - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptors': [], - 'properties': null, - }).properties, - equals( - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': remoteId, - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptors': [], - 'properties': {}, - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'descriptors': [], - 'properties': {}, - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptors': [], - 'properties': {}, - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptors': [], - 'properties': {}, - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final descriptors = []; - final properties = BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ); - - expect( - BmBluetoothCharacteristic( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - descriptors: descriptors, - properties: properties, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality() - .hash(descriptors) ^ - properties.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ) == - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ) == - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the descriptors property', - () { - final descriptors = [ - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - ]; - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: descriptors, - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'descriptors', - equals( - descriptors.map( - (descriptor) { - return descriptor.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the properties property', - () { - final properties = BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ); - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: properties, - ).toMap(), - containsPair( - 'properties', - equals(properties.toMap()), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmBluetoothCharacteristic( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart deleted file mode 100644 index a94a835c..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart +++ /dev/null @@ -1,244 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBluetoothDescriptor', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmBluetoothDescriptor.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptor_uuid': '0102', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptor uuid property', - () { - final descriptorUuid = '0102'; - - expect( - BmBluetoothDescriptor.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': descriptorUuid, - }).descriptorUuid, - equals(Guid(descriptorUuid)), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmBluetoothDescriptor.fromMap({ - 'remote_id': remoteId, - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmBluetoothDescriptor.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final characteristicUuid = Guid('0102'); - final descriptorUuid = Guid('0102'); - - expect( - BmBluetoothDescriptor( - remoteId: remoteId, - serviceUuid: serviceUuid, - characteristicUuid: characteristicUuid, - descriptorUuid: descriptorUuid, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str1'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ) == - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str2'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ) == - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the descriptor uuid property', - () { - final descriptorUuid = Guid('0102'); - - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: descriptorUuid, - ).toMap(), - containsPair( - 'descriptor_uuid', - equals(descriptorUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmBluetoothDescriptor( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart deleted file mode 100644 index 98c18c2c..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart +++ /dev/null @@ -1,432 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBluetoothService', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristics property', - () { - final characteristics = [ - { - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'descriptors': [], - 'properties': {}, - }, - ]; - - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': characteristics, - 'included_services': [], - }).characteristics, - equals( - characteristics.map( - (characteristic) { - return BmBluetoothCharacteristic.fromMap(characteristic); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the characteristics property as [] if it is null', - () { - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': null, - 'included_services': [], - }).characteristics, - equals([]), - ); - }, - ); - - test( - 'deserializes the included services property', - () { - final includedServices = [ - { - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': [], - }, - ]; - - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': includedServices, - }).includedServices, - equals( - includedServices.map( - (includedService) { - return BmBluetoothService.fromMap(includedService); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the included services property as [] if it is null', - () { - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': null, - }).includedServices, - equals([]), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmBluetoothService.fromMap({ - 'remote_id': remoteId, - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': null, - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'is_primary': 1, - 'characteristics': [], - 'included_services': null, - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - - test( - 'deserializes the is primary property as false if it is not 1', - () { - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 0, - 'characteristics': [], - 'included_services': null, - }).isPrimary, - isFalse, - ); - }, - ); - - test( - 'deserializes the is primary property as true if it is 1', - () { - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': null, - }).isPrimary, - isTrue, - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final isPrimary = true; - final characteristics = []; - final includedServices = []; - - expect( - BmBluetoothService( - remoteId: remoteId, - serviceUuid: serviceUuid, - isPrimary: isPrimary, - characteristics: characteristics, - includedServices: includedServices, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - isPrimary.hashCode ^ - const ListEquality() - .hash(characteristics) ^ - const ListEquality() - .hash(includedServices), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ) == - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: false, - characteristics: [], - includedServices: [], - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ) == - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristics property', - () { - final characteristics = [ - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - ]; - - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: characteristics, - includedServices: [], - ).toMap(), - containsPair( - 'characteristics', - equals( - characteristics.map( - (characteristic) { - return characteristic.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the included services property', - () { - final includedServices = [ - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ), - ]; - - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: includedServices, - ).toMap(), - containsPair( - 'included_services', - equals( - includedServices.map( - (includedService) { - return includedService.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the is primary property as 0 if it is false', - () { - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: false, - characteristics: [], - includedServices: [], - ).toMap(), - containsPair( - 'is_primary', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the is primary property as 1 if it is true', - () { - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ).toMap(), - containsPair( - 'is_primary', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmBluetoothService( - remoteId: remoteId, - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - isPrimary: true, - characteristics: [], - includedServices: [], - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart deleted file mode 100644 index b3d893c2..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart +++ /dev/null @@ -1,104 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBondStateResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the bond state property', - () { - expect( - BmBondStateResponse.fromMap({ - 'remote_id': 'str', - 'bond_state': 0, - }).bondState, - equals(BmBondStateEnum.none), - ); - }, - ); - - test( - 'deserializes the prev state property', - () { - expect( - BmBondStateResponse.fromMap({ - 'remote_id': 'str', - 'bond_state': 0, - 'prev_state': 0, - }).prevState, - equals(BmBondStateEnum.none), - ); - }, - ); - - test( - 'throws a range error if the bond state property index is out of range', - () { - expect( - () { - BmBondStateResponse.fromMap({ - 'remote_id': 'str', - 'bond_state': 3, - }); - }, - throwsRangeError, - ); - }, - ); - - test( - 'throws a range error if the prev state property index is out of range', - () { - expect( - () { - BmBondStateResponse.fromMap({ - 'remote_id': 'str', - 'bond_state': 0, - 'prev_state': 3, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the bond state property', - () { - expect( - BmBondStateResponse( - remoteId: DeviceIdentifier('str'), - bondState: BmBondStateEnum.none, - ).toMap(), - containsPair('bond_state', 0), - ); - }, - ); - - test( - 'serializes the prev state property', - () { - expect( - BmBondStateResponse( - remoteId: DeviceIdentifier('str'), - bondState: BmBondStateEnum.none, - prevState: BmBondStateEnum.none, - ).toMap(), - containsPair('prev_state', 0), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart deleted file mode 100644 index 5b07e287..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart +++ /dev/null @@ -1,493 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmCharacteristicData', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmCharacteristicData.fromMap({ - 'remote_id': remoteId, - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'value': '', - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'value': '', - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'value': '', - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the value property', - () { - final value = '010203'; - - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'value': value, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).value, - equals(hex.decode(value)), - ); - }, - ); - - test( - 'deserializes the value property as [] if it is null', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'value': null, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).value, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final value = []; - final success = true; - final errorCode = 0; - final errorString = ''; - - expect( - BmCharacteristicData( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - value: value, - success: success, - errorCode: errorCode, - errorString: errorString, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: false, - errorCode: 0, - errorString: '', - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmCharacteristicData( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: false, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the value property', - () { - final value = [0x01, 0x02, 0x03]; - - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: value, - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'value', - hex.encode(value), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart deleted file mode 100644 index 75301ba1..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart +++ /dev/null @@ -1,384 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmCharacteristicProperties', - () { - group( - 'fromMap', - () { - test( - 'deserializes the properties as false if they are not 1', - () { - expect( - BmCharacteristicProperties.fromMap({ - 'broadcast': 0, - 'read': 0, - 'write_without_response': 0, - 'write': 0, - 'notify': 0, - 'indicate': 0, - 'authenticated_signed_writes': 0, - 'extended_properties': 0, - 'notify_encryption_required': 0, - 'indicate_encryption_required': 0, - }), - equals( - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - ); - }, - ); - - test( - 'deserializes the properties as true if they are 1', - () { - expect( - BmCharacteristicProperties.fromMap({ - 'broadcast': 1, - 'read': 1, - 'write_without_response': 1, - 'write': 1, - 'notify': 1, - 'indicate': 1, - 'authenticated_signed_writes': 1, - 'extended_properties': 1, - 'notify_encryption_required': 1, - 'indicate_encryption_required': 1, - }), - equals( - BmCharacteristicProperties( - broadcast: true, - read: true, - writeWithoutResponse: true, - write: true, - notify: true, - indicate: true, - authenticatedSignedWrites: true, - extendedProperties: true, - notifyEncryptionRequired: true, - indicateEncryptionRequired: true, - ), - ), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final broadcast = false; - final read = false; - final writeWithoutResponse = false; - final write = false; - final notify = false; - final indicate = false; - final authenticatedSignedWrites = false; - final extendedProperties = false; - final notifyEncryptionRequired = false; - final indicateEncryptionRequired = false; - - expect( - BmCharacteristicProperties( - broadcast: broadcast, - read: read, - writeWithoutResponse: writeWithoutResponse, - write: write, - notify: notify, - indicate: indicate, - authenticatedSignedWrites: authenticatedSignedWrites, - extendedProperties: extendedProperties, - notifyEncryptionRequired: notifyEncryptionRequired, - indicateEncryptionRequired: indicateEncryptionRequired, - ).hashCode, - equals( - broadcast.hashCode ^ - read.hashCode ^ - writeWithoutResponse.hashCode ^ - write.hashCode ^ - notify.hashCode ^ - indicate.hashCode ^ - authenticatedSignedWrites.hashCode ^ - extendedProperties.hashCode ^ - notifyEncryptionRequired.hashCode ^ - indicateEncryptionRequired.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ) == - BmCharacteristicProperties( - broadcast: true, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ) == - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the properties as 0 if they are false', - () { - final map = BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ).toMap(); - - expect( - map, - containsPair( - 'broadcast', - equals(0), - ), - ); - expect( - map, - containsPair( - 'read', - equals(0), - ), - ); - expect( - map, - containsPair( - 'write_without_response', - equals(0), - ), - ); - expect( - map, - containsPair( - 'write', - equals(0), - ), - ); - expect( - map, - containsPair( - 'notify', - equals(0), - ), - ); - expect( - map, - containsPair( - 'indicate', - equals(0), - ), - ); - expect( - map, - containsPair( - 'authenticated_signed_writes', - equals(0), - ), - ); - expect( - map, - containsPair( - 'extended_properties', - equals(0), - ), - ); - expect( - map, - containsPair( - 'notify_encryption_required', - equals(0), - ), - ); - expect( - map, - containsPair( - 'indicate_encryption_required', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the properties as 1 if they are true', - () { - final map = BmCharacteristicProperties( - broadcast: true, - read: true, - writeWithoutResponse: true, - write: true, - notify: true, - indicate: true, - authenticatedSignedWrites: true, - extendedProperties: true, - notifyEncryptionRequired: true, - indicateEncryptionRequired: true, - ).toMap(); - - expect( - map, - containsPair( - 'broadcast', - equals(1), - ), - ); - expect( - map, - containsPair( - 'read', - equals(1), - ), - ); - expect( - map, - containsPair( - 'write_without_response', - equals(1), - ), - ); - expect( - map, - containsPair( - 'write', - equals(1), - ), - ); - expect( - map, - containsPair( - 'notify', - equals(1), - ), - ); - expect( - map, - containsPair( - 'indicate', - equals(1), - ), - ); - expect( - map, - containsPair( - 'authenticated_signed_writes', - equals(1), - ), - ); - expect( - map, - containsPair( - 'extended_properties', - equals(1), - ), - ); - expect( - map, - containsPair( - 'notify_encryption_required', - equals(1), - ), - ); - expect( - map, - containsPair( - 'indicate_encryption_required', - equals(1), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart deleted file mode 100644 index 46d33333..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmConnectionPriorityRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the connection priority property', - () { - expect( - BmConnectionPriorityRequest.fromMap({ - 'remote_id': 'str', - 'connection_priority': 0, - }).connectionPriority, - equals(BmConnectionPriorityEnum.balanced), - ); - }, - ); - - test( - 'throws a range error if the connection priority property index is out of range', - () { - expect( - () { - BmConnectionPriorityRequest.fromMap({ - 'remote_id': 'str', - 'connection_priority': 3, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the connection priority property', - () { - expect( - BmConnectionPriorityRequest( - remoteId: DeviceIdentifier('str'), - connectionPriority: BmConnectionPriorityEnum.balanced, - ).toMap(), - containsPair('connection_priority', 0), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart deleted file mode 100644 index 4a33d69c..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmConnectionStateResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the connection state property', - () { - expect( - BmConnectionStateResponse.fromMap({ - 'remote_id': 'str', - 'connection_state': 0, - }).connectionState, - equals(BmConnectionStateEnum.disconnected), - ); - }, - ); - - test( - 'throws a range error if the connection state property index is out of range', - () { - expect( - () { - BmConnectionStateResponse.fromMap({ - 'remote_id': 'str', - 'connection_state': 2, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the connection state property', - () { - expect( - BmConnectionStateResponse( - remoteId: DeviceIdentifier('str'), - connectionState: BmConnectionStateEnum.disconnected, - ).toMap(), - containsPair('connection_state', 0), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart deleted file mode 100644 index e7096be4..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart +++ /dev/null @@ -1,563 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmDescriptorData', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptor uuid property', - () { - final descriptorUuid = '0102'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': descriptorUuid, - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).descriptorUuid, - equals(Guid(descriptorUuid)), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': remoteId, - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the value property', - () { - final value = '010203'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': value, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).value, - equals(hex.decode(value)), - ); - }, - ); - - test( - 'deserializes the value property as [] if it is null', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': null, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).value, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final descriptorUuid = Guid('0102'); - final value = []; - final success = true; - final errorCode = 0; - final errorString = ''; - - expect( - BmDescriptorData( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - descriptorUuid: descriptorUuid, - value: value, - success: success, - errorCode: errorCode, - errorString: errorString, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: false, - errorCode: 0, - errorString: '', - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the descriptor uuid property', - () { - final descriptorUuid = Guid('0102'); - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: descriptorUuid, - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'descriptor_uuid', - equals(descriptorUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmDescriptorData( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: false, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the value property', - () { - final value = [0x01, 0x02, 0x03]; - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: value, - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'value', - hex.encode(value), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart deleted file mode 100644 index 0beef270..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmDevicesList', - () { - group( - 'fromMap', - () { - test( - 'deserializes the devices property as [] if it is null', - () { - expect( - BmDevicesList.fromMap({ - 'devices': null, - }).devices, - equals([]), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart deleted file mode 100644 index d7df6914..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart +++ /dev/null @@ -1,312 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmDiscoverServicesResult', - () { - group( - 'fromMap', - () { - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': remoteId, - 'services': [], - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the services property', - () { - final services = [ - { - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': [], - } - ]; - - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', - 'services': services, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).services, - equals( - services.map( - (service) { - return BmBluetoothService.fromMap(service); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the services property as [] if it is null', - () { - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', - 'services': null, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).services, - equals([]), - ); - }, - ); - - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', - 'services': [], - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', - 'services': [], - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', - 'services': [], - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final services = []; - final success = true; - final errorCode = 0; - final errorString = ''; - - expect( - BmDiscoverServicesResult( - remoteId: remoteId, - services: services, - success: success, - errorCode: errorCode, - errorString: errorString, - ).hashCode, - equals( - remoteId.hashCode ^ - const ListEquality().hash(services) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: false, - errorCode: 0, - errorString: '', - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmDiscoverServicesResult( - remoteId: remoteId, - services: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the services property', - () { - final services = [ - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ), - ]; - - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: services, - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'services', - equals( - services.map( - (service) { - return service.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: false, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(1), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart deleted file mode 100644 index 6c482e77..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart +++ /dev/null @@ -1,208 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmMsdFilter', - () { - group( - 'fromMap', - () { - test( - 'deserializes the data property', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': '010203', - 'mask': null, - }).data, - equals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - - test( - 'deserializes the data property as null if it is null', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': null, - 'mask': null, - }).data, - isNull, - ); - }, - ); - - test( - 'deserializes the mask property', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': null, - 'mask': '010203', - }).mask, - equals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - - test( - 'deserializes the mask property as null if it is null', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': null, - 'mask': null, - }).mask, - isNull, - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final manufacturerId = 0; - final data = []; - final mask = []; - - expect( - BmMsdFilter( - manufacturerId, - data, - mask, - ).hashCode, - equals( - manufacturerId.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmMsdFilter(0, [], []) == BmMsdFilter(1, [], []), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmMsdFilter(0, [], []) == BmMsdFilter(0, [], []), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the data property', - () { - final data = [0x01, 0x02, 0x03]; - - expect( - BmMsdFilter( - 0, - data, - [], - ).toMap(), - containsPair( - 'data', - hex.encode(data), - ), - ); - }, - ); - - test( - 'serializes the data property as null if it is null', - () { - expect( - BmMsdFilter( - 0, - null, - [], - ).toMap(), - containsPair( - 'data', - isNull, - ), - ); - }, - ); - - test( - 'serializes the mask property', - () { - final mask = [0x01, 0x02, 0x03]; - - expect( - BmMsdFilter( - 0, - [], - mask, - ).toMap(), - containsPair( - 'mask', - hex.encode(mask), - ), - ); - }, - ); - - test( - 'serializes the mask property as null if it is null', - () { - expect( - BmMsdFilter( - 0, - [], - null, - ).toMap(), - containsPair( - 'mask', - isNull, - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart deleted file mode 100644 index b2386ec5..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmMtuChangedResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmMtuChangedResponse.fromMap({ - 'remote_id': 'str', - 'mtu': 0, - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmMtuChangedResponse.fromMap({ - 'remote_id': 'str', - 'mtu': 0, - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmMtuChangedResponse.fromMap({ - 'remote_id': 'str', - 'mtu': 0, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart deleted file mode 100644 index 415d4a59..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart +++ /dev/null @@ -1,252 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmReadCharacteristicRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmReadCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmReadCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmReadCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmReadCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - - expect( - BmReadCharacteristicRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ) == - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ) == - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmReadCharacteristicRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart deleted file mode 100644 index 2a1d1479..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart +++ /dev/null @@ -1,305 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmReadDescriptorRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptor_uuid': '0102', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptor uuid property', - () { - final descriptorUuid = '0102'; - - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': descriptorUuid, - }).descriptorUuid, - equals(Guid(descriptorUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final descriptorUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - descriptorUuid: descriptorUuid, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ) == - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ) == - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the characteristic uuid property', - () { - final descriptorUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: descriptorUuid, - ).toMap(), - containsPair( - 'descriptor_uuid', - equals(descriptorUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmReadDescriptorRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart deleted file mode 100644 index 4af76ce0..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmReadRssiResult', - () { - group( - 'fromMap', - () { - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmReadRssiResult.fromMap({ - 'remote_id': 'str', - 'rssi': 0, - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmReadRssiResult.fromMap({ - 'remote_id': 'str', - 'rssi': 0, - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmReadRssiResult.fromMap({ - 'remote_id': 'str', - 'rssi': 0, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart deleted file mode 100644 index 75200dd3..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart +++ /dev/null @@ -1,497 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmScanAdvertisement', - () { - group( - 'fromMap', - () { - test( - 'deserializes the connectable property as false if it is not 1', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 0, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': 0, - }).connectable, - isFalse, - ); - }, - ); - - test( - 'deserializes the connectable property as true if it is 1', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': 0, - }).connectable, - isTrue, - ); - }, - ); - - test( - 'deserializes the manufacturer data property', - () { - final manufacturerData = { - 1: '010203', - }; - - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': manufacturerData, - 'service_data': {}, - 'service_uuids': [], - 'rssi': 0, - }).manufacturerData, - equals( - manufacturerData.map( - (key, value) { - return MapEntry(key, hex.decode(value)); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the manufacturer data property as {} if it is null', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': null, - 'service_data': {}, - 'service_uuids': [], - 'rssi': 0, - }).manufacturerData, - equals({}), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': remoteId, - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': 0, - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the rssi property', - () { - final rssi = 0; - - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': rssi, - }).rssi, - equals(rssi), - ); - }, - ); - - test( - 'deserializes the rssi property as 0 if it is null', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': null, - }).rssi, - equals(0), - ); - }, - ); - - test( - 'deserializes the service data property', - () { - final serviceData = { - '0102': '010203', - }; - - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': serviceData, - 'service_uuids': [], - 'rssi': 0, - }).serviceData, - equals( - serviceData.map( - (key, value) { - return MapEntry(Guid(key), hex.decode(value)); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the service data property as {} if it is null', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': null, - 'service_uuids': [], - 'rssi': 0, - }).serviceData, - equals({}), - ); - }, - ); - - test( - 'deserializes the service uuids property', - () { - final serviceUuids = [ - '0102', - ]; - - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': serviceUuids, - 'rssi': 0, - }).serviceUuids, - equals( - serviceUuids.map( - (serviceUuid) { - return Guid(serviceUuid); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the service uuids property as [] if it is null', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': null, - 'rssi': 0, - }).serviceUuids, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final platformName = null; - final advName = null; - final connectable = true; - final txPowerLevel = 0; - final appearance = 0; - final manufacturerData = >{}; - final serviceData = >{}; - final serviceUuids = []; - final rssi = 0; - - expect( - BmScanAdvertisement( - remoteId: remoteId, - platformName: platformName, - advName: advName, - connectable: connectable, - txPowerLevel: txPowerLevel, - appearance: appearance, - manufacturerData: manufacturerData, - serviceData: serviceData, - serviceUuids: serviceUuids, - rssi: rssi, - ).hashCode, - equals( - remoteId.hashCode ^ - platformName.hashCode ^ - advName.hashCode ^ - connectable.hashCode ^ - txPowerLevel.hashCode ^ - appearance.hashCode ^ - const MapEquality>() - .hash(manufacturerData) ^ - const MapEquality>().hash(serviceData) ^ - const ListEquality().hash(serviceUuids) ^ - rssi.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ) == - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: false, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ) == - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the connectable property as 0 if it is false', - () { - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: false, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'connectable', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the connectable property as 1 if it is true', - () { - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'connectable', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the manufacturer data property', - () { - final manufacturerData = { - 0: [0x01, 0x02, 0x03], - }; - - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: manufacturerData, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'manufacturer_data', - equals( - manufacturerData.map( - (key, value) { - return MapEntry(key, hex.encode(value)); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmScanAdvertisement( - remoteId: remoteId, - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the service data property', - () { - final serviceData = { - Guid('0102'): [0x01, 0x02, 0x03], - }; - - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: serviceData, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'service_data', - equals( - serviceData.map( - (key, value) { - return MapEntry(key.str, hex.encode(value)); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the service uuids property', - () { - final serviceUuids = [ - Guid('0102'), - ]; - - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: serviceUuids, - rssi: 0, - ).toMap(), - containsPair( - 'service_uuids', - equals( - serviceUuids.map( - (serviceUuid) { - return serviceUuid.str; - }, - ), - ), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart deleted file mode 100644 index 34bc770e..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart +++ /dev/null @@ -1,260 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmScanResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the advertisements property', - () { - final advertisements = [ - { - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - } - ]; - - expect( - BmScanResponse.fromMap({ - 'advertisements': advertisements, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).advertisements, - equals( - advertisements.map( - (advertisement) { - return BmScanAdvertisement.fromMap(advertisement); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the advertisements property as [] if it is null', - () { - expect( - BmScanResponse.fromMap({ - 'advertisements': null, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).advertisements, - equals([]), - ); - }, - ); - - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmScanResponse.fromMap({ - 'advertisements': [], - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmScanResponse.fromMap({ - 'advertisements': [], - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmScanResponse.fromMap({ - 'advertisements': [], - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final advertisements = []; - final success = true; - final errorCode = 0; - final errorString = ''; - - expect( - BmScanResponse( - advertisements: advertisements, - success: success, - errorCode: errorCode, - errorString: errorString, - ).hashCode, - equals( - const ListEquality() - .hash(advertisements) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmScanResponse( - advertisements: [], - success: false, - errorCode: 0, - errorString: '', - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the services property', - () { - final advertisements = [ - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ), - ]; - - expect( - BmScanResponse( - advertisements: advertisements, - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'advertisements', - equals( - advertisements.map( - (advertisement) { - return advertisement.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmScanResponse( - advertisements: [], - success: false, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(1), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart deleted file mode 100644 index c90dbcc3..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart +++ /dev/null @@ -1,574 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmScanSettings', - () { - group( - 'fromMap', - () { - test( - 'deserializes the with keywords property', - () { - final withKeywords = [ - 'keyword', - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': withKeywords, - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withKeywords, - equals(withKeywords), - ); - }, - ); - - test( - 'deserializes the with keywords property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': null, - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withKeywords, - equals([]), - ); - }, - ); - - test( - 'deserializes the with msd property', - () { - final withMsd = [ - { - 'manufacturer_id': 0, - 'data': '', - 'mask': '', - }, - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': withMsd, - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withMsd, - equals( - withMsd.map( - (manufacturerData) { - return BmMsdFilter.fromMap(manufacturerData); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the with msd property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': null, - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withMsd, - equals([]), - ); - }, - ); - - test( - 'deserializes the with names property', - () { - final withNames = [ - 'name', - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': withNames, - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withNames, - equals(withNames), - ); - }, - ); - - test( - 'deserializes the with names property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': null, - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withNames, - equals([]), - ); - }, - ); - - test( - 'deserializes the with remote ids property', - () { - final withRemoteIds = [ - 'str', - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': withRemoteIds, - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withRemoteIds, - equals(withRemoteIds), - ); - }, - ); - - test( - 'deserializes the with remote ids property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': null, - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withRemoteIds, - equals([]), - ); - }, - ); - - test( - 'deserializes the with service data property', - () { - final withServiceData = [ - { - 'service': '0102', - 'data': '010203', - 'mask': '010203', - }, - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': withServiceData, - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withServiceData, - equals( - withServiceData.map( - (serviceData) { - return BmServiceDataFilter.fromMap(serviceData); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the with service data property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': null, - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withServiceData, - equals([]), - ); - }, - ); - - test( - 'deserializes the with services property', - () { - final withServices = [ - '0102', - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': withServices, - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withServices, - equals( - withServices.map( - (service) { - return Guid(service); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the with services property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': null, - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withServices, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final withServices = []; - final withRemoteIds = []; - final withNames = []; - final withKeywords = []; - final withMsd = []; - final withServiceData = []; - final continuousUpdates = false; - final continuousDivisor = 1; - final androidLegacy = false; - final androidScanMode = 0; - final androidUsesFineLocation = false; - - expect( - BmScanSettings( - withServices: withServices, - withRemoteIds: withRemoteIds, - withNames: withNames, - withKeywords: withKeywords, - withMsd: withMsd, - withServiceData: withServiceData, - continuousUpdates: continuousUpdates, - continuousDivisor: continuousDivisor, - androidLegacy: androidLegacy, - androidScanMode: androidScanMode, - androidUsesFineLocation: androidUsesFineLocation, - ).hashCode, - equals( - const ListEquality().hash(withServices) ^ - const ListEquality().hash(withRemoteIds) ^ - const ListEquality().hash(withNames) ^ - const ListEquality().hash(withKeywords) ^ - const ListEquality().hash(withMsd) ^ - const ListEquality() - .hash(withServiceData) ^ - continuousUpdates.hashCode ^ - continuousDivisor.hashCode ^ - androidLegacy.hashCode ^ - androidScanMode.hashCode ^ - androidUsesFineLocation.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ) == - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: true, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ) == - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the with msd property', - () { - final withMsd = [ - BmMsdFilter( - 0, - [], - [], - ), - ]; - - expect( - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: withMsd, - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ).toMap(), - containsPair( - 'with_msd', - equals( - withMsd.map( - (manufacturerData) { - return manufacturerData.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the with service data property', - () { - final withServiceData = [ - BmServiceDataFilter( - Guid('0102'), - [], - [], - ), - ]; - - expect( - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: withServiceData, - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ).toMap(), - containsPair( - 'with_service_data', - equals( - withServiceData.map( - (serviceData) { - return serviceData.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the with services property', - () { - final withServices = [ - Guid('0102'), - ]; - - expect( - BmScanSettings( - withServices: withServices, - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ).toMap(), - containsPair( - 'with_services', - equals( - withServices.map( - (service) { - return service.str; - }, - ), - ), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart deleted file mode 100644 index 1e241a8d..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart +++ /dev/null @@ -1,211 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmServiceDataFilter', - () { - group( - 'fromMap', - () { - test( - 'deserializes the data property', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': '010203', - 'mask': '010203', - }).data, - equals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - - test( - 'deserializes the data property as [] if it is null', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': null, - 'mask': '010203', - }).data, - equals([]), - ); - }, - ); - - test( - 'deserializes the mask property', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': '010203', - 'mask': '010203', - }).mask, - equals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - - test( - 'deserializes the mask property as [] if it is null', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': '010203', - 'mask': null, - }).mask, - equals([]), - ); - }, - ); - - test( - 'deserializes the service property', - () { - final service = '0102'; - - expect( - BmServiceDataFilter.fromMap({ - 'service': service, - 'data': '010203', - 'mask': '010203', - }).service, - equals(Guid(service)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final service = Guid('0102'); - final data = []; - final mask = []; - - expect( - BmServiceDataFilter( - service, - data, - mask, - ).hashCode, - equals( - service.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmServiceDataFilter(Guid('0102'), [], []) == - BmServiceDataFilter(Guid('0304'), [], []), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmServiceDataFilter(Guid('0102'), [], []) == - BmServiceDataFilter(Guid('0102'), [], []), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the data property', - () { - final data = [0x01, 0x02, 0x03]; - - expect( - BmServiceDataFilter( - Guid('0102'), - data, - [], - ).toMap(), - containsPair( - 'data', - hex.encode(data), - ), - ); - }, - ); - - test( - 'serializes the mask property', - () { - final mask = [0x01, 0x02, 0x03]; - - expect( - BmServiceDataFilter( - Guid('0102'), - [], - mask, - ).toMap(), - containsPair( - 'mask', - hex.encode(mask), - ), - ); - }, - ); - - test( - 'serializes the characteristic uuid property', - () { - final service = Guid('0102'); - - expect( - BmServiceDataFilter( - service, - [], - [], - ).toMap(), - containsPair( - 'service', - equals(service.str), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart deleted file mode 100644 index 4ce9ebe5..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart +++ /dev/null @@ -1,284 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmSetNotifyValueRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'force_indications': false, - 'enable': false, - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final forceIndications = false; - final enable = false; - - expect( - BmSetNotifyValueRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - forceIndications: forceIndications, - enable: enable, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - forceIndications.hashCode ^ - enable.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ) == - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ) == - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmSetNotifyValueRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart deleted file mode 100644 index 61fb826f..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart +++ /dev/null @@ -1,112 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmTurnOnResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the user accepted property', - () { - expect( - BmTurnOnResponse.fromMap({ - 'user_accepted': true, - }).userAccepted, - isTrue, - ); - }, - ); - - test( - 'deserializes the user accepted property as false if it is null', - () { - expect( - BmTurnOnResponse.fromMap({ - 'user_accepted': null, - }).userAccepted, - isFalse, - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final userAccepted = true; - - expect( - BmTurnOnResponse( - userAccepted: userAccepted, - ).hashCode, - equals(userAccepted.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmTurnOnResponse( - userAccepted: true, - ) == - BmTurnOnResponse( - userAccepted: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmTurnOnResponse( - userAccepted: true, - ) == - BmTurnOnResponse( - userAccepted: true, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the user accepted property', - () { - expect( - BmTurnOnResponse( - userAccepted: true, - ).toMap(), - containsPair( - 'user_accepted', - isTrue, - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart deleted file mode 100644 index f4ef3688..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart +++ /dev/null @@ -1,471 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmWriteCharacteristicRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'write_type': 0, - 'allow_long_write': 0, - 'value': '', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 0, - 'value': '', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 0, - 'value': '', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 0, - 'value': '', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - - test( - 'deserializes the allow long write property as false if it is 0', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 0, - 'value': '', - }).allowLongWrite, - isFalse, - ); - }, - ); - - test( - 'deserializes the allow long write property as true if it is not 0', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 1, - 'value': '', - }).allowLongWrite, - isTrue, - ); - }, - ); - - test( - 'deserializes the value property', - () { - final value = '010203'; - - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 0, - 'value': value, - }).value, - equals(hex.decode(value)), - ); - }, - ); - - test( - 'deserializes the value property as [] if it is null', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 0, - 'value': null, - }).value, - equals([]), - ); - }, - ); - - test( - 'deserializes the write type property', - () { - final writeType = BmWriteType.withResponse; - - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': writeType.index, - 'allow_long_write': 0, - 'value': '', - }).writeType, - equals(writeType), - ); - }, - ); - - test( - 'throws a range error if the write type property index is out of range', - () { - expect( - () { - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 2, - 'allow_long_write': 0, - 'value': '', - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final writeType = BmWriteType.withResponse; - final allowLongWrite = false; - final value = []; - - expect( - BmWriteCharacteristicRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - writeType: writeType, - allowLongWrite: allowLongWrite, - value: value, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - writeType.hashCode ^ - allowLongWrite.hashCode ^ - const ListEquality().hash(value), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ) == - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ) == - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmWriteCharacteristicRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'allow_long_write', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: true, - value: [], - ).toMap(), - containsPair( - 'allow_long_write', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the write type property', - () { - final writeType = BmWriteType.withResponse; - - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: writeType, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'write_type', - equals(writeType.index), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart deleted file mode 100644 index 4a2c8d79..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart +++ /dev/null @@ -1,379 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmWriteDescriptorRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptor_uuid': '0102', - 'value': '', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptor uuid property', - () { - final descriptorUuid = '0102'; - - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': descriptorUuid, - 'value': '', - }).descriptorUuid, - equals(Guid(descriptorUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - - test( - 'deserializes the value property', - () { - final value = '010203'; - - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': value, - }).value, - equals(hex.decode(value)), - ); - }, - ); - - test( - 'deserializes the value property as [] if it is null', - () { - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': null, - }).value, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final descriptorUuid = Guid('0102'); - final value = []; - - expect( - BmWriteDescriptorRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - descriptorUuid: descriptorUuid, - value: value, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ) == - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ) == - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the characteristic uuid property', - () { - final descriptorUuid = Guid('0102'); - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: descriptorUuid, - value: [], - ).toMap(), - containsPair( - 'descriptor_uuid', - equals(descriptorUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmWriteDescriptorRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the value property', - () { - final value = [0x01, 0x02, 0x03]; - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: value, - ).toMap(), - containsPair( - 'value', - hex.encode(value), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart deleted file mode 100644 index 87da0ac3..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart +++ /dev/null @@ -1,109 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'DeviceIdentifier', - () { - group( - 'hashCode', - () { - test( - 'returns the hash code of a lower case identifier', - () { - expect( - DeviceIdentifier('str').hashCode, - equals('str'.hashCode), - ); - }, - ); - - test( - 'returns the hash code of a mixed case identifier', - () { - expect( - DeviceIdentifier('sTr').hashCode, - equals('str'.hashCode), - ); - }, - ); - - test( - 'returns the hash code of an upper case identifier', - () { - expect( - DeviceIdentifier('STR').hashCode, - equals('str'.hashCode), - ); - }, - ); - }, - ); - - group( - 'id', - () { - test( - 'returns the str property', - () { - expect( - DeviceIdentifier('str').id, - equals('str'), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - DeviceIdentifier('str1') == DeviceIdentifier('str2'), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - DeviceIdentifier('str') == DeviceIdentifier('str'), - isTrue, - ); - }, - ); - - test( - 'returns true if they are equal ignoring case', - () { - expect( - DeviceIdentifier('str') == DeviceIdentifier('STR'), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toString', - () { - test( - 'returns the str property', - () { - expect( - DeviceIdentifier('str').toString(), - equals('str'), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart deleted file mode 100644 index 3ec20d5a..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart +++ /dev/null @@ -1,366 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'Guid', - () { - group( - 'empty', - () { - test( - 'constructs an instance', - () { - expect( - Guid.empty().bytes, - equals([ - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - ]), - ); - }, - ); - }, - ); - - group( - 'fromBytes', - () { - test( - 'constructs an instance from a list of 2 bytes', - () { - expect( - Guid.fromBytes([ - 0x01, - 0x02, - ]).bytes, - equals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'constructs an instance from a list of 4 bytes', - () { - expect( - Guid.fromBytes([ - 0x01, - 0x02, - 0x03, - 0x04, - ]).bytes, - equals([ - 0x01, - 0x02, - 0x03, - 0x04, - ]), - ); - }, - ); - - test( - 'constructs an instance from a list of 16 bytes', - () { - expect( - Guid.fromBytes([ - 0x01, - 0x02, - 0x03, - 0x04, - 0x00, - 0x00, - 0x10, - 0x00, - 0x80, - 0x00, - 0x00, - 0x80, - 0x5F, - 0x9B, - 0x34, - 0xFB, - ]).bytes, - equals([ - 0x01, - 0x02, - 0x03, - 0x04, - 0x00, - 0x00, - 0x10, - 0x00, - 0x80, - 0x00, - 0x00, - 0x80, - 0x5F, - 0x9B, - 0x34, - 0xFB, - ]), - ); - }, - ); - - test( - 'throws a format exception if the list is not 2 nor 4 nor 16 bytes in length', - () { - expect( - () { - Guid.fromBytes([ - 0x01, - 0x02, - 0x03, - ]); - }, - throwsFormatException, - ); - }, - ); - }, - ); - - group( - 'fromString', - () { - test( - 'constructs an instance from a string of 2 bytes', - () { - expect( - Guid.fromString('0102').bytes, - equals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'constructs an instance from a string of 4 bytes', - () { - expect( - Guid.fromString('01020304').bytes, - equals([ - 0x01, - 0x02, - 0x03, - 0x04, - ]), - ); - }, - ); - - test( - 'constructs an instance from a string of 16 bytes', - () { - expect( - Guid.fromString('0102030400001000800000805f9b34fb').bytes, - equals([ - 0x01, - 0x02, - 0x03, - 0x04, - 0x00, - 0x00, - 0x10, - 0x00, - 0x80, - 0x00, - 0x00, - 0x80, - 0x5F, - 0x9B, - 0x34, - 0xFB, - ]), - ); - }, - ); - - test( - 'constructs an instance from a uuid formatted string', - () { - expect( - Guid.fromString('01020304-0000-1000-8000-00805f9b34fb').bytes, - equals([ - 0x01, - 0x02, - 0x03, - 0x04, - 0x00, - 0x00, - 0x10, - 0x00, - 0x80, - 0x00, - 0x00, - 0x80, - 0x5F, - 0x9B, - 0x34, - 0xFB, - ]), - ); - }, - ); - - test( - 'throws a format exception if the string is not 2 nor 4 nor 16 bytes in length', - () { - expect( - () { - Guid.fromString('010203'); - }, - throwsFormatException, - ); - }, - ); - }, - ); - }, - ); - - group( - 'str', - () { - test( - 'returns a string of 2 bytes if the list of bytes is 2 bytes in length', - () { - expect( - Guid('0102').str, - equals('0102'), - ); - }, - ); - - test( - 'returns a string of 4 bytes if the list of bytes is 4 bytes in length', - () { - expect( - Guid('01020304').str, - equals('01020304'), - ); - }, - ); - - test( - 'returns a string of 16 bytes if the list of bytes is 16 bytes in length and does not end with the suffix', - () { - expect( - Guid('01020304-0000-0000-0000-000000000000').str, - equals('01020304-0000-0000-0000-000000000000'), - ); - }, - ); - - test( - 'returns a string of 4 bytes if the list of bytes is 16 bytes in length and ends with the suffix', - () { - expect( - Guid('01020304-0000-1000-8000-00805f9b34fb').str, - equals('01020304'), - ); - }, - ); - }, - ); - - group( - 'str128', - () { - test( - 'returns a string of 16 bytes if the list of bytes is 2 bytes in length', - () { - expect( - Guid('0102').str128, - equals('00000102-0000-1000-8000-00805f9b34fb'), - ); - }, - ); - - test( - 'returns a string of 16 bytes if the list of bytes is 4 bytes in length', - () { - expect( - Guid('01020304').str128, - equals('01020304-0000-1000-8000-00805f9b34fb'), - ); - }, - ); - - test( - 'returns a string of 16 bytes if the list of bytes is 16 bytes in length', - () { - expect( - Guid('01020304-0000-1000-8000-00805f9b34fb').str128, - equals('01020304-0000-1000-8000-00805f9b34fb'), - ); - }, - ); - }, - ); - - group( - 'uuid', - () { - test( - 'returns the str property', - () { - expect( - Guid('0102').uuid, - equals('0102'), - ); - }, - ); - }, - ); - - group( - 'uuid128', - () { - test( - 'returns the str128 property', - () { - expect( - Guid('0102').uuid128, - equals('00000102-0000-1000-8000-00805f9b34fb'), - ); - }, - ); - }, - ); - - group( - 'toString', - () { - test( - 'returns the str property', - () { - expect( - Guid('0102').toString(), - equals('0102'), - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/options_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/options_test.dart deleted file mode 100644 index 9a9e4ee5..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/options_test.dart +++ /dev/null @@ -1,104 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'Options', - () { - group( - 'fromMap', - () { - test( - 'deserializes the show power alert property', - () { - final showPowerAlert = false; - - expect( - Options.fromMap({ - 'show_power_alert': showPowerAlert, - }).showPowerAlert, - equals(showPowerAlert), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final showPowerAlert = false; - - expect( - Options( - showPowerAlert: showPowerAlert, - ).hashCode, - equals(showPowerAlert.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - Options( - showPowerAlert: false, - ) == - Options( - showPowerAlert: true, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - Options( - showPowerAlert: false, - ) == - Options( - showPowerAlert: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the show power alert property', - () { - final showPowerAlert = false; - - expect( - Options( - showPowerAlert: showPowerAlert, - ).toMap(), - containsPair( - 'show_power_alert', - equals(showPowerAlert), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart deleted file mode 100644 index 97d72772..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart +++ /dev/null @@ -1,145 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'PhySupport', - () { - group( - 'fromMap', - () { - test( - 'deserializes the le 2m property', - () { - final le2M = false; - - expect( - PhySupport.fromMap({ - 'le_2M': le2M, - 'le_coded': false, - }).le2M, - equals(le2M), - ); - }, - ); - - test( - 'deserializes the le coded property', - () { - final leCoded = false; - - expect( - PhySupport.fromMap({ - 'le_2M': false, - 'le_coded': leCoded, - }).leCoded, - equals(leCoded), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final le2M = false; - final leCoded = false; - - expect( - PhySupport( - le2M: le2M, - leCoded: leCoded, - ).hashCode, - equals(le2M.hashCode ^ leCoded.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - PhySupport( - le2M: false, - leCoded: false, - ) == - PhySupport( - le2M: true, - leCoded: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - PhySupport( - le2M: false, - leCoded: false, - ) == - PhySupport( - le2M: false, - leCoded: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the le 2m property', - () { - final le2M = false; - - expect( - PhySupport( - le2M: le2M, - leCoded: false, - ).toMap(), - containsPair( - 'le_2M', - equals(le2M), - ), - ); - }, - ); - - test( - 'serializes the le coded property', - () { - final leCoded = false; - - expect( - PhySupport( - le2M: false, - leCoded: leCoded, - ).toMap(), - containsPair( - 'le_coded', - equals(leCoded), - ), - ); - }, - ); - }, - ); - }, - ); -} From d8c6e6dca09a6fc4bb995608fc13b6fb62552ec6 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:40 +0100 Subject: [PATCH 45/90] Revert "test: remove tests from platform interface" This reverts commit 28f2e96fc079bb750e7910b263b2498e7529f402. --- ...method_channel_flutter_blue_plus_test.dart | 2038 +++++++++++++++++ .../bm_bluetooth_adapter_state_test.dart | 118 + .../bm_bluetooth_characteristic_test.dart | 567 +++++ .../types/bm_bluetooth_descriptor_test.dart | 244 ++ .../test/types/bm_bluetooth_service_test.dart | 432 ++++ .../types/bm_bond_state_response_test.dart | 104 + .../types/bm_characteristic_data_test.dart | 493 ++++ .../bm_characteristic_properties_test.dart | 384 ++++ .../bm_connection_priority_request_test.dart | 60 + .../bm_connection_state_response_test.dart | 60 + .../test/types/bm_descriptor_data_test.dart | 563 +++++ .../test/types/bm_devices_list_test.dart | 26 + .../bm_discover_services_result_test.dart | 312 +++ .../test/types/bm_msd_filter_test.dart | 208 ++ .../types/bm_mtu_changed_response_test.dart | 62 + .../bm_read_characteristic_request_test.dart | 252 ++ .../bm_read_descriptor_request_test.dart | 305 +++ .../test/types/bm_read_rssi_result_test.dart | 62 + .../types/bm_scan_advertisement_test.dart | 497 ++++ .../test/types/bm_scan_response_test.dart | 260 +++ .../test/types/bm_scan_settings_test.dart | 574 +++++ .../types/bm_service_data_filter_test.dart | 211 ++ .../bm_set_notify_value_request_test.dart | 284 +++ .../test/types/bm_turn_on_response_test.dart | 112 + .../bm_write_characteristic_request_test.dart | 471 ++++ .../bm_write_descriptor_request_test.dart | 379 +++ .../test/types/device_identifier_test.dart | 109 + .../test/types/guid_test.dart | 366 +++ .../test/types/options_test.dart | 104 + .../test/types/phy_support_test.dart | 145 ++ 30 files changed, 9802 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/options_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart new file mode 100644 index 00000000..c799341b --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart @@ -0,0 +1,2038 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/method_channel/method_channel_flutter_blue_plus.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group( + 'MethodChannelFlutterBluePlus', + () { + final flutterBluePlus = MethodChannelFlutterBluePlus(); + final log = []; + + Future? Function(MethodCall call)? methodCallHandler; + + group( + 'onAdapterStateChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ).toMap(); + + expectLater( + flutterBluePlus.onAdapterStateChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnAdapterStateChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ).toMap(); + + expectLater( + flutterBluePlus.onAdapterStateChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnAdapterStateChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onBondStateChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmBondStateResponse( + remoteId: DeviceIdentifier('str'), + bondState: BmBondStateEnum.none, + ).toMap(); + + expectLater( + flutterBluePlus.onBondStateChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnBondStateChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmBondStateResponse( + remoteId: DeviceIdentifier('str'), + bondState: BmBondStateEnum.none, + ).toMap(); + + expectLater( + flutterBluePlus.onBondStateChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnBondStateChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onCharacteristicReceived', + () { + test( + 'deserializes the event', + () async { + final arguments = BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onCharacteristicReceived.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnCharacteristicReceived', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onCharacteristicReceived, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnCharacteristicReceived', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onCharacteristicWritten', + () { + test( + 'deserializes the event', + () async { + final arguments = BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onCharacteristicWritten.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnCharacteristicWritten', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onCharacteristicWritten, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnCharacteristicWritten', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onConnectionStateChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmConnectionStateResponse( + remoteId: DeviceIdentifier('str'), + connectionState: BmConnectionStateEnum.disconnected, + ).toMap(); + + expectLater( + flutterBluePlus.onConnectionStateChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnConnectionStateChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmConnectionStateResponse( + remoteId: DeviceIdentifier('str'), + connectionState: BmConnectionStateEnum.disconnected, + ).toMap(); + + expectLater( + flutterBluePlus.onConnectionStateChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnConnectionStateChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onDescriptorRead', + () { + test( + 'deserializes the event', + () async { + final arguments = BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDescriptorRead.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDescriptorRead', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDescriptorRead, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDescriptorRead', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onDescriptorWritten', + () { + test( + 'deserializes the event', + () async { + final arguments = BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDescriptorWritten.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDescriptorWritten', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDescriptorWritten, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDescriptorWritten', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onDetachedFromEngine', + () { + test( + 'handles the method call', + () async { + expectLater( + flutterBluePlus.onDetachedFromEngine, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDetachedFromEngine', + ), + ); + }, + ); + }, + ); + + group( + 'onDiscoveredServices', + () { + test( + 'deserializes the event', + () async { + final arguments = BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDiscoveredServices.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDiscoveredServices', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onDiscoveredServices, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnDiscoveredServices', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onMtuChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmMtuChangedResponse( + remoteId: DeviceIdentifier('str'), + mtu: 0, + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onMtuChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnMtuChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmMtuChangedResponse( + remoteId: DeviceIdentifier('str'), + mtu: 0, + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onMtuChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnMtuChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onNameChanged', + () { + test( + 'deserializes the event', + () async { + final arguments = BmNameChanged( + remoteId: DeviceIdentifier('str'), + name: '', + ).toMap(); + + expectLater( + flutterBluePlus.onNameChanged.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnNameChanged', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmNameChanged( + remoteId: DeviceIdentifier('str'), + name: '', + ).toMap(); + + expectLater( + flutterBluePlus.onNameChanged, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnNameChanged', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onReadRssi', + () { + test( + 'deserializes the event', + () async { + final arguments = BmReadRssiResult( + remoteId: DeviceIdentifier('str'), + rssi: 0, + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onReadRssi.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnReadRssi', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmReadRssiResult( + remoteId: DeviceIdentifier('str'), + rssi: 0, + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onReadRssi, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnReadRssi', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onScanResponse', + () { + test( + 'deserializes the event', + () async { + final arguments = BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onScanResponse.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnScanResponse', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(); + + expectLater( + flutterBluePlus.onScanResponse, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnScanResponse', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onServicesReset', + () { + test( + 'deserializes the event', + () async { + final arguments = BmBluetoothDevice( + remoteId: DeviceIdentifier('str'), + ).toMap(); + + expectLater( + flutterBluePlus.onServicesReset.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnServicesReset', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmBluetoothDevice( + remoteId: DeviceIdentifier('str'), + ).toMap(); + + expectLater( + flutterBluePlus.onServicesReset, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnServicesReset', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'onServicesReset', + () { + test( + 'deserializes the event', + () async { + final arguments = BmTurnOnResponse( + userAccepted: true, + ).toMap(); + + expectLater( + flutterBluePlus.onTurnOnResponse.map( + (event) { + return event.toMap(); + }, + ), + emits(equals(arguments)), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnTurnOnResponse', + arguments, + ), + ); + }, + ); + + test( + 'handles the method call', + () async { + final arguments = BmTurnOnResponse( + userAccepted: true, + ).toMap(); + + expectLater( + flutterBluePlus.onTurnOnResponse, + emits(anything), + ); + + await flutterBluePlus.handleMethodCall( + MethodCall( + 'OnTurnOnResponse', + arguments, + ), + ); + }, + ); + }, + ); + + group( + 'clearGattCache', + () { + test( + 'invokes the method', + () async { + final device = DeviceIdentifier('str'); + + await flutterBluePlus.clearGattCache(device); + + expect( + log, + equals([ + isMethodCall( + 'clearGattCache', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'connect', + () { + final result = true; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final request = BmConnectRequest( + remoteId: DeviceIdentifier('str'), + autoConnect: false, + ); + + expect( + await flutterBluePlus.connect(request), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final request = BmConnectRequest( + remoteId: DeviceIdentifier('str'), + autoConnect: false, + ); + + await flutterBluePlus.connect(request); + + expect( + log, + equals([ + isMethodCall( + 'connect', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'connectedCount', + () { + final result = 0; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.connectedCount(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.connectedCount(); + + expect( + log, + equals([ + isMethodCall( + 'connectedCount', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'createBond', + () { + final result = true; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final device = DeviceIdentifier('str'); + + expect( + await flutterBluePlus.createBond(device), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final device = DeviceIdentifier('str'); + + await flutterBluePlus.createBond(device); + + expect( + log, + equals([ + isMethodCall( + 'createBond', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'disconnect', + () { + final result = true; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final device = DeviceIdentifier('str'); + + expect( + await flutterBluePlus.disconnect(device), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final device = DeviceIdentifier('str'); + + await flutterBluePlus.disconnect(device); + + expect( + log, + equals([ + isMethodCall( + 'disconnect', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'discoverServices', + () { + test( + 'invokes the method', + () async { + final device = DeviceIdentifier('str'); + + await flutterBluePlus.discoverServices(device); + + expect( + log, + equals([ + isMethodCall( + 'discoverServices', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'flutterRestart', + () { + final result = 0; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.flutterRestart(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.flutterRestart(); + + expect( + log, + equals([ + isMethodCall( + 'flutterRestart', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getAdapterName', + () { + final result = ''; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.getAdapterName(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getAdapterName(); + + expect( + log, + equals([ + isMethodCall( + 'getAdapterName', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getAdapterState', + () { + final result = BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ); + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + (await flutterBluePlus.getAdapterState()).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getAdapterState(); + + expect( + log, + equals([ + isMethodCall( + 'getAdapterState', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getBondState', + () { + final result = BmBondStateResponse( + remoteId: DeviceIdentifier('str'), + bondState: BmBondStateEnum.none, + ); + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final device = DeviceIdentifier('str'); + + expect( + (await flutterBluePlus.getBondState(device)).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + final device = DeviceIdentifier('str'); + + await flutterBluePlus.getBondState(device); + + expect( + log, + equals([ + isMethodCall( + 'getBondState', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getBondedDevices', + () { + final result = BmDevicesList( + devices: [], + ); + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + (await flutterBluePlus.getBondedDevices()).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getBondedDevices(); + + expect( + log, + equals([ + isMethodCall( + 'getBondedDevices', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getPhySupport', + () { + final result = PhySupport( + le2M: false, + leCoded: false, + ); + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + (await flutterBluePlus.getPhySupport()).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getPhySupport(); + + expect( + log, + equals([ + isMethodCall( + 'getPhySupport', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'getSystemDevices', + () { + final result = BmDevicesList( + devices: [], + ); + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result.toMap()); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + (await flutterBluePlus.getSystemDevices()).toMap(), + equals(result.toMap()), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.getSystemDevices(); + + expect( + log, + equals([ + isMethodCall( + 'getSystemDevices', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'isSupported', + () { + final result = true; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.isSupported(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.isSupported(); + + expect( + log, + equals([ + isMethodCall( + 'isSupported', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'readCharacteristic', + () { + test( + 'invokes the method', + () async { + final request = BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ); + + await flutterBluePlus.readCharacteristic(request); + + expect( + log, + equals([ + isMethodCall( + 'readCharacteristic', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'readDescriptor', + () { + test( + 'invokes the method', + () async { + final request = BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ); + + await flutterBluePlus.readDescriptor(request); + + expect( + log, + equals([ + isMethodCall( + 'readDescriptor', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'readRssi', + () { + test( + 'invokes the method', + () async { + final device = DeviceIdentifier('str'); + + await flutterBluePlus.readRssi(device); + + expect( + log, + equals([ + isMethodCall( + 'readRssi', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'removeBond', + () { + final result = true; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final device = DeviceIdentifier('str'); + + expect( + await flutterBluePlus.removeBond(device), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final device = DeviceIdentifier('str'); + + await flutterBluePlus.removeBond(device); + + expect( + log, + equals([ + isMethodCall( + 'removeBond', + arguments: device.str, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'requestConnectionPriority', + () { + test( + 'invokes the method', + () async { + final request = BmConnectionPriorityRequest( + remoteId: DeviceIdentifier('str'), + connectionPriority: BmConnectionPriorityEnum.balanced, + ); + + await flutterBluePlus.requestConnectionPriority(request); + + expect( + log, + equals([ + isMethodCall( + 'requestConnectionPriority', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'requestMtu', + () { + test( + 'invokes the method', + () async { + final request = BmMtuChangeRequest( + remoteId: DeviceIdentifier('str'), + mtu: 0, + ); + + await flutterBluePlus.requestMtu(request); + + expect( + log, + equals([ + isMethodCall( + 'requestMtu', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'setLogLevel', + () { + test( + 'invokes the method', + () async { + final level = LogLevel.none; + + await flutterBluePlus.setLogLevel(level); + + expect( + log, + equals([ + isMethodCall( + 'setLogLevel', + arguments: level.index, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'setNotifyValue', + () { + final result = true; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + final request = BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ); + + expect( + await flutterBluePlus.setNotifyValue(request), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + final request = BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ); + + await flutterBluePlus.setNotifyValue(request); + + expect( + log, + equals([ + isMethodCall( + 'setNotifyValue', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'setOptions', + () { + test( + 'invokes the method', + () async { + final options = Options( + showPowerAlert: false, + ); + + await flutterBluePlus.setOptions(options); + + expect( + log, + equals([ + isMethodCall( + 'setOptions', + arguments: options.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'setPreferredPhy', + () { + test( + 'invokes the method', + () async { + final preferredPhy = BmPreferredPhy( + remoteId: DeviceIdentifier('str'), + txPhy: 0, + rxPhy: 0, + phyOptions: 0, + ); + + await flutterBluePlus.setPreferredPhy(preferredPhy); + + expect( + log, + equals([ + isMethodCall( + 'setPreferredPhy', + arguments: preferredPhy.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'startScan', + () { + test( + 'invokes the method', + () async { + final settings = BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ); + + await flutterBluePlus.startScan(settings); + + expect( + log, + equals([ + isMethodCall( + 'startScan', + arguments: settings.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'stopScan', + () { + test( + 'invokes the method', + () async { + await flutterBluePlus.stopScan(); + + expect( + log, + equals([ + isMethodCall( + 'stopScan', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'turnOff', + () { + test( + 'invokes the method', + () async { + await flutterBluePlus.turnOff(); + + expect( + log, + equals([ + isMethodCall( + 'turnOff', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'turnOn', + () { + final result = true; + + setUp( + () { + methodCallHandler = (call) { + return Future.value(result); + }; + }, + ); + + tearDown( + () { + methodCallHandler = null; + }, + ); + + test( + 'deserializes the result', + () async { + expect( + await flutterBluePlus.turnOn(), + equals(result), + ); + }, + ); + + test( + 'invokes the method', + () async { + await flutterBluePlus.turnOn(); + + expect( + log, + equals([ + isMethodCall( + 'turnOn', + arguments: null, + ), + ]), + ); + }, + ); + }, + ); + + group( + 'writeCharacteristic', + () { + test( + 'invokes the method', + () async { + final request = BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ); + + await flutterBluePlus.writeCharacteristic(request); + + expect( + log, + equals([ + isMethodCall( + 'writeCharacteristic', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + group( + 'writeDescriptor', + () { + test( + 'invokes the method', + () async { + final request = BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ); + + await flutterBluePlus.writeDescriptor(request); + + expect( + log, + equals([ + isMethodCall( + 'writeDescriptor', + arguments: request.toMap(), + ), + ]), + ); + }, + ); + }, + ); + + setUp( + () { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler( + flutterBluePlus.channel, + (call) { + log.add(call); + + return methodCallHandler?.call(call); + }, + ); + }, + ); + + tearDown( + () { + log.clear(); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart new file mode 100644 index 00000000..4bc542ec --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart @@ -0,0 +1,118 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBluetoothAdapterState', + () { + group( + 'fromMap', + () { + test( + 'deserializes the adapter state property', + () { + final adapterState = BmAdapterStateEnum.unknown; + + expect( + BmBluetoothAdapterState.fromMap({ + 'adapter_state': adapterState.index, + }).adapterState, + equals(adapterState), + ); + }, + ); + + test( + 'throws a range error if the adapter state property index is out of range', + () { + expect( + () { + BmBluetoothAdapterState.fromMap({ + 'adapter_state': 7, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final adapterState = BmAdapterStateEnum.unknown; + + expect( + BmBluetoothAdapterState( + adapterState: adapterState, + ).hashCode, + equals(adapterState.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ) == + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unavailable, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ) == + BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.unknown, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the adapter state property', + () { + final adapterState = BmAdapterStateEnum.unknown; + + expect( + BmBluetoothAdapterState( + adapterState: adapterState, + ).toMap(), + containsPair( + 'adapter_state', + equals(adapterState.index), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart new file mode 100644 index 00000000..48f71e75 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart @@ -0,0 +1,567 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBluetoothCharacteristic', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptors': [], + 'properties': {}, + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptors property', + () { + final descriptors = [ + { + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }, + ]; + + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptors': descriptors, + 'properties': {}, + }).descriptors, + equals( + descriptors.map( + (descriptor) { + return BmBluetoothDescriptor.fromMap(descriptor); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the descriptors property as [] if it is null', + () { + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptors': null, + 'properties': {}, + }).descriptors, + equals([]), + ); + }, + ); + + test( + 'deserializes the properties property properties as false if it is null', + () { + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptors': [], + 'properties': null, + }).properties, + equals( + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': remoteId, + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptors': [], + 'properties': {}, + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'descriptors': [], + 'properties': {}, + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptors': [], + 'properties': {}, + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmBluetoothCharacteristic.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptors': [], + 'properties': {}, + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final descriptors = []; + final properties = BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ); + + expect( + BmBluetoothCharacteristic( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + descriptors: descriptors, + properties: properties, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality() + .hash(descriptors) ^ + properties.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ) == + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ) == + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the descriptors property', + () { + final descriptors = [ + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + ]; + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: descriptors, + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'descriptors', + equals( + descriptors.map( + (descriptor) { + return descriptor.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the properties property', + () { + final properties = BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ); + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: properties, + ).toMap(), + containsPair( + 'properties', + equals(properties.toMap()), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmBluetoothCharacteristic( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart new file mode 100644 index 00000000..a94a835c --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart @@ -0,0 +1,244 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBluetoothDescriptor', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmBluetoothDescriptor.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptor_uuid': '0102', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptor uuid property', + () { + final descriptorUuid = '0102'; + + expect( + BmBluetoothDescriptor.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': descriptorUuid, + }).descriptorUuid, + equals(Guid(descriptorUuid)), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmBluetoothDescriptor.fromMap({ + 'remote_id': remoteId, + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmBluetoothDescriptor.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final characteristicUuid = Guid('0102'); + final descriptorUuid = Guid('0102'); + + expect( + BmBluetoothDescriptor( + remoteId: remoteId, + serviceUuid: serviceUuid, + characteristicUuid: characteristicUuid, + descriptorUuid: descriptorUuid, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str1'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ) == + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str2'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ) == + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the descriptor uuid property', + () { + final descriptorUuid = Guid('0102'); + + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: descriptorUuid, + ).toMap(), + containsPair( + 'descriptor_uuid', + equals(descriptorUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmBluetoothDescriptor( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmBluetoothDescriptor( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart new file mode 100644 index 00000000..98c18c2c --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart @@ -0,0 +1,432 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBluetoothService', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristics property', + () { + final characteristics = [ + { + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'descriptors': [], + 'properties': {}, + }, + ]; + + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': characteristics, + 'included_services': [], + }).characteristics, + equals( + characteristics.map( + (characteristic) { + return BmBluetoothCharacteristic.fromMap(characteristic); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the characteristics property as [] if it is null', + () { + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': null, + 'included_services': [], + }).characteristics, + equals([]), + ); + }, + ); + + test( + 'deserializes the included services property', + () { + final includedServices = [ + { + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': [], + }, + ]; + + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': includedServices, + }).includedServices, + equals( + includedServices.map( + (includedService) { + return BmBluetoothService.fromMap(includedService); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the included services property as [] if it is null', + () { + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': null, + }).includedServices, + equals([]), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmBluetoothService.fromMap({ + 'remote_id': remoteId, + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': null, + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'is_primary': 1, + 'characteristics': [], + 'included_services': null, + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + + test( + 'deserializes the is primary property as false if it is not 1', + () { + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 0, + 'characteristics': [], + 'included_services': null, + }).isPrimary, + isFalse, + ); + }, + ); + + test( + 'deserializes the is primary property as true if it is 1', + () { + expect( + BmBluetoothService.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': null, + }).isPrimary, + isTrue, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final isPrimary = true; + final characteristics = []; + final includedServices = []; + + expect( + BmBluetoothService( + remoteId: remoteId, + serviceUuid: serviceUuid, + isPrimary: isPrimary, + characteristics: characteristics, + includedServices: includedServices, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + isPrimary.hashCode ^ + const ListEquality() + .hash(characteristics) ^ + const ListEquality() + .hash(includedServices), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ) == + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: false, + characteristics: [], + includedServices: [], + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ) == + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristics property', + () { + final characteristics = [ + BmBluetoothCharacteristic( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptors: [], + properties: BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + ]; + + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: characteristics, + includedServices: [], + ).toMap(), + containsPair( + 'characteristics', + equals( + characteristics.map( + (characteristic) { + return characteristic.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the included services property', + () { + final includedServices = [ + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ), + ]; + + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: includedServices, + ).toMap(), + containsPair( + 'included_services', + equals( + includedServices.map( + (includedService) { + return includedService.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the is primary property as 0 if it is false', + () { + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: false, + characteristics: [], + includedServices: [], + ).toMap(), + containsPair( + 'is_primary', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the is primary property as 1 if it is true', + () { + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ).toMap(), + containsPair( + 'is_primary', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmBluetoothService( + remoteId: remoteId, + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + isPrimary: true, + characteristics: [], + includedServices: [], + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart new file mode 100644 index 00000000..b3d893c2 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart @@ -0,0 +1,104 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmBondStateResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the bond state property', + () { + expect( + BmBondStateResponse.fromMap({ + 'remote_id': 'str', + 'bond_state': 0, + }).bondState, + equals(BmBondStateEnum.none), + ); + }, + ); + + test( + 'deserializes the prev state property', + () { + expect( + BmBondStateResponse.fromMap({ + 'remote_id': 'str', + 'bond_state': 0, + 'prev_state': 0, + }).prevState, + equals(BmBondStateEnum.none), + ); + }, + ); + + test( + 'throws a range error if the bond state property index is out of range', + () { + expect( + () { + BmBondStateResponse.fromMap({ + 'remote_id': 'str', + 'bond_state': 3, + }); + }, + throwsRangeError, + ); + }, + ); + + test( + 'throws a range error if the prev state property index is out of range', + () { + expect( + () { + BmBondStateResponse.fromMap({ + 'remote_id': 'str', + 'bond_state': 0, + 'prev_state': 3, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the bond state property', + () { + expect( + BmBondStateResponse( + remoteId: DeviceIdentifier('str'), + bondState: BmBondStateEnum.none, + ).toMap(), + containsPair('bond_state', 0), + ); + }, + ); + + test( + 'serializes the prev state property', + () { + expect( + BmBondStateResponse( + remoteId: DeviceIdentifier('str'), + bondState: BmBondStateEnum.none, + prevState: BmBondStateEnum.none, + ).toMap(), + containsPair('prev_state', 0), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart new file mode 100644 index 00000000..5b07e287 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart @@ -0,0 +1,493 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmCharacteristicData', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmCharacteristicData.fromMap({ + 'remote_id': remoteId, + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'value': '', + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'value': '', + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'value': '', + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the value property', + () { + final value = '010203'; + + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'value': value, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).value, + equals(hex.decode(value)), + ); + }, + ); + + test( + 'deserializes the value property as [] if it is null', + () { + expect( + BmCharacteristicData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'value': null, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).value, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final value = []; + final success = true; + final errorCode = 0; + final errorString = ''; + + expect( + BmCharacteristicData( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + value: value, + success: success, + errorCode: errorCode, + errorString: errorString, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: false, + errorCode: 0, + errorString: '', + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmCharacteristicData( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: false, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the value property', + () { + final value = [0x01, 0x02, 0x03]; + + expect( + BmCharacteristicData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + value: value, + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'value', + hex.encode(value), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart new file mode 100644 index 00000000..75301ba1 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart @@ -0,0 +1,384 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmCharacteristicProperties', + () { + group( + 'fromMap', + () { + test( + 'deserializes the properties as false if they are not 1', + () { + expect( + BmCharacteristicProperties.fromMap({ + 'broadcast': 0, + 'read': 0, + 'write_without_response': 0, + 'write': 0, + 'notify': 0, + 'indicate': 0, + 'authenticated_signed_writes': 0, + 'extended_properties': 0, + 'notify_encryption_required': 0, + 'indicate_encryption_required': 0, + }), + equals( + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ), + ); + }, + ); + + test( + 'deserializes the properties as true if they are 1', + () { + expect( + BmCharacteristicProperties.fromMap({ + 'broadcast': 1, + 'read': 1, + 'write_without_response': 1, + 'write': 1, + 'notify': 1, + 'indicate': 1, + 'authenticated_signed_writes': 1, + 'extended_properties': 1, + 'notify_encryption_required': 1, + 'indicate_encryption_required': 1, + }), + equals( + BmCharacteristicProperties( + broadcast: true, + read: true, + writeWithoutResponse: true, + write: true, + notify: true, + indicate: true, + authenticatedSignedWrites: true, + extendedProperties: true, + notifyEncryptionRequired: true, + indicateEncryptionRequired: true, + ), + ), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final broadcast = false; + final read = false; + final writeWithoutResponse = false; + final write = false; + final notify = false; + final indicate = false; + final authenticatedSignedWrites = false; + final extendedProperties = false; + final notifyEncryptionRequired = false; + final indicateEncryptionRequired = false; + + expect( + BmCharacteristicProperties( + broadcast: broadcast, + read: read, + writeWithoutResponse: writeWithoutResponse, + write: write, + notify: notify, + indicate: indicate, + authenticatedSignedWrites: authenticatedSignedWrites, + extendedProperties: extendedProperties, + notifyEncryptionRequired: notifyEncryptionRequired, + indicateEncryptionRequired: indicateEncryptionRequired, + ).hashCode, + equals( + broadcast.hashCode ^ + read.hashCode ^ + writeWithoutResponse.hashCode ^ + write.hashCode ^ + notify.hashCode ^ + indicate.hashCode ^ + authenticatedSignedWrites.hashCode ^ + extendedProperties.hashCode ^ + notifyEncryptionRequired.hashCode ^ + indicateEncryptionRequired.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ) == + BmCharacteristicProperties( + broadcast: true, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ) == + BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the properties as 0 if they are false', + () { + final map = BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ).toMap(); + + expect( + map, + containsPair( + 'broadcast', + equals(0), + ), + ); + expect( + map, + containsPair( + 'read', + equals(0), + ), + ); + expect( + map, + containsPair( + 'write_without_response', + equals(0), + ), + ); + expect( + map, + containsPair( + 'write', + equals(0), + ), + ); + expect( + map, + containsPair( + 'notify', + equals(0), + ), + ); + expect( + map, + containsPair( + 'indicate', + equals(0), + ), + ); + expect( + map, + containsPair( + 'authenticated_signed_writes', + equals(0), + ), + ); + expect( + map, + containsPair( + 'extended_properties', + equals(0), + ), + ); + expect( + map, + containsPair( + 'notify_encryption_required', + equals(0), + ), + ); + expect( + map, + containsPair( + 'indicate_encryption_required', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the properties as 1 if they are true', + () { + final map = BmCharacteristicProperties( + broadcast: true, + read: true, + writeWithoutResponse: true, + write: true, + notify: true, + indicate: true, + authenticatedSignedWrites: true, + extendedProperties: true, + notifyEncryptionRequired: true, + indicateEncryptionRequired: true, + ).toMap(); + + expect( + map, + containsPair( + 'broadcast', + equals(1), + ), + ); + expect( + map, + containsPair( + 'read', + equals(1), + ), + ); + expect( + map, + containsPair( + 'write_without_response', + equals(1), + ), + ); + expect( + map, + containsPair( + 'write', + equals(1), + ), + ); + expect( + map, + containsPair( + 'notify', + equals(1), + ), + ); + expect( + map, + containsPair( + 'indicate', + equals(1), + ), + ); + expect( + map, + containsPair( + 'authenticated_signed_writes', + equals(1), + ), + ); + expect( + map, + containsPair( + 'extended_properties', + equals(1), + ), + ); + expect( + map, + containsPair( + 'notify_encryption_required', + equals(1), + ), + ); + expect( + map, + containsPair( + 'indicate_encryption_required', + equals(1), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart new file mode 100644 index 00000000..46d33333 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart @@ -0,0 +1,60 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmConnectionPriorityRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the connection priority property', + () { + expect( + BmConnectionPriorityRequest.fromMap({ + 'remote_id': 'str', + 'connection_priority': 0, + }).connectionPriority, + equals(BmConnectionPriorityEnum.balanced), + ); + }, + ); + + test( + 'throws a range error if the connection priority property index is out of range', + () { + expect( + () { + BmConnectionPriorityRequest.fromMap({ + 'remote_id': 'str', + 'connection_priority': 3, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the connection priority property', + () { + expect( + BmConnectionPriorityRequest( + remoteId: DeviceIdentifier('str'), + connectionPriority: BmConnectionPriorityEnum.balanced, + ).toMap(), + containsPair('connection_priority', 0), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart new file mode 100644 index 00000000..4a33d69c --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart @@ -0,0 +1,60 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmConnectionStateResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the connection state property', + () { + expect( + BmConnectionStateResponse.fromMap({ + 'remote_id': 'str', + 'connection_state': 0, + }).connectionState, + equals(BmConnectionStateEnum.disconnected), + ); + }, + ); + + test( + 'throws a range error if the connection state property index is out of range', + () { + expect( + () { + BmConnectionStateResponse.fromMap({ + 'remote_id': 'str', + 'connection_state': 2, + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the connection state property', + () { + expect( + BmConnectionStateResponse( + remoteId: DeviceIdentifier('str'), + connectionState: BmConnectionStateEnum.disconnected, + ).toMap(), + containsPair('connection_state', 0), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart new file mode 100644 index 00000000..e7096be4 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart @@ -0,0 +1,563 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmDescriptorData', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptor uuid property', + () { + final descriptorUuid = '0102'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': descriptorUuid, + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).descriptorUuid, + equals(Guid(descriptorUuid)), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': remoteId, + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the value property', + () { + final value = '010203'; + + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': value, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).value, + equals(hex.decode(value)), + ); + }, + ); + + test( + 'deserializes the value property as [] if it is null', + () { + expect( + BmDescriptorData.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': null, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).value, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final descriptorUuid = Guid('0102'); + final value = []; + final success = true; + final errorCode = 0; + final errorString = ''; + + expect( + BmDescriptorData( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + descriptorUuid: descriptorUuid, + value: value, + success: success, + errorCode: errorCode, + errorString: errorString, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: false, + errorCode: 0, + errorString: '', + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the descriptor uuid property', + () { + final descriptorUuid = Guid('0102'); + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: descriptorUuid, + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'descriptor_uuid', + equals(descriptorUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmDescriptorData( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: false, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the value property', + () { + final value = [0x01, 0x02, 0x03]; + + expect( + BmDescriptorData( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: value, + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'value', + hex.encode(value), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart new file mode 100644 index 00000000..0beef270 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart @@ -0,0 +1,26 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmDevicesList', + () { + group( + 'fromMap', + () { + test( + 'deserializes the devices property as [] if it is null', + () { + expect( + BmDevicesList.fromMap({ + 'devices': null, + }).devices, + equals([]), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart new file mode 100644 index 00000000..d7df6914 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart @@ -0,0 +1,312 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmDiscoverServicesResult', + () { + group( + 'fromMap', + () { + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': remoteId, + 'services': [], + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the services property', + () { + final services = [ + { + 'remote_id': 'str', + 'service_uuid': '0102', + 'is_primary': 1, + 'characteristics': [], + 'included_services': [], + } + ]; + + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': 'str', + 'services': services, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).services, + equals( + services.map( + (service) { + return BmBluetoothService.fromMap(service); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the services property as [] if it is null', + () { + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': 'str', + 'services': null, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).services, + equals([]), + ); + }, + ); + + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': 'str', + 'services': [], + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': 'str', + 'services': [], + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmDiscoverServicesResult.fromMap({ + 'remote_id': 'str', + 'services': [], + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final services = []; + final success = true; + final errorCode = 0; + final errorString = ''; + + expect( + BmDiscoverServicesResult( + remoteId: remoteId, + services: services, + success: success, + errorCode: errorCode, + errorString: errorString, + ).hashCode, + equals( + remoteId.hashCode ^ + const ListEquality().hash(services) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: false, + errorCode: 0, + errorString: '', + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmDiscoverServicesResult( + remoteId: remoteId, + services: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the services property', + () { + final services = [ + BmBluetoothService( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + isPrimary: true, + characteristics: [], + includedServices: [], + ), + ]; + + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: services, + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'services', + equals( + services.map( + (service) { + return service.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: false, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmDiscoverServicesResult( + remoteId: DeviceIdentifier('str'), + services: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(1), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart new file mode 100644 index 00000000..6c482e77 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart @@ -0,0 +1,208 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmMsdFilter', + () { + group( + 'fromMap', + () { + test( + 'deserializes the data property', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': '010203', + 'mask': null, + }).data, + equals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + + test( + 'deserializes the data property as null if it is null', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': null, + 'mask': null, + }).data, + isNull, + ); + }, + ); + + test( + 'deserializes the mask property', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': null, + 'mask': '010203', + }).mask, + equals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + + test( + 'deserializes the mask property as null if it is null', + () { + expect( + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': null, + 'mask': null, + }).mask, + isNull, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final manufacturerId = 0; + final data = []; + final mask = []; + + expect( + BmMsdFilter( + manufacturerId, + data, + mask, + ).hashCode, + equals( + manufacturerId.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmMsdFilter(0, [], []) == BmMsdFilter(1, [], []), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmMsdFilter(0, [], []) == BmMsdFilter(0, [], []), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the data property', + () { + final data = [0x01, 0x02, 0x03]; + + expect( + BmMsdFilter( + 0, + data, + [], + ).toMap(), + containsPair( + 'data', + hex.encode(data), + ), + ); + }, + ); + + test( + 'serializes the data property as null if it is null', + () { + expect( + BmMsdFilter( + 0, + null, + [], + ).toMap(), + containsPair( + 'data', + isNull, + ), + ); + }, + ); + + test( + 'serializes the mask property', + () { + final mask = [0x01, 0x02, 0x03]; + + expect( + BmMsdFilter( + 0, + [], + mask, + ).toMap(), + containsPair( + 'mask', + hex.encode(mask), + ), + ); + }, + ); + + test( + 'serializes the mask property as null if it is null', + () { + expect( + BmMsdFilter( + 0, + [], + null, + ).toMap(), + containsPair( + 'mask', + isNull, + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart new file mode 100644 index 00000000..b2386ec5 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart @@ -0,0 +1,62 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmMtuChangedResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmMtuChangedResponse.fromMap({ + 'remote_id': 'str', + 'mtu': 0, + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmMtuChangedResponse.fromMap({ + 'remote_id': 'str', + 'mtu': 0, + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmMtuChangedResponse.fromMap({ + 'remote_id': 'str', + 'mtu': 0, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart new file mode 100644 index 00000000..415d4a59 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart @@ -0,0 +1,252 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmReadCharacteristicRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmReadCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmReadCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmReadCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmReadCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + + expect( + BmReadCharacteristicRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ) == + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ) == + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmReadCharacteristicRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmReadCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart new file mode 100644 index 00000000..2a1d1479 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart @@ -0,0 +1,305 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmReadDescriptorRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptor_uuid': '0102', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptor uuid property', + () { + final descriptorUuid = '0102'; + + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': descriptorUuid, + }).descriptorUuid, + equals(Guid(descriptorUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmReadDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final descriptorUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + descriptorUuid: descriptorUuid, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ) == + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ) == + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the characteristic uuid property', + () { + final descriptorUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: descriptorUuid, + ).toMap(), + containsPair( + 'descriptor_uuid', + equals(descriptorUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmReadDescriptorRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmReadDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart new file mode 100644 index 00000000..4af76ce0 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart @@ -0,0 +1,62 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmReadRssiResult', + () { + group( + 'fromMap', + () { + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmReadRssiResult.fromMap({ + 'remote_id': 'str', + 'rssi': 0, + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmReadRssiResult.fromMap({ + 'remote_id': 'str', + 'rssi': 0, + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmReadRssiResult.fromMap({ + 'remote_id': 'str', + 'rssi': 0, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart new file mode 100644 index 00000000..75200dd3 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart @@ -0,0 +1,497 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmScanAdvertisement', + () { + group( + 'fromMap', + () { + test( + 'deserializes the connectable property as false if it is not 1', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 0, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': 0, + }).connectable, + isFalse, + ); + }, + ); + + test( + 'deserializes the connectable property as true if it is 1', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': 0, + }).connectable, + isTrue, + ); + }, + ); + + test( + 'deserializes the manufacturer data property', + () { + final manufacturerData = { + 1: '010203', + }; + + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': manufacturerData, + 'service_data': {}, + 'service_uuids': [], + 'rssi': 0, + }).manufacturerData, + equals( + manufacturerData.map( + (key, value) { + return MapEntry(key, hex.decode(value)); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the manufacturer data property as {} if it is null', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': null, + 'service_data': {}, + 'service_uuids': [], + 'rssi': 0, + }).manufacturerData, + equals({}), + ); + }, + ); + + test( + 'deserializes the remote id property', + () { + final remoteId = 'str'; + + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': remoteId, + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': 0, + }).remoteId, + equals(DeviceIdentifier(remoteId)), + ); + }, + ); + + test( + 'deserializes the rssi property', + () { + final rssi = 0; + + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': rssi, + }).rssi, + equals(rssi), + ); + }, + ); + + test( + 'deserializes the rssi property as 0 if it is null', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + 'rssi': null, + }).rssi, + equals(0), + ); + }, + ); + + test( + 'deserializes the service data property', + () { + final serviceData = { + '0102': '010203', + }; + + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': serviceData, + 'service_uuids': [], + 'rssi': 0, + }).serviceData, + equals( + serviceData.map( + (key, value) { + return MapEntry(Guid(key), hex.decode(value)); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the service data property as {} if it is null', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': null, + 'service_uuids': [], + 'rssi': 0, + }).serviceData, + equals({}), + ); + }, + ); + + test( + 'deserializes the service uuids property', + () { + final serviceUuids = [ + '0102', + ]; + + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': serviceUuids, + 'rssi': 0, + }).serviceUuids, + equals( + serviceUuids.map( + (serviceUuid) { + return Guid(serviceUuid); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the service uuids property as [] if it is null', + () { + expect( + BmScanAdvertisement.fromMap({ + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': null, + 'rssi': 0, + }).serviceUuids, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final platformName = null; + final advName = null; + final connectable = true; + final txPowerLevel = 0; + final appearance = 0; + final manufacturerData = >{}; + final serviceData = >{}; + final serviceUuids = []; + final rssi = 0; + + expect( + BmScanAdvertisement( + remoteId: remoteId, + platformName: platformName, + advName: advName, + connectable: connectable, + txPowerLevel: txPowerLevel, + appearance: appearance, + manufacturerData: manufacturerData, + serviceData: serviceData, + serviceUuids: serviceUuids, + rssi: rssi, + ).hashCode, + equals( + remoteId.hashCode ^ + platformName.hashCode ^ + advName.hashCode ^ + connectable.hashCode ^ + txPowerLevel.hashCode ^ + appearance.hashCode ^ + const MapEquality>() + .hash(manufacturerData) ^ + const MapEquality>().hash(serviceData) ^ + const ListEquality().hash(serviceUuids) ^ + rssi.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ) == + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: false, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ) == + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the connectable property as 0 if it is false', + () { + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: false, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'connectable', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the connectable property as 1 if it is true', + () { + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'connectable', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the manufacturer data property', + () { + final manufacturerData = { + 0: [0x01, 0x02, 0x03], + }; + + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: manufacturerData, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'manufacturer_data', + equals( + manufacturerData.map( + (key, value) { + return MapEntry(key, hex.encode(value)); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmScanAdvertisement( + remoteId: remoteId, + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the service data property', + () { + final serviceData = { + Guid('0102'): [0x01, 0x02, 0x03], + }; + + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: serviceData, + serviceUuids: [], + rssi: 0, + ).toMap(), + containsPair( + 'service_data', + equals( + serviceData.map( + (key, value) { + return MapEntry(key.str, hex.encode(value)); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the service uuids property', + () { + final serviceUuids = [ + Guid('0102'), + ]; + + expect( + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: serviceUuids, + rssi: 0, + ).toMap(), + containsPair( + 'service_uuids', + equals( + serviceUuids.map( + (serviceUuid) { + return serviceUuid.str; + }, + ), + ), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart new file mode 100644 index 00000000..34bc770e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart @@ -0,0 +1,260 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmScanResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the advertisements property', + () { + final advertisements = [ + { + 'remote_id': 'str', + 'connectable': 1, + 'manufacturer_data': {}, + 'service_data': {}, + 'service_uuids': [], + } + ]; + + expect( + BmScanResponse.fromMap({ + 'advertisements': advertisements, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).advertisements, + equals( + advertisements.map( + (advertisement) { + return BmScanAdvertisement.fromMap(advertisement); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the advertisements property as [] if it is null', + () { + expect( + BmScanResponse.fromMap({ + 'advertisements': null, + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).advertisements, + equals([]), + ); + }, + ); + + test( + 'deserializes the success property as false if it is 0', + () { + expect( + BmScanResponse.fromMap({ + 'advertisements': [], + 'success': 0, + 'error_code': 0, + 'error_string': '', + }).success, + isFalse, + ); + }, + ); + + test( + 'deserializes the success property as true if it is null', + () { + expect( + BmScanResponse.fromMap({ + 'advertisements': [], + 'success': null, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + + test( + 'deserializes the success property as true if it is not 0', + () { + expect( + BmScanResponse.fromMap({ + 'advertisements': [], + 'success': 1, + 'error_code': 0, + 'error_string': '', + }).success, + isTrue, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final advertisements = []; + final success = true; + final errorCode = 0; + final errorString = ''; + + expect( + BmScanResponse( + advertisements: advertisements, + success: success, + errorCode: errorCode, + errorString: errorString, + ).hashCode, + equals( + const ListEquality() + .hash(advertisements) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmScanResponse( + advertisements: [], + success: false, + errorCode: 0, + errorString: '', + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ) == + BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the services property', + () { + final advertisements = [ + BmScanAdvertisement( + remoteId: DeviceIdentifier('str'), + connectable: true, + manufacturerData: {}, + serviceData: {}, + serviceUuids: [], + rssi: 0, + ), + ]; + + expect( + BmScanResponse( + advertisements: advertisements, + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'advertisements', + equals( + advertisements.map( + (advertisement) { + return advertisement.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmScanResponse( + advertisements: [], + success: false, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmScanResponse( + advertisements: [], + success: true, + errorCode: 0, + errorString: '', + ).toMap(), + containsPair( + 'success', + equals(1), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart new file mode 100644 index 00000000..c90dbcc3 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart @@ -0,0 +1,574 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmScanSettings', + () { + group( + 'fromMap', + () { + test( + 'deserializes the with keywords property', + () { + final withKeywords = [ + 'keyword', + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': withKeywords, + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withKeywords, + equals(withKeywords), + ); + }, + ); + + test( + 'deserializes the with keywords property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': null, + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withKeywords, + equals([]), + ); + }, + ); + + test( + 'deserializes the with msd property', + () { + final withMsd = [ + { + 'manufacturer_id': 0, + 'data': '', + 'mask': '', + }, + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': withMsd, + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withMsd, + equals( + withMsd.map( + (manufacturerData) { + return BmMsdFilter.fromMap(manufacturerData); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the with msd property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': null, + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withMsd, + equals([]), + ); + }, + ); + + test( + 'deserializes the with names property', + () { + final withNames = [ + 'name', + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': withNames, + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withNames, + equals(withNames), + ); + }, + ); + + test( + 'deserializes the with names property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': null, + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withNames, + equals([]), + ); + }, + ); + + test( + 'deserializes the with remote ids property', + () { + final withRemoteIds = [ + 'str', + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': withRemoteIds, + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withRemoteIds, + equals(withRemoteIds), + ); + }, + ); + + test( + 'deserializes the with remote ids property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': null, + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withRemoteIds, + equals([]), + ); + }, + ); + + test( + 'deserializes the with service data property', + () { + final withServiceData = [ + { + 'service': '0102', + 'data': '010203', + 'mask': '010203', + }, + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': withServiceData, + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServiceData, + equals( + withServiceData.map( + (serviceData) { + return BmServiceDataFilter.fromMap(serviceData); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the with service data property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': [], + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': null, + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServiceData, + equals([]), + ); + }, + ); + + test( + 'deserializes the with services property', + () { + final withServices = [ + '0102', + ]; + + expect( + BmScanSettings.fromMap({ + 'with_services': withServices, + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServices, + equals( + withServices.map( + (service) { + return Guid(service); + }, + ), + ), + ); + }, + ); + + test( + 'deserializes the with services property as [] if it is null', + () { + expect( + BmScanSettings.fromMap({ + 'with_services': null, + 'with_remote_ids': [], + 'with_names': [], + 'with_keywords': [], + 'with_msd': [], + 'with_service_data': [], + 'continuous_updates': false, + 'continuous_divisor': 1, + 'android_legacy': false, + 'android_scan_mode': 0, + 'android_uses_fine_location': false, + }).withServices, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final withServices = []; + final withRemoteIds = []; + final withNames = []; + final withKeywords = []; + final withMsd = []; + final withServiceData = []; + final continuousUpdates = false; + final continuousDivisor = 1; + final androidLegacy = false; + final androidScanMode = 0; + final androidUsesFineLocation = false; + + expect( + BmScanSettings( + withServices: withServices, + withRemoteIds: withRemoteIds, + withNames: withNames, + withKeywords: withKeywords, + withMsd: withMsd, + withServiceData: withServiceData, + continuousUpdates: continuousUpdates, + continuousDivisor: continuousDivisor, + androidLegacy: androidLegacy, + androidScanMode: androidScanMode, + androidUsesFineLocation: androidUsesFineLocation, + ).hashCode, + equals( + const ListEquality().hash(withServices) ^ + const ListEquality().hash(withRemoteIds) ^ + const ListEquality().hash(withNames) ^ + const ListEquality().hash(withKeywords) ^ + const ListEquality().hash(withMsd) ^ + const ListEquality() + .hash(withServiceData) ^ + continuousUpdates.hashCode ^ + continuousDivisor.hashCode ^ + androidLegacy.hashCode ^ + androidScanMode.hashCode ^ + androidUsesFineLocation.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ) == + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: true, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ) == + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the with msd property', + () { + final withMsd = [ + BmMsdFilter( + 0, + [], + [], + ), + ]; + + expect( + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: withMsd, + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ).toMap(), + containsPair( + 'with_msd', + equals( + withMsd.map( + (manufacturerData) { + return manufacturerData.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the with service data property', + () { + final withServiceData = [ + BmServiceDataFilter( + Guid('0102'), + [], + [], + ), + ]; + + expect( + BmScanSettings( + withServices: [], + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: withServiceData, + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ).toMap(), + containsPair( + 'with_service_data', + equals( + withServiceData.map( + (serviceData) { + return serviceData.toMap(); + }, + ), + ), + ), + ); + }, + ); + + test( + 'serializes the with services property', + () { + final withServices = [ + Guid('0102'), + ]; + + expect( + BmScanSettings( + withServices: withServices, + withRemoteIds: [], + withNames: [], + withKeywords: [], + withMsd: [], + withServiceData: [], + continuousUpdates: false, + continuousDivisor: 1, + androidLegacy: false, + androidScanMode: 0, + androidUsesFineLocation: false, + ).toMap(), + containsPair( + 'with_services', + equals( + withServices.map( + (service) { + return service.str; + }, + ), + ), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart new file mode 100644 index 00000000..1e241a8d --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart @@ -0,0 +1,211 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmServiceDataFilter', + () { + group( + 'fromMap', + () { + test( + 'deserializes the data property', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': '010203', + 'mask': '010203', + }).data, + equals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + + test( + 'deserializes the data property as [] if it is null', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': null, + 'mask': '010203', + }).data, + equals([]), + ); + }, + ); + + test( + 'deserializes the mask property', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': '010203', + 'mask': '010203', + }).mask, + equals([ + 0x01, + 0x02, + 0x03, + ]), + ); + }, + ); + + test( + 'deserializes the mask property as [] if it is null', + () { + expect( + BmServiceDataFilter.fromMap({ + 'service': '0102', + 'data': '010203', + 'mask': null, + }).mask, + equals([]), + ); + }, + ); + + test( + 'deserializes the service property', + () { + final service = '0102'; + + expect( + BmServiceDataFilter.fromMap({ + 'service': service, + 'data': '010203', + 'mask': '010203', + }).service, + equals(Guid(service)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final service = Guid('0102'); + final data = []; + final mask = []; + + expect( + BmServiceDataFilter( + service, + data, + mask, + ).hashCode, + equals( + service.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmServiceDataFilter(Guid('0102'), [], []) == + BmServiceDataFilter(Guid('0304'), [], []), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmServiceDataFilter(Guid('0102'), [], []) == + BmServiceDataFilter(Guid('0102'), [], []), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the data property', + () { + final data = [0x01, 0x02, 0x03]; + + expect( + BmServiceDataFilter( + Guid('0102'), + data, + [], + ).toMap(), + containsPair( + 'data', + hex.encode(data), + ), + ); + }, + ); + + test( + 'serializes the mask property', + () { + final mask = [0x01, 0x02, 0x03]; + + expect( + BmServiceDataFilter( + Guid('0102'), + [], + mask, + ).toMap(), + containsPair( + 'mask', + hex.encode(mask), + ), + ); + }, + ); + + test( + 'serializes the characteristic uuid property', + () { + final service = Guid('0102'); + + expect( + BmServiceDataFilter( + service, + [], + [], + ).toMap(), + containsPair( + 'service', + equals(service.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart new file mode 100644 index 00000000..4ce9ebe5 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart @@ -0,0 +1,284 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmSetNotifyValueRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'force_indications': false, + 'enable': false, + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final forceIndications = false; + final enable = false; + + expect( + BmSetNotifyValueRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + forceIndications: forceIndications, + enable: enable, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + forceIndications.hashCode ^ + enable.hashCode, + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ) == + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ) == + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmSetNotifyValueRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmSetNotifyValueRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + forceIndications: false, + enable: false, + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart new file mode 100644 index 00000000..61fb826f --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart @@ -0,0 +1,112 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmTurnOnResponse', + () { + group( + 'fromMap', + () { + test( + 'deserializes the user accepted property', + () { + expect( + BmTurnOnResponse.fromMap({ + 'user_accepted': true, + }).userAccepted, + isTrue, + ); + }, + ); + + test( + 'deserializes the user accepted property as false if it is null', + () { + expect( + BmTurnOnResponse.fromMap({ + 'user_accepted': null, + }).userAccepted, + isFalse, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final userAccepted = true; + + expect( + BmTurnOnResponse( + userAccepted: userAccepted, + ).hashCode, + equals(userAccepted.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmTurnOnResponse( + userAccepted: true, + ) == + BmTurnOnResponse( + userAccepted: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmTurnOnResponse( + userAccepted: true, + ) == + BmTurnOnResponse( + userAccepted: true, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the user accepted property', + () { + expect( + BmTurnOnResponse( + userAccepted: true, + ).toMap(), + containsPair( + 'user_accepted', + isTrue, + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart new file mode 100644 index 00000000..f4ef3688 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart @@ -0,0 +1,471 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmWriteCharacteristicRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'write_type': 0, + 'allow_long_write': 0, + 'value': '', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 0, + 'value': '', + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 0, + 'value': '', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 0, + 'value': '', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + + test( + 'deserializes the allow long write property as false if it is 0', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 0, + 'value': '', + }).allowLongWrite, + isFalse, + ); + }, + ); + + test( + 'deserializes the allow long write property as true if it is not 0', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 1, + 'value': '', + }).allowLongWrite, + isTrue, + ); + }, + ); + + test( + 'deserializes the value property', + () { + final value = '010203'; + + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 0, + 'value': value, + }).value, + equals(hex.decode(value)), + ); + }, + ); + + test( + 'deserializes the value property as [] if it is null', + () { + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 0, + 'allow_long_write': 0, + 'value': null, + }).value, + equals([]), + ); + }, + ); + + test( + 'deserializes the write type property', + () { + final writeType = BmWriteType.withResponse; + + expect( + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': writeType.index, + 'allow_long_write': 0, + 'value': '', + }).writeType, + equals(writeType), + ); + }, + ); + + test( + 'throws a range error if the write type property index is out of range', + () { + expect( + () { + BmWriteCharacteristicRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'write_type': 2, + 'allow_long_write': 0, + 'value': '', + }); + }, + throwsRangeError, + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final writeType = BmWriteType.withResponse; + final allowLongWrite = false; + final value = []; + + expect( + BmWriteCharacteristicRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + writeType: writeType, + allowLongWrite: allowLongWrite, + value: value, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + writeType.hashCode ^ + allowLongWrite.hashCode ^ + const ListEquality().hash(value), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ) == + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ) == + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmWriteCharacteristicRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the success property as 0 if it is false', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'allow_long_write', + equals(0), + ), + ); + }, + ); + + test( + 'serializes the success property as 1 if it is true', + () { + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: BmWriteType.withResponse, + allowLongWrite: true, + value: [], + ).toMap(), + containsPair( + 'allow_long_write', + equals(1), + ), + ); + }, + ); + + test( + 'serializes the write type property', + () { + final writeType = BmWriteType.withResponse; + + expect( + BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + writeType: writeType, + allowLongWrite: false, + value: [], + ).toMap(), + containsPair( + 'write_type', + equals(writeType.index), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart new file mode 100644 index 00000000..4a2c8d79 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart @@ -0,0 +1,379 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmWriteDescriptorRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the characteristic uuid property', + () { + final characteristicUuid = '0102'; + + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': characteristicUuid, + 'descriptor_uuid': '0102', + 'value': '', + }).characteristicUuid, + equals(Guid(characteristicUuid)), + ); + }, + ); + + test( + 'deserializes the descriptor uuid property', + () { + final descriptorUuid = '0102'; + + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': descriptorUuid, + 'value': '', + }).descriptorUuid, + equals(Guid(descriptorUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property', + () { + final secondaryServiceUuid = '0102'; + + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': secondaryServiceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + }).secondaryServiceUuid, + equals(Guid(secondaryServiceUuid)), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + }).secondaryServiceUuid, + isNull, + ); + }, + ); + + test( + 'deserializes the service uuid property', + () { + final serviceUuid = '0102'; + + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': serviceUuid, + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': '', + }).serviceUuid, + equals(Guid(serviceUuid)), + ); + }, + ); + + test( + 'deserializes the value property', + () { + final value = '010203'; + + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': value, + }).value, + equals(hex.decode(value)), + ); + }, + ); + + test( + 'deserializes the value property as [] if it is null', + () { + expect( + BmWriteDescriptorRequest.fromMap({ + 'remote_id': 'str', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'descriptor_uuid': '0102', + 'value': null, + }).value, + equals([]), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final remoteId = DeviceIdentifier('str'); + final serviceUuid = Guid('0102'); + final secondaryServiceUuid = null; + final characteristicUuid = Guid('0102'); + final descriptorUuid = Guid('0102'); + final value = []; + + expect( + BmWriteDescriptorRequest( + remoteId: remoteId, + serviceUuid: serviceUuid, + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: characteristicUuid, + descriptorUuid: descriptorUuid, + value: value, + ).hashCode, + equals( + remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value), + ), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ) == + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ) == + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the characteristic uuid property', + () { + final characteristicUuid = Guid('0102'); + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: characteristicUuid, + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'characteristic_uuid', + equals(characteristicUuid.str), + ), + ); + }, + ); + + test( + 'serializes the characteristic uuid property', + () { + final descriptorUuid = Guid('0102'); + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: descriptorUuid, + value: [], + ).toMap(), + containsPair( + 'descriptor_uuid', + equals(descriptorUuid.str), + ), + ); + }, + ); + + test( + 'serializes the remote id property', + () { + final remoteId = DeviceIdentifier('str'); + + expect( + BmWriteDescriptorRequest( + remoteId: remoteId, + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'remote_id', + equals(remoteId.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property', + () { + final secondaryServiceUuid = Guid('0102'); + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: secondaryServiceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'secondary_service_uuid', + equals(secondaryServiceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the secondary service uuid property as null if it is null', + () { + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + secondaryServiceUuid: null, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'secondary_service_uuid', + isNull, + ), + ); + }, + ); + + test( + 'serializes the service uuid property', + () { + final serviceUuid = Guid('0102'); + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: serviceUuid, + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: [], + ).toMap(), + containsPair( + 'service_uuid', + equals(serviceUuid.str), + ), + ); + }, + ); + + test( + 'serializes the value property', + () { + final value = [0x01, 0x02, 0x03]; + + expect( + BmWriteDescriptorRequest( + remoteId: DeviceIdentifier('str'), + serviceUuid: Guid('0102'), + characteristicUuid: Guid('0102'), + descriptorUuid: Guid('0102'), + value: value, + ).toMap(), + containsPair( + 'value', + hex.encode(value), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart new file mode 100644 index 00000000..87da0ac3 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart @@ -0,0 +1,109 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'DeviceIdentifier', + () { + group( + 'hashCode', + () { + test( + 'returns the hash code of a lower case identifier', + () { + expect( + DeviceIdentifier('str').hashCode, + equals('str'.hashCode), + ); + }, + ); + + test( + 'returns the hash code of a mixed case identifier', + () { + expect( + DeviceIdentifier('sTr').hashCode, + equals('str'.hashCode), + ); + }, + ); + + test( + 'returns the hash code of an upper case identifier', + () { + expect( + DeviceIdentifier('STR').hashCode, + equals('str'.hashCode), + ); + }, + ); + }, + ); + + group( + 'id', + () { + test( + 'returns the str property', + () { + expect( + DeviceIdentifier('str').id, + equals('str'), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + DeviceIdentifier('str1') == DeviceIdentifier('str2'), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + DeviceIdentifier('str') == DeviceIdentifier('str'), + isTrue, + ); + }, + ); + + test( + 'returns true if they are equal ignoring case', + () { + expect( + DeviceIdentifier('str') == DeviceIdentifier('STR'), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toString', + () { + test( + 'returns the str property', + () { + expect( + DeviceIdentifier('str').toString(), + equals('str'), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart new file mode 100644 index 00000000..3ec20d5a --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart @@ -0,0 +1,366 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'Guid', + () { + group( + 'empty', + () { + test( + 'constructs an instance', + () { + expect( + Guid.empty().bytes, + equals([ + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + ]), + ); + }, + ); + }, + ); + + group( + 'fromBytes', + () { + test( + 'constructs an instance from a list of 2 bytes', + () { + expect( + Guid.fromBytes([ + 0x01, + 0x02, + ]).bytes, + equals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'constructs an instance from a list of 4 bytes', + () { + expect( + Guid.fromBytes([ + 0x01, + 0x02, + 0x03, + 0x04, + ]).bytes, + equals([ + 0x01, + 0x02, + 0x03, + 0x04, + ]), + ); + }, + ); + + test( + 'constructs an instance from a list of 16 bytes', + () { + expect( + Guid.fromBytes([ + 0x01, + 0x02, + 0x03, + 0x04, + 0x00, + 0x00, + 0x10, + 0x00, + 0x80, + 0x00, + 0x00, + 0x80, + 0x5F, + 0x9B, + 0x34, + 0xFB, + ]).bytes, + equals([ + 0x01, + 0x02, + 0x03, + 0x04, + 0x00, + 0x00, + 0x10, + 0x00, + 0x80, + 0x00, + 0x00, + 0x80, + 0x5F, + 0x9B, + 0x34, + 0xFB, + ]), + ); + }, + ); + + test( + 'throws a format exception if the list is not 2 nor 4 nor 16 bytes in length', + () { + expect( + () { + Guid.fromBytes([ + 0x01, + 0x02, + 0x03, + ]); + }, + throwsFormatException, + ); + }, + ); + }, + ); + + group( + 'fromString', + () { + test( + 'constructs an instance from a string of 2 bytes', + () { + expect( + Guid.fromString('0102').bytes, + equals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'constructs an instance from a string of 4 bytes', + () { + expect( + Guid.fromString('01020304').bytes, + equals([ + 0x01, + 0x02, + 0x03, + 0x04, + ]), + ); + }, + ); + + test( + 'constructs an instance from a string of 16 bytes', + () { + expect( + Guid.fromString('0102030400001000800000805f9b34fb').bytes, + equals([ + 0x01, + 0x02, + 0x03, + 0x04, + 0x00, + 0x00, + 0x10, + 0x00, + 0x80, + 0x00, + 0x00, + 0x80, + 0x5F, + 0x9B, + 0x34, + 0xFB, + ]), + ); + }, + ); + + test( + 'constructs an instance from a uuid formatted string', + () { + expect( + Guid.fromString('01020304-0000-1000-8000-00805f9b34fb').bytes, + equals([ + 0x01, + 0x02, + 0x03, + 0x04, + 0x00, + 0x00, + 0x10, + 0x00, + 0x80, + 0x00, + 0x00, + 0x80, + 0x5F, + 0x9B, + 0x34, + 0xFB, + ]), + ); + }, + ); + + test( + 'throws a format exception if the string is not 2 nor 4 nor 16 bytes in length', + () { + expect( + () { + Guid.fromString('010203'); + }, + throwsFormatException, + ); + }, + ); + }, + ); + }, + ); + + group( + 'str', + () { + test( + 'returns a string of 2 bytes if the list of bytes is 2 bytes in length', + () { + expect( + Guid('0102').str, + equals('0102'), + ); + }, + ); + + test( + 'returns a string of 4 bytes if the list of bytes is 4 bytes in length', + () { + expect( + Guid('01020304').str, + equals('01020304'), + ); + }, + ); + + test( + 'returns a string of 16 bytes if the list of bytes is 16 bytes in length and does not end with the suffix', + () { + expect( + Guid('01020304-0000-0000-0000-000000000000').str, + equals('01020304-0000-0000-0000-000000000000'), + ); + }, + ); + + test( + 'returns a string of 4 bytes if the list of bytes is 16 bytes in length and ends with the suffix', + () { + expect( + Guid('01020304-0000-1000-8000-00805f9b34fb').str, + equals('01020304'), + ); + }, + ); + }, + ); + + group( + 'str128', + () { + test( + 'returns a string of 16 bytes if the list of bytes is 2 bytes in length', + () { + expect( + Guid('0102').str128, + equals('00000102-0000-1000-8000-00805f9b34fb'), + ); + }, + ); + + test( + 'returns a string of 16 bytes if the list of bytes is 4 bytes in length', + () { + expect( + Guid('01020304').str128, + equals('01020304-0000-1000-8000-00805f9b34fb'), + ); + }, + ); + + test( + 'returns a string of 16 bytes if the list of bytes is 16 bytes in length', + () { + expect( + Guid('01020304-0000-1000-8000-00805f9b34fb').str128, + equals('01020304-0000-1000-8000-00805f9b34fb'), + ); + }, + ); + }, + ); + + group( + 'uuid', + () { + test( + 'returns the str property', + () { + expect( + Guid('0102').uuid, + equals('0102'), + ); + }, + ); + }, + ); + + group( + 'uuid128', + () { + test( + 'returns the str128 property', + () { + expect( + Guid('0102').uuid128, + equals('00000102-0000-1000-8000-00805f9b34fb'), + ); + }, + ); + }, + ); + + group( + 'toString', + () { + test( + 'returns the str property', + () { + expect( + Guid('0102').toString(), + equals('0102'), + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/options_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/options_test.dart new file mode 100644 index 00000000..9a9e4ee5 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/options_test.dart @@ -0,0 +1,104 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'Options', + () { + group( + 'fromMap', + () { + test( + 'deserializes the show power alert property', + () { + final showPowerAlert = false; + + expect( + Options.fromMap({ + 'show_power_alert': showPowerAlert, + }).showPowerAlert, + equals(showPowerAlert), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final showPowerAlert = false; + + expect( + Options( + showPowerAlert: showPowerAlert, + ).hashCode, + equals(showPowerAlert.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + Options( + showPowerAlert: false, + ) == + Options( + showPowerAlert: true, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + Options( + showPowerAlert: false, + ) == + Options( + showPowerAlert: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the show power alert property', + () { + final showPowerAlert = false; + + expect( + Options( + showPowerAlert: showPowerAlert, + ).toMap(), + containsPair( + 'show_power_alert', + equals(showPowerAlert), + ), + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart new file mode 100644 index 00000000..97d72772 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart @@ -0,0 +1,145 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'PhySupport', + () { + group( + 'fromMap', + () { + test( + 'deserializes the le 2m property', + () { + final le2M = false; + + expect( + PhySupport.fromMap({ + 'le_2M': le2M, + 'le_coded': false, + }).le2M, + equals(le2M), + ); + }, + ); + + test( + 'deserializes the le coded property', + () { + final leCoded = false; + + expect( + PhySupport.fromMap({ + 'le_2M': false, + 'le_coded': leCoded, + }).leCoded, + equals(leCoded), + ); + }, + ); + }, + ); + + group( + 'hashCode', + () { + test( + 'returns the hash code', + () { + final le2M = false; + final leCoded = false; + + expect( + PhySupport( + le2M: le2M, + leCoded: leCoded, + ).hashCode, + equals(le2M.hashCode ^ leCoded.hashCode), + ); + }, + ); + }, + ); + + group( + '==', + () { + test( + 'returns false if they are not equal', + () { + expect( + PhySupport( + le2M: false, + leCoded: false, + ) == + PhySupport( + le2M: true, + leCoded: false, + ), + isFalse, + ); + }, + ); + + test( + 'returns true if they are equal', + () { + expect( + PhySupport( + le2M: false, + leCoded: false, + ) == + PhySupport( + le2M: false, + leCoded: false, + ), + isTrue, + ); + }, + ); + }, + ); + + group( + 'toMap', + () { + test( + 'serializes the le 2m property', + () { + final le2M = false; + + expect( + PhySupport( + le2M: le2M, + leCoded: false, + ).toMap(), + containsPair( + 'le_2M', + equals(le2M), + ), + ); + }, + ); + + test( + 'serializes the le coded property', + () { + final leCoded = false; + + expect( + PhySupport( + le2M: false, + leCoded: leCoded, + ).toMap(), + containsPair( + 'le_coded', + equals(leCoded), + ), + ); + }, + ); + }, + ); + }, + ); +} From 4a46ec6d3636e23620e0c1e331966fce2a4e4f06 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:41 +0100 Subject: [PATCH 46/90] Revert "refactor: add single bluetooth_msgs file" This reverts commit 11c781f3f3ed99ab002d07b76589faac0c640b8b. --- .../lib/src/types/bluetooth_msgs.dart | 1550 ----------------- .../lib/src/types/bm_adapter_state_enum.dart | 9 + .../src/types/bm_bluetooth_adapter_state.dart | 34 + .../types/bm_bluetooth_characteristic.dart | 82 + .../src/types/bm_bluetooth_descriptor.dart | 50 + .../lib/src/types/bm_bluetooth_device.dart | 27 + .../lib/src/types/bm_bluetooth_service.dart | 70 + .../lib/src/types/bm_bond_state_enum.dart | 5 + .../lib/src/types/bm_bond_state_response.dart | 34 + .../lib/src/types/bm_characteristic_data.dart | 75 + .../types/bm_characteristic_properties.dart | 77 + .../lib/src/types/bm_connect_request.dart | 27 + .../types/bm_connection_priority_enum.dart | 5 + .../types/bm_connection_priority_request.dart | 29 + .../src/types/bm_connection_state_enum.dart | 4 + .../types/bm_connection_state_response.dart | 37 + .../lib/src/types/bm_descriptor_data.dart | 80 + .../lib/src/types/bm_devices_list.dart | 48 + .../types/bm_discover_services_result.dart | 62 + .../lib/src/types/bm_msd_filter.dart | 44 + .../lib/src/types/bm_mtu_change_request.dart | 27 + .../src/types/bm_mtu_changed_response.dart | 41 + .../lib/src/types/bm_name_changed.dart | 27 + .../lib/src/types/bm_preferred_phy.dart | 35 + .../types/bm_read_characteristic_request.dart | 52 + .../src/types/bm_read_descriptor_request.dart | 57 + .../lib/src/types/bm_read_rssi_result.dart | 41 + .../lib/src/types/bm_scan_advertisement.dart | 90 + .../lib/src/types/bm_scan_response.dart | 57 + .../lib/src/types/bm_scan_settings.dart | 100 ++ .../lib/src/types/bm_service_data_filter.dart | 45 + .../types/bm_set_notify_value_request.dart | 62 + .../lib/src/types/bm_turn_on_response.dart | 32 + .../bm_write_characteristic_request.dart | 69 + .../types/bm_write_descriptor_request.dart | 63 + .../lib/src/types/bm_write_type.dart | 4 + .../lib/src/types/types.dart | 36 +- 37 files changed, 1636 insertions(+), 1551 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bluetooth_msgs.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bluetooth_msgs.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bluetooth_msgs.dart deleted file mode 100644 index 48753ad3..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bluetooth_msgs.dart +++ /dev/null @@ -1,1550 +0,0 @@ -import 'dart:collection'; - -import '../utils/utils.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; - -enum BmAdapterStateEnum { - unknown, // 0 - unavailable, // 1 - unauthorized, // 2 - turningOn, // 3 - on, // 4 - turningOff, // 5 - off, // 6 -} - -class BmBluetoothAdapterState { - BmAdapterStateEnum adapterState; - - BmBluetoothAdapterState({ - required this.adapterState, - }); - - factory BmBluetoothAdapterState.fromMap( - Map json, - ) { - return BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.values[json['adapter_state'] as int], - ); - } - - @override - int get hashCode { - return adapterState.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothAdapterState && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'adapter_state': adapterState.index, - }; - } -} - -class BmBluetoothCharacteristic { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - List descriptors; - BmCharacteristicProperties properties; - - BmBluetoothCharacteristic({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptors, - required this.properties, - }); - - factory BmBluetoothCharacteristic.fromMap( - Map json, - ) { - return BmBluetoothCharacteristic( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptors: (json['descriptors'] as List?) - ?.map((descriptor) => BmBluetoothDescriptor.fromMap(descriptor)) - .toList() ?? - [], - properties: json['properties'] != null - ? BmCharacteristicProperties.fromMap(json['properties']) - : BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality().hash(descriptors) ^ - properties.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothCharacteristic && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptors': - descriptors.map((descriptor) => descriptor.toMap()).toList(), - 'properties': properties.toMap(), - }; - } -} - -class BmBluetoothDescriptor { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - - BmBluetoothDescriptor({ - required this.remoteId, - required this.serviceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - }); - - factory BmBluetoothDescriptor.fromMap( - Map json, - ) { - return BmBluetoothDescriptor( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothDescriptor && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - }; - } -} - -class BmBluetoothDevice { - DeviceIdentifier remoteId; - String? platformName; - - BmBluetoothDevice({ - required this.remoteId, - this.platformName, - }); - - factory BmBluetoothDevice.fromMap( - Map json, - ) { - return BmBluetoothDevice( - remoteId: DeviceIdentifier(json['remote_id']), - platformName: json['platform_name'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'platform_name': platformName, - }; - } -} - -class BmBluetoothService { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - bool isPrimary; - List characteristics; - List includedServices; - - BmBluetoothService({ - required this.remoteId, - required this.serviceUuid, - required this.isPrimary, - required this.characteristics, - required this.includedServices, - }); - - factory BmBluetoothService.fromMap( - Map json, - ) { - return BmBluetoothService( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - isPrimary: json['is_primary'] == 1, - characteristics: (json['characteristics'] as List?) - ?.map((characteristic) => - BmBluetoothCharacteristic.fromMap(characteristic)) - .toList() ?? - [], - includedServices: (json['included_services'] as List?) - ?.map((includedService) => - BmBluetoothService.fromMap(includedService)) - .toList() ?? - [], - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - isPrimary.hashCode ^ - const ListEquality().hash(characteristics) ^ - const ListEquality().hash(includedServices); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothService && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'is_primary': isPrimary ? 1 : 0, - 'characteristics': characteristics - .map((characteristic) => characteristic.toMap()) - .toList(), - 'included_services': includedServices - .map((includedService) => includedService.toMap()) - .toList(), - }; - } -} - -enum BmBondStateEnum { - none, // 0 - bonding, // 1 - bonded, // 2 -} - -class BmBondStateResponse { - final DeviceIdentifier remoteId; - final BmBondStateEnum bondState; - final BmBondStateEnum? prevState; - - BmBondStateResponse({ - required this.remoteId, - required this.bondState, - this.prevState, - }); - - factory BmBondStateResponse.fromMap( - Map json, - ) { - return BmBondStateResponse( - remoteId: DeviceIdentifier(json['remote_id']), - bondState: BmBondStateEnum.values[json['bond_state'] as int], - prevState: json['prev_state'] != null - ? BmBondStateEnum.values[json['prev_state'] as int] - : null, - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'bond_state': bondState.index, - 'prev_state': prevState?.index, - }; - } -} - -class BmCharacteristicData { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final List value; - final bool success; - final int errorCode; - final String errorString; - - BmCharacteristicData({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.value, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmCharacteristicData.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmCharacteristicData( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmCharacteristicData && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'value': hex.encode(value), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} - -class BmCharacteristicProperties { - bool broadcast; - bool read; - bool writeWithoutResponse; - bool write; - bool notify; - bool indicate; - bool authenticatedSignedWrites; - bool extendedProperties; - bool notifyEncryptionRequired; - bool indicateEncryptionRequired; - - BmCharacteristicProperties({ - required this.broadcast, - required this.read, - required this.writeWithoutResponse, - required this.write, - required this.notify, - required this.indicate, - required this.authenticatedSignedWrites, - required this.extendedProperties, - required this.notifyEncryptionRequired, - required this.indicateEncryptionRequired, - }); - - factory BmCharacteristicProperties.fromMap( - Map json, - ) { - return BmCharacteristicProperties( - broadcast: json['broadcast'] == 1, - read: json['read'] == 1, - writeWithoutResponse: json['write_without_response'] == 1, - write: json['write'] == 1, - notify: json['notify'] == 1, - indicate: json['indicate'] == 1, - authenticatedSignedWrites: json['authenticated_signed_writes'] == 1, - extendedProperties: json['extended_properties'] == 1, - notifyEncryptionRequired: json['notify_encryption_required'] == 1, - indicateEncryptionRequired: json['indicate_encryption_required'] == 1, - ); - } - - @override - int get hashCode { - return broadcast.hashCode ^ - read.hashCode ^ - writeWithoutResponse.hashCode ^ - write.hashCode ^ - notify.hashCode ^ - indicate.hashCode ^ - authenticatedSignedWrites.hashCode ^ - extendedProperties.hashCode ^ - notifyEncryptionRequired.hashCode ^ - indicateEncryptionRequired.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmCharacteristicProperties && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'broadcast': broadcast ? 1 : 0, - 'read': read ? 1 : 0, - 'write_without_response': writeWithoutResponse ? 1 : 0, - 'write': write ? 1 : 0, - 'notify': notify ? 1 : 0, - 'indicate': indicate ? 1 : 0, - 'authenticated_signed_writes': authenticatedSignedWrites ? 1 : 0, - 'extended_properties': extendedProperties ? 1 : 0, - 'notify_encryption_required': notifyEncryptionRequired ? 1 : 0, - 'indicate_encryption_required': indicateEncryptionRequired ? 1 : 0, - }; - } -} - -class BmConnectRequest { - DeviceIdentifier remoteId; - bool autoConnect; - - BmConnectRequest({ - required this.remoteId, - required this.autoConnect, - }); - - factory BmConnectRequest.fromMap( - Map json, - ) { - return BmConnectRequest( - remoteId: DeviceIdentifier(json['remote_id']), - autoConnect: json['auto_connect'] == 1, - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'auto_connect': autoConnect ? 1 : 0, - }; - } -} - -enum BmConnectionPriorityEnum { - balanced, // 0 - high, // 1 - lowPower, // 2 -} - -class BmConnectionPriorityRequest { - final DeviceIdentifier remoteId; - final BmConnectionPriorityEnum connectionPriority; - - BmConnectionPriorityRequest({ - required this.remoteId, - required this.connectionPriority, - }); - - factory BmConnectionPriorityRequest.fromMap( - Map json, - ) { - return BmConnectionPriorityRequest( - remoteId: DeviceIdentifier(json['remote_id']), - connectionPriority: - BmConnectionPriorityEnum.values[json['connection_priority'] as int], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'connection_priority': connectionPriority.index, - }; - } -} - -enum BmConnectionStateEnum { - disconnected, // 0 - connected, // 1 -} - -class BmConnectionStateResponse { - final DeviceIdentifier remoteId; - final BmConnectionStateEnum connectionState; - final int? disconnectReasonCode; - final String? disconnectReasonString; - - BmConnectionStateResponse({ - required this.remoteId, - required this.connectionState, - this.disconnectReasonCode, - this.disconnectReasonString, - }); - - factory BmConnectionStateResponse.fromMap( - Map json, - ) { - return BmConnectionStateResponse( - remoteId: DeviceIdentifier(json['remote_id']), - connectionState: - BmConnectionStateEnum.values[json['connection_state'] as int], - disconnectReasonCode: json['disconnect_reason_code'], - disconnectReasonString: json['disconnect_reason_string'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'connection_state': connectionState.index, - 'disconnectReasonCode': disconnectReasonCode, - 'disconnectReasonString': disconnectReasonString, - }; - } -} - -class BmDescriptorData { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - final List value; - final bool success; - final int errorCode; - final String errorString; - - BmDescriptorData({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - required this.value, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmDescriptorData.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmDescriptorData( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmDescriptorData && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - 'value': hex.encode(value), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} - -class BmDevicesList extends ListBase { - final List devices; - - BmDevicesList({ - required this.devices, - }); - - factory BmDevicesList.fromMap( - Map json, - ) { - return BmDevicesList( - devices: (json['devices'] as List?) - ?.map((device) => BmBluetoothDevice.fromMap(device)) - .toList() ?? - [], - ); - } - - Map toMap() { - return { - 'devices': devices.map((device) => device.toMap()).toList(), - }; - } - - @override - int get length { - return devices.length; - } - - @override - set length(int newLength) { - devices.length = newLength; - } - - @override - BmBluetoothDevice operator [](int index) { - return devices[index]; - } - - @override - void operator []=(int index, BmBluetoothDevice value) { - devices[index] = value; - } -} - -class BmDiscoverServicesResult { - final DeviceIdentifier remoteId; - final List services; - final bool success; - final int errorCode; - final String errorString; - - BmDiscoverServicesResult({ - required this.remoteId, - required this.services, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmDiscoverServicesResult.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmDiscoverServicesResult( - remoteId: DeviceIdentifier(json['remote_id']), - services: (json['services'] as List?) - ?.map((service) => - BmBluetoothService.fromMap(service as Map)) - .toList() ?? - [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - const ListEquality().hash(services) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmDiscoverServicesResult && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'services': services.map((service) => service.toMap()).toList(), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} - -class BmMsdFilter { - int manufacturerId; - List? data; - List? mask; - - BmMsdFilter( - this.manufacturerId, - this.data, - this.mask, - ); - - factory BmMsdFilter.fromMap( - Map json, - ) { - return BmMsdFilter( - json['manufacturer_id'], - json['data'] != null ? hex.decode(json['data']) : null, - json['mask'] != null ? hex.decode(json['mask']) : null, - ); - } - - @override - int get hashCode { - return manufacturerId.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmMsdFilter && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'manufacturer_id': manufacturerId, - 'data': data != null ? hex.encode(data!) : null, - 'mask': mask != null ? hex.encode(mask!) : null, - }; - } -} - -class BmMtuChangeRequest { - final DeviceIdentifier remoteId; - final int mtu; - - BmMtuChangeRequest({ - required this.remoteId, - required this.mtu, - }); - - factory BmMtuChangeRequest.fromMap( - Map json, - ) { - return BmMtuChangeRequest( - remoteId: DeviceIdentifier(json['remote_id']), - mtu: json['mtu'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'mtu': mtu, - }; - } -} - -class BmMtuChangedResponse { - final DeviceIdentifier remoteId; - final int mtu; - final bool success; - final int errorCode; - final String errorString; - - BmMtuChangedResponse({ - required this.remoteId, - required this.mtu, - this.success = true, - this.errorCode = 0, - this.errorString = '', - }); - - factory BmMtuChangedResponse.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmMtuChangedResponse( - remoteId: DeviceIdentifier(json['remote_id']), - mtu: json['mtu'], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'mtu': mtu, - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} - -class BmNameChanged { - DeviceIdentifier remoteId; - String name; - - BmNameChanged({ - required this.remoteId, - required this.name, - }); - - factory BmNameChanged.fromMap( - Map json, - ) { - return BmNameChanged( - remoteId: DeviceIdentifier(json['remote_id']), - name: json['name'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'name': name, - }; - } -} - -class BmPreferredPhy { - final DeviceIdentifier remoteId; - final int txPhy; - final int rxPhy; - final int phyOptions; - - BmPreferredPhy({ - required this.remoteId, - required this.txPhy, - required this.rxPhy, - required this.phyOptions, - }); - - factory BmPreferredPhy.fromMap( - Map json, - ) { - return BmPreferredPhy( - remoteId: DeviceIdentifier(json['remote_id']), - txPhy: json['tx_phy'], - rxPhy: json['rx_phy'], - phyOptions: json['phy_options'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'tx_phy': txPhy, - 'rx_phy': rxPhy, - 'phy_options': phyOptions, - }; - } -} - -class BmReadCharacteristicRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - - BmReadCharacteristicRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - }); - - factory BmReadCharacteristicRequest.fromMap( - Map json, - ) { - return BmReadCharacteristicRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmReadCharacteristicRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - }; - } -} - -class BmReadDescriptorRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - - BmReadDescriptorRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - }); - - factory BmReadDescriptorRequest.fromMap( - Map json, - ) { - return BmReadDescriptorRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmReadDescriptorRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - }; - } -} - -class BmReadRssiResult { - final DeviceIdentifier remoteId; - final int rssi; - final bool success; - final int errorCode; - final String errorString; - - BmReadRssiResult({ - required this.remoteId, - required this.rssi, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmReadRssiResult.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmReadRssiResult( - remoteId: DeviceIdentifier(json['remote_id']), - rssi: json['rssi'], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'rssi': rssi, - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} - -class BmScanAdvertisement { - final DeviceIdentifier remoteId; - final String? platformName; - final String? advName; - final bool connectable; - final int? txPowerLevel; - final int? appearance; // not supported on iOS / macOS - final Map> manufacturerData; - final Map> serviceData; - final List serviceUuids; - final int rssi; - - BmScanAdvertisement({ - required this.remoteId, - this.platformName, - this.advName, - required this.connectable, - this.txPowerLevel, - this.appearance, - required this.manufacturerData, - required this.serviceData, - required this.serviceUuids, - required this.rssi, - }); - - factory BmScanAdvertisement.fromMap( - Map json, - ) { - return BmScanAdvertisement( - remoteId: DeviceIdentifier(json['remote_id']), - platformName: json['platform_name'], - advName: json['adv_name'], - connectable: json['connectable'] == 1, - txPowerLevel: json['tx_power_level'], - appearance: json['appearance'], - manufacturerData: (json['manufacturer_data'] as Map?) - ?.map((key, value) => MapEntry(key, hex.decode(value))) ?? - {}, - serviceData: (json['service_data'] as Map?) - ?.map((key, value) => MapEntry(Guid(key), hex.decode(value))) ?? - {}, - serviceUuids: (json['service_uuids'] as List?) - ?.map((str) => Guid(str)) - .toList() ?? - [], - rssi: json['rssi'] ?? 0, - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - platformName.hashCode ^ - advName.hashCode ^ - connectable.hashCode ^ - txPowerLevel.hashCode ^ - appearance.hashCode ^ - const MapEquality>().hash(manufacturerData) ^ - const MapEquality>().hash(serviceData) ^ - const ListEquality().hash(serviceUuids) ^ - rssi.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanAdvertisement && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'platform_name': platformName, - 'adv_name': advName, - 'connectable': connectable ? 1 : 0, - 'tx_power_level': txPowerLevel, - 'appearance': appearance, - 'manufacturer_data': manufacturerData - .map((key, value) => MapEntry(key, hex.encode(value))), - 'service_data': - serviceData.map((key, value) => MapEntry(key.str, hex.encode(value))), - 'service_uuids': serviceUuids.map((uuid) => uuid.str).toList(), - 'rssi': rssi, - }; - } -} - -class BmScanResponse { - final List advertisements; - final bool success; - final int errorCode; - final String errorString; - - BmScanResponse({ - required this.advertisements, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmScanResponse.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmScanResponse( - advertisements: (json['advertisements'] as List?) - ?.map( - (advertisement) => BmScanAdvertisement.fromMap(advertisement)) - .toList() ?? - [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - @override - int get hashCode { - return const ListEquality().hash(advertisements) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanResponse && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'advertisements': - advertisements.map((advertisement) => advertisement.toMap()).toList(), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} - -class BmScanSettings { - final List withServices; - final List withRemoteIds; - final List withNames; - final List withKeywords; - final List withMsd; - final List withServiceData; - final bool continuousUpdates; - final int continuousDivisor; - final bool androidLegacy; - final int androidScanMode; - final bool androidUsesFineLocation; - - BmScanSettings({ - required this.withServices, - required this.withRemoteIds, - required this.withNames, - required this.withKeywords, - required this.withMsd, - required this.withServiceData, - required this.continuousUpdates, - required this.continuousDivisor, - required this.androidLegacy, - required this.androidScanMode, - required this.androidUsesFineLocation, - }); - - factory BmScanSettings.fromMap( - Map json, - ) { - return BmScanSettings( - withServices: (json['with_services'] as List?) - ?.map((str) => Guid(str)) - .toList() ?? - [], - withRemoteIds: - (json['with_remote_ids'] as List?)?.cast() ?? [], - withNames: (json['with_names'] as List?)?.cast() ?? [], - withKeywords: - (json['with_keywords'] as List?)?.cast() ?? [], - withMsd: (json['with_msd'] as List?) - ?.map((manufacturerData) => BmMsdFilter.fromMap(manufacturerData)) - .toList() ?? - [], - withServiceData: (json['with_service_data'] as List?) - ?.map((serviceData) => BmServiceDataFilter.fromMap(serviceData)) - .toList() ?? - [], - continuousUpdates: json['continuous_updates'], - continuousDivisor: json['continuous_divisor'], - androidLegacy: json['android_legacy'], - androidScanMode: json['android_scan_mode'], - androidUsesFineLocation: json['android_uses_fine_location'], - ); - } - - @override - int get hashCode { - return const ListEquality().hash(withServices) ^ - const ListEquality().hash(withRemoteIds) ^ - const ListEquality().hash(withNames) ^ - const ListEquality().hash(withKeywords) ^ - const ListEquality().hash(withMsd) ^ - const ListEquality().hash(withServiceData) ^ - continuousUpdates.hashCode ^ - continuousDivisor.hashCode ^ - androidLegacy.hashCode ^ - androidScanMode.hashCode ^ - androidUsesFineLocation.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanSettings && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'with_services': withServices.map((uuid) => uuid.str).toList(), - 'with_remote_ids': withRemoteIds, - 'with_names': withNames, - 'with_keywords': withKeywords, - 'with_msd': - withMsd.map((manufacturerData) => manufacturerData.toMap()).toList(), - 'with_service_data': - withServiceData.map((serviceData) => serviceData.toMap()).toList(), - 'continuous_updates': continuousUpdates, - 'continuous_divisor': continuousDivisor, - 'android_legacy': androidLegacy, - 'android_scan_mode': androidScanMode, - 'android_uses_fine_location': androidUsesFineLocation, - }; - } -} - -class BmServiceDataFilter { - Guid service; - List data; - List mask; - - BmServiceDataFilter( - this.service, - this.data, - this.mask, - ); - - factory BmServiceDataFilter.fromMap( - Map json, - ) { - return BmServiceDataFilter( - Guid(json['service']), - json['data'] != null ? hex.decode(json['data']) : [], - json['mask'] != null ? hex.decode(json['mask']) : [], - ); - } - - @override - int get hashCode { - return service.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmServiceDataFilter && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'service': service.str, - 'data': hex.encode(data), - 'mask': hex.encode(mask), - }; - } -} - -class BmSetNotifyValueRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final bool forceIndications; - final bool enable; - - BmSetNotifyValueRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.forceIndications, - required this.enable, - }); - - factory BmSetNotifyValueRequest.fromMap( - Map json, - ) { - return BmSetNotifyValueRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - forceIndications: json['force_indications'], - enable: json['enable'], - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - forceIndications.hashCode ^ - enable.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmSetNotifyValueRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'force_indications': forceIndications, - 'enable': enable, - }; - } -} - -class BmTurnOnResponse { - bool userAccepted; - - BmTurnOnResponse({ - required this.userAccepted, - }); - - factory BmTurnOnResponse.fromMap( - Map json, - ) { - return BmTurnOnResponse( - userAccepted: json['user_accepted'] ?? false, - ); - } - - @override - int get hashCode { - return userAccepted.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmTurnOnResponse && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'user_accepted': userAccepted, - }; - } -} - -class BmWriteCharacteristicRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final BmWriteType writeType; - final bool allowLongWrite; - final List value; - - BmWriteCharacteristicRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.writeType, - required this.allowLongWrite, - required this.value, - }); - - factory BmWriteCharacteristicRequest.fromMap( - Map json, - ) { - return BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - writeType: BmWriteType.values[json['write_type'] as int], - allowLongWrite: json['allow_long_write'] != 0, - value: json['value'] != null ? hex.decode(json['value']) : [], - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - writeType.hashCode ^ - allowLongWrite.hashCode ^ - const ListEquality().hash(value); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmWriteCharacteristicRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'write_type': writeType.index, - 'allow_long_write': allowLongWrite ? 1 : 0, - 'value': hex.encode(value), - }; - } -} - -class BmWriteDescriptorRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - final List value; - - BmWriteDescriptorRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - required this.value, - }); - - factory BmWriteDescriptorRequest.fromMap( - Map json, - ) { - return BmWriteDescriptorRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - ); - } - - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmWriteDescriptorRequest && hashCode == other.hashCode; - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - 'value': hex.encode(value), - }; - } -} - -enum BmWriteType { - withResponse, // 0 - withoutResponse, // 1 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart new file mode 100644 index 00000000..68ea06ab --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart @@ -0,0 +1,9 @@ +enum BmAdapterStateEnum { + unknown, // 0 + unavailable, // 1 + unauthorized, // 2 + turningOn, // 3 + on, // 4 + turningOff, // 5 + off, // 6 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart new file mode 100644 index 00000000..f6dbbc8e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart @@ -0,0 +1,34 @@ +import 'bm_adapter_state_enum.dart'; + +class BmBluetoothAdapterState { + BmAdapterStateEnum adapterState; + + BmBluetoothAdapterState({ + required this.adapterState, + }); + + factory BmBluetoothAdapterState.fromMap( + Map json, + ) { + return BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.values[json['adapter_state'] as int], + ); + } + + @override + int get hashCode { + return adapterState.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothAdapterState && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'adapter_state': adapterState.index, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart new file mode 100644 index 00000000..2bfcf66c --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart @@ -0,0 +1,82 @@ +import '../utils/utils.dart'; +import 'bm_bluetooth_descriptor.dart'; +import 'bm_characteristic_properties.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmBluetoothCharacteristic { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + List descriptors; + BmCharacteristicProperties properties; + + BmBluetoothCharacteristic({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptors, + required this.properties, + }); + + factory BmBluetoothCharacteristic.fromMap( + Map json, + ) { + return BmBluetoothCharacteristic( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptors: (json['descriptors'] as List?) + ?.map((descriptor) => BmBluetoothDescriptor.fromMap(descriptor)) + .toList() ?? + [], + properties: json['properties'] != null + ? BmCharacteristicProperties.fromMap(json['properties']) + : BmCharacteristicProperties( + broadcast: false, + read: false, + writeWithoutResponse: false, + write: false, + notify: false, + indicate: false, + authenticatedSignedWrites: false, + extendedProperties: false, + notifyEncryptionRequired: false, + indicateEncryptionRequired: false, + ), + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality().hash(descriptors) ^ + properties.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothCharacteristic && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptors': + descriptors.map((descriptor) => descriptor.toMap()).toList(), + 'properties': properties.toMap(), + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart new file mode 100644 index 00000000..9a0160ae --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart @@ -0,0 +1,50 @@ +import 'guid.dart'; +import 'device_identifier.dart'; + +class BmBluetoothDescriptor { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + + BmBluetoothDescriptor({ + required this.remoteId, + required this.serviceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + }); + + factory BmBluetoothDescriptor.fromMap( + Map json, + ) { + return BmBluetoothDescriptor( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothDescriptor && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart new file mode 100644 index 00000000..6a16229e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart @@ -0,0 +1,27 @@ +import 'device_identifier.dart'; + +class BmBluetoothDevice { + DeviceIdentifier remoteId; + String? platformName; + + BmBluetoothDevice({ + required this.remoteId, + this.platformName, + }); + + factory BmBluetoothDevice.fromMap( + Map json, + ) { + return BmBluetoothDevice( + remoteId: DeviceIdentifier(json['remote_id']), + platformName: json['platform_name'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'platform_name': platformName, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart new file mode 100644 index 00000000..f0102cfe --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart @@ -0,0 +1,70 @@ +import 'package:collection/collection.dart'; + +import 'bm_bluetooth_characteristic.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmBluetoothService { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + bool isPrimary; + List characteristics; + List includedServices; + + BmBluetoothService({ + required this.remoteId, + required this.serviceUuid, + required this.isPrimary, + required this.characteristics, + required this.includedServices, + }); + + factory BmBluetoothService.fromMap( + Map json, + ) { + return BmBluetoothService( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + isPrimary: json['is_primary'] == 1, + characteristics: (json['characteristics'] as List?) + ?.map((characteristic) => + BmBluetoothCharacteristic.fromMap(characteristic)) + .toList() ?? + [], + includedServices: (json['included_services'] as List?) + ?.map((includedService) => + BmBluetoothService.fromMap(includedService)) + .toList() ?? + [], + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + isPrimary.hashCode ^ + const ListEquality().hash(characteristics) ^ + const ListEquality().hash(includedServices); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmBluetoothService && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'is_primary': isPrimary ? 1 : 0, + 'characteristics': characteristics + .map((characteristic) => characteristic.toMap()) + .toList(), + 'included_services': includedServices + .map((includedService) => includedService.toMap()) + .toList(), + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart new file mode 100644 index 00000000..4e9756b1 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart @@ -0,0 +1,5 @@ +enum BmBondStateEnum { + none, // 0 + bonding, // 1 + bonded, // 2 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart new file mode 100644 index 00000000..bacb627e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart @@ -0,0 +1,34 @@ +import 'bm_bond_state_enum.dart'; +import 'device_identifier.dart'; + +class BmBondStateResponse { + final DeviceIdentifier remoteId; + final BmBondStateEnum bondState; + final BmBondStateEnum? prevState; + + BmBondStateResponse({ + required this.remoteId, + required this.bondState, + this.prevState, + }); + + factory BmBondStateResponse.fromMap( + Map json, + ) { + return BmBondStateResponse( + remoteId: DeviceIdentifier(json['remote_id']), + bondState: BmBondStateEnum.values[json['bond_state'] as int], + prevState: json['prev_state'] != null + ? BmBondStateEnum.values[json['prev_state'] as int] + : null, + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'bond_state': bondState.index, + 'prev_state': prevState?.index, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart new file mode 100644 index 00000000..076ccee1 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart @@ -0,0 +1,75 @@ +import '../utils/utils.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmCharacteristicData { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final List value; + final bool success; + final int errorCode; + final String errorString; + + BmCharacteristicData({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.value, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmCharacteristicData.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmCharacteristicData( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmCharacteristicData && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'value': hex.encode(value), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart new file mode 100644 index 00000000..30745221 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart @@ -0,0 +1,77 @@ +class BmCharacteristicProperties { + bool broadcast; + bool read; + bool writeWithoutResponse; + bool write; + bool notify; + bool indicate; + bool authenticatedSignedWrites; + bool extendedProperties; + bool notifyEncryptionRequired; + bool indicateEncryptionRequired; + + BmCharacteristicProperties({ + required this.broadcast, + required this.read, + required this.writeWithoutResponse, + required this.write, + required this.notify, + required this.indicate, + required this.authenticatedSignedWrites, + required this.extendedProperties, + required this.notifyEncryptionRequired, + required this.indicateEncryptionRequired, + }); + + factory BmCharacteristicProperties.fromMap( + Map json, + ) { + return BmCharacteristicProperties( + broadcast: json['broadcast'] == 1, + read: json['read'] == 1, + writeWithoutResponse: json['write_without_response'] == 1, + write: json['write'] == 1, + notify: json['notify'] == 1, + indicate: json['indicate'] == 1, + authenticatedSignedWrites: json['authenticated_signed_writes'] == 1, + extendedProperties: json['extended_properties'] == 1, + notifyEncryptionRequired: json['notify_encryption_required'] == 1, + indicateEncryptionRequired: json['indicate_encryption_required'] == 1, + ); + } + + @override + int get hashCode { + return broadcast.hashCode ^ + read.hashCode ^ + writeWithoutResponse.hashCode ^ + write.hashCode ^ + notify.hashCode ^ + indicate.hashCode ^ + authenticatedSignedWrites.hashCode ^ + extendedProperties.hashCode ^ + notifyEncryptionRequired.hashCode ^ + indicateEncryptionRequired.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmCharacteristicProperties && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'broadcast': broadcast ? 1 : 0, + 'read': read ? 1 : 0, + 'write_without_response': writeWithoutResponse ? 1 : 0, + 'write': write ? 1 : 0, + 'notify': notify ? 1 : 0, + 'indicate': indicate ? 1 : 0, + 'authenticated_signed_writes': authenticatedSignedWrites ? 1 : 0, + 'extended_properties': extendedProperties ? 1 : 0, + 'notify_encryption_required': notifyEncryptionRequired ? 1 : 0, + 'indicate_encryption_required': indicateEncryptionRequired ? 1 : 0, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart new file mode 100644 index 00000000..b56394c8 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart @@ -0,0 +1,27 @@ +import 'device_identifier.dart'; + +class BmConnectRequest { + DeviceIdentifier remoteId; + bool autoConnect; + + BmConnectRequest({ + required this.remoteId, + required this.autoConnect, + }); + + factory BmConnectRequest.fromMap( + Map json, + ) { + return BmConnectRequest( + remoteId: DeviceIdentifier(json['remote_id']), + autoConnect: json['auto_connect'] == 1, + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'auto_connect': autoConnect ? 1 : 0, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart new file mode 100644 index 00000000..e205abcb --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart @@ -0,0 +1,5 @@ +enum BmConnectionPriorityEnum { + balanced, // 0 + high, // 1 + lowPower, // 2 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart new file mode 100644 index 00000000..118080c1 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart @@ -0,0 +1,29 @@ +import 'bm_connection_priority_enum.dart'; +import 'device_identifier.dart'; + +class BmConnectionPriorityRequest { + final DeviceIdentifier remoteId; + final BmConnectionPriorityEnum connectionPriority; + + BmConnectionPriorityRequest({ + required this.remoteId, + required this.connectionPriority, + }); + + factory BmConnectionPriorityRequest.fromMap( + Map json, + ) { + return BmConnectionPriorityRequest( + remoteId: DeviceIdentifier(json['remote_id']), + connectionPriority: + BmConnectionPriorityEnum.values[json['connection_priority'] as int], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'connection_priority': connectionPriority.index, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart new file mode 100644 index 00000000..e254b9e9 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart @@ -0,0 +1,4 @@ +enum BmConnectionStateEnum { + disconnected, // 0 + connected, // 1 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart new file mode 100644 index 00000000..43553e89 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart @@ -0,0 +1,37 @@ +import 'bm_connection_state_enum.dart'; +import 'device_identifier.dart'; + +class BmConnectionStateResponse { + final DeviceIdentifier remoteId; + final BmConnectionStateEnum connectionState; + final int? disconnectReasonCode; + final String? disconnectReasonString; + + BmConnectionStateResponse({ + required this.remoteId, + required this.connectionState, + this.disconnectReasonCode, + this.disconnectReasonString, + }); + + factory BmConnectionStateResponse.fromMap( + Map json, + ) { + return BmConnectionStateResponse( + remoteId: DeviceIdentifier(json['remote_id']), + connectionState: + BmConnectionStateEnum.values[json['connection_state'] as int], + disconnectReasonCode: json['disconnect_reason_code'], + disconnectReasonString: json['disconnect_reason_string'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'connection_state': connectionState.index, + 'disconnectReasonCode': disconnectReasonCode, + 'disconnectReasonString': disconnectReasonString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart new file mode 100644 index 00000000..0f7cae55 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart @@ -0,0 +1,80 @@ +import '../utils/utils.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmDescriptorData { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + final List value; + final bool success; + final int errorCode; + final String errorString; + + BmDescriptorData({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + required this.value, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmDescriptorData.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmDescriptorData( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmDescriptorData && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + 'value': hex.encode(value), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart new file mode 100644 index 00000000..4fa7460e --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart @@ -0,0 +1,48 @@ +import 'dart:collection'; + +import 'bm_bluetooth_device.dart'; + +class BmDevicesList extends ListBase { + final List devices; + + BmDevicesList({ + required this.devices, + }); + + factory BmDevicesList.fromMap( + Map json, + ) { + return BmDevicesList( + devices: (json['devices'] as List?) + ?.map((device) => BmBluetoothDevice.fromMap(device)) + .toList() ?? + [], + ); + } + + Map toMap() { + return { + 'devices': devices.map((device) => device.toMap()).toList(), + }; + } + + @override + int get length { + return devices.length; + } + + @override + set length(int newLength) { + devices.length = newLength; + } + + @override + BmBluetoothDevice operator [](int index) { + return devices[index]; + } + + @override + void operator []=(int index, BmBluetoothDevice value) { + devices[index] = value; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart new file mode 100644 index 00000000..30017f94 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart @@ -0,0 +1,62 @@ +import '../utils/utils.dart'; +import 'bm_bluetooth_service.dart'; +import 'device_identifier.dart'; + +class BmDiscoverServicesResult { + final DeviceIdentifier remoteId; + final List services; + final bool success; + final int errorCode; + final String errorString; + + BmDiscoverServicesResult({ + required this.remoteId, + required this.services, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmDiscoverServicesResult.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmDiscoverServicesResult( + remoteId: DeviceIdentifier(json['remote_id']), + services: (json['services'] as List?) + ?.map((service) => + BmBluetoothService.fromMap(service as Map)) + .toList() ?? + [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + const ListEquality().hash(services) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmDiscoverServicesResult && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'services': services.map((service) => service.toMap()).toList(), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart new file mode 100644 index 00000000..89424bdb --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart @@ -0,0 +1,44 @@ +import '../utils/utils.dart'; + +class BmMsdFilter { + int manufacturerId; + List? data; + List? mask; + + BmMsdFilter( + this.manufacturerId, + this.data, + this.mask, + ); + + factory BmMsdFilter.fromMap( + Map json, + ) { + return BmMsdFilter( + json['manufacturer_id'], + json['data'] != null ? hex.decode(json['data']) : null, + json['mask'] != null ? hex.decode(json['mask']) : null, + ); + } + + @override + int get hashCode { + return manufacturerId.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmMsdFilter && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'manufacturer_id': manufacturerId, + 'data': data != null ? hex.encode(data!) : null, + 'mask': mask != null ? hex.encode(mask!) : null, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart new file mode 100644 index 00000000..4c03df5f --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart @@ -0,0 +1,27 @@ +import 'device_identifier.dart'; + +class BmMtuChangeRequest { + final DeviceIdentifier remoteId; + final int mtu; + + BmMtuChangeRequest({ + required this.remoteId, + required this.mtu, + }); + + factory BmMtuChangeRequest.fromMap( + Map json, + ) { + return BmMtuChangeRequest( + remoteId: DeviceIdentifier(json['remote_id']), + mtu: json['mtu'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'mtu': mtu, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart new file mode 100644 index 00000000..2ffbc90b --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart @@ -0,0 +1,41 @@ +import 'device_identifier.dart'; + +class BmMtuChangedResponse { + final DeviceIdentifier remoteId; + final int mtu; + final bool success; + final int errorCode; + final String errorString; + + BmMtuChangedResponse({ + required this.remoteId, + required this.mtu, + this.success = true, + this.errorCode = 0, + this.errorString = '', + }); + + factory BmMtuChangedResponse.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmMtuChangedResponse( + remoteId: DeviceIdentifier(json['remote_id']), + mtu: json['mtu'], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'mtu': mtu, + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart new file mode 100644 index 00000000..54597f3d --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart @@ -0,0 +1,27 @@ +import 'device_identifier.dart'; + +class BmNameChanged { + DeviceIdentifier remoteId; + String name; + + BmNameChanged({ + required this.remoteId, + required this.name, + }); + + factory BmNameChanged.fromMap( + Map json, + ) { + return BmNameChanged( + remoteId: DeviceIdentifier(json['remote_id']), + name: json['name'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'name': name, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart new file mode 100644 index 00000000..b8accc11 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart @@ -0,0 +1,35 @@ +import 'device_identifier.dart'; + +class BmPreferredPhy { + final DeviceIdentifier remoteId; + final int txPhy; + final int rxPhy; + final int phyOptions; + + BmPreferredPhy({ + required this.remoteId, + required this.txPhy, + required this.rxPhy, + required this.phyOptions, + }); + + factory BmPreferredPhy.fromMap( + Map json, + ) { + return BmPreferredPhy( + remoteId: DeviceIdentifier(json['remote_id']), + txPhy: json['tx_phy'], + rxPhy: json['rx_phy'], + phyOptions: json['phy_options'], + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'tx_phy': txPhy, + 'rx_phy': rxPhy, + 'phy_options': phyOptions, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart new file mode 100644 index 00000000..9c706891 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart @@ -0,0 +1,52 @@ +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmReadCharacteristicRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + + BmReadCharacteristicRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + }); + + factory BmReadCharacteristicRequest.fromMap( + Map json, + ) { + return BmReadCharacteristicRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmReadCharacteristicRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart new file mode 100644 index 00000000..dec81238 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart @@ -0,0 +1,57 @@ +import 'guid.dart'; +import 'device_identifier.dart'; + +class BmReadDescriptorRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + + BmReadDescriptorRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + }); + + factory BmReadDescriptorRequest.fromMap( + Map json, + ) { + return BmReadDescriptorRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmReadDescriptorRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart new file mode 100644 index 00000000..b2436d63 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart @@ -0,0 +1,41 @@ +import 'device_identifier.dart'; + +class BmReadRssiResult { + final DeviceIdentifier remoteId; + final int rssi; + final bool success; + final int errorCode; + final String errorString; + + BmReadRssiResult({ + required this.remoteId, + required this.rssi, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmReadRssiResult.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmReadRssiResult( + remoteId: DeviceIdentifier(json['remote_id']), + rssi: json['rssi'], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'rssi': rssi, + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart new file mode 100644 index 00000000..4d238e27 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart @@ -0,0 +1,90 @@ +import '../utils/utils.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmScanAdvertisement { + final DeviceIdentifier remoteId; + final String? platformName; + final String? advName; + final bool connectable; + final int? txPowerLevel; + final int? appearance; // not supported on iOS / macOS + final Map> manufacturerData; + final Map> serviceData; + final List serviceUuids; + final int rssi; + + BmScanAdvertisement({ + required this.remoteId, + this.platformName, + this.advName, + required this.connectable, + this.txPowerLevel, + this.appearance, + required this.manufacturerData, + required this.serviceData, + required this.serviceUuids, + required this.rssi, + }); + + factory BmScanAdvertisement.fromMap( + Map json, + ) { + return BmScanAdvertisement( + remoteId: DeviceIdentifier(json['remote_id']), + platformName: json['platform_name'], + advName: json['adv_name'], + connectable: json['connectable'] == 1, + txPowerLevel: json['tx_power_level'], + appearance: json['appearance'], + manufacturerData: (json['manufacturer_data'] as Map?) + ?.map((key, value) => MapEntry(key, hex.decode(value))) ?? + {}, + serviceData: (json['service_data'] as Map?) + ?.map((key, value) => MapEntry(Guid(key), hex.decode(value))) ?? + {}, + serviceUuids: (json['service_uuids'] as List?) + ?.map((str) => Guid(str)) + .toList() ?? + [], + rssi: json['rssi'] ?? 0, + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + platformName.hashCode ^ + advName.hashCode ^ + connectable.hashCode ^ + txPowerLevel.hashCode ^ + appearance.hashCode ^ + const MapEquality>().hash(manufacturerData) ^ + const MapEquality>().hash(serviceData) ^ + const ListEquality().hash(serviceUuids) ^ + rssi.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanAdvertisement && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'platform_name': platformName, + 'adv_name': advName, + 'connectable': connectable ? 1 : 0, + 'tx_power_level': txPowerLevel, + 'appearance': appearance, + 'manufacturer_data': manufacturerData + .map((key, value) => MapEntry(key, hex.encode(value))), + 'service_data': + serviceData.map((key, value) => MapEntry(key.str, hex.encode(value))), + 'service_uuids': serviceUuids.map((uuid) => uuid.str).toList(), + 'rssi': rssi, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart new file mode 100644 index 00000000..3a9170b2 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart @@ -0,0 +1,57 @@ +import '../utils/utils.dart'; +import 'bm_scan_advertisement.dart'; + +class BmScanResponse { + final List advertisements; + final bool success; + final int errorCode; + final String errorString; + + BmScanResponse({ + required this.advertisements, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmScanResponse.fromMap( + Map json, + ) { + final success = json['success'] == null || json['success'] != 0; + + return BmScanResponse( + advertisements: (json['advertisements'] as List?) + ?.map( + (advertisement) => BmScanAdvertisement.fromMap(advertisement)) + .toList() ?? + [], + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : '', + ); + } + + @override + int get hashCode { + return const ListEquality().hash(advertisements) ^ + success.hashCode ^ + errorCode.hashCode ^ + errorString.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanResponse && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'advertisements': + advertisements.map((advertisement) => advertisement.toMap()).toList(), + 'success': success ? 1 : 0, + 'error_code': errorCode, + 'error_string': errorString, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart new file mode 100644 index 00000000..9b090c53 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart @@ -0,0 +1,100 @@ +import '../utils/utils.dart'; +import 'bm_msd_filter.dart'; +import 'bm_service_data_filter.dart'; +import 'guid.dart'; + +class BmScanSettings { + final List withServices; + final List withRemoteIds; + final List withNames; + final List withKeywords; + final List withMsd; + final List withServiceData; + final bool continuousUpdates; + final int continuousDivisor; + final bool androidLegacy; + final int androidScanMode; + final bool androidUsesFineLocation; + + BmScanSettings({ + required this.withServices, + required this.withRemoteIds, + required this.withNames, + required this.withKeywords, + required this.withMsd, + required this.withServiceData, + required this.continuousUpdates, + required this.continuousDivisor, + required this.androidLegacy, + required this.androidScanMode, + required this.androidUsesFineLocation, + }); + + factory BmScanSettings.fromMap( + Map json, + ) { + return BmScanSettings( + withServices: (json['with_services'] as List?) + ?.map((str) => Guid(str)) + .toList() ?? + [], + withRemoteIds: + (json['with_remote_ids'] as List?)?.cast() ?? [], + withNames: (json['with_names'] as List?)?.cast() ?? [], + withKeywords: + (json['with_keywords'] as List?)?.cast() ?? [], + withMsd: (json['with_msd'] as List?) + ?.map((manufacturerData) => BmMsdFilter.fromMap(manufacturerData)) + .toList() ?? + [], + withServiceData: (json['with_service_data'] as List?) + ?.map((serviceData) => BmServiceDataFilter.fromMap(serviceData)) + .toList() ?? + [], + continuousUpdates: json['continuous_updates'], + continuousDivisor: json['continuous_divisor'], + androidLegacy: json['android_legacy'], + androidScanMode: json['android_scan_mode'], + androidUsesFineLocation: json['android_uses_fine_location'], + ); + } + + @override + int get hashCode { + return const ListEquality().hash(withServices) ^ + const ListEquality().hash(withRemoteIds) ^ + const ListEquality().hash(withNames) ^ + const ListEquality().hash(withKeywords) ^ + const ListEquality().hash(withMsd) ^ + const ListEquality().hash(withServiceData) ^ + continuousUpdates.hashCode ^ + continuousDivisor.hashCode ^ + androidLegacy.hashCode ^ + androidScanMode.hashCode ^ + androidUsesFineLocation.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmScanSettings && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'with_services': withServices.map((uuid) => uuid.str).toList(), + 'with_remote_ids': withRemoteIds, + 'with_names': withNames, + 'with_keywords': withKeywords, + 'with_msd': + withMsd.map((manufacturerData) => manufacturerData.toMap()).toList(), + 'with_service_data': + withServiceData.map((serviceData) => serviceData.toMap()).toList(), + 'continuous_updates': continuousUpdates, + 'continuous_divisor': continuousDivisor, + 'android_legacy': androidLegacy, + 'android_scan_mode': androidScanMode, + 'android_uses_fine_location': androidUsesFineLocation, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart new file mode 100644 index 00000000..afb665a5 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart @@ -0,0 +1,45 @@ +import '../utils/utils.dart'; +import 'guid.dart'; + +class BmServiceDataFilter { + Guid service; + List data; + List mask; + + BmServiceDataFilter( + this.service, + this.data, + this.mask, + ); + + factory BmServiceDataFilter.fromMap( + Map json, + ) { + return BmServiceDataFilter( + Guid(json['service']), + json['data'] != null ? hex.decode(json['data']) : [], + json['mask'] != null ? hex.decode(json['mask']) : [], + ); + } + + @override + int get hashCode { + return service.hashCode ^ + const ListEquality().hash(data) ^ + const ListEquality().hash(mask); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmServiceDataFilter && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'service': service.str, + 'data': hex.encode(data), + 'mask': hex.encode(mask), + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart new file mode 100644 index 00000000..9d831817 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart @@ -0,0 +1,62 @@ +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmSetNotifyValueRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final bool forceIndications; + final bool enable; + + BmSetNotifyValueRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.forceIndications, + required this.enable, + }); + + factory BmSetNotifyValueRequest.fromMap( + Map json, + ) { + return BmSetNotifyValueRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + forceIndications: json['force_indications'], + enable: json['enable'], + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + forceIndications.hashCode ^ + enable.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmSetNotifyValueRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'force_indications': forceIndications, + 'enable': enable, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart new file mode 100644 index 00000000..8719a1b6 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart @@ -0,0 +1,32 @@ +class BmTurnOnResponse { + bool userAccepted; + + BmTurnOnResponse({ + required this.userAccepted, + }); + + factory BmTurnOnResponse.fromMap( + Map json, + ) { + return BmTurnOnResponse( + userAccepted: json['user_accepted'] ?? false, + ); + } + + @override + int get hashCode { + return userAccepted.hashCode; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmTurnOnResponse && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'user_accepted': userAccepted, + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart new file mode 100644 index 00000000..1e034cdf --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart @@ -0,0 +1,69 @@ +import '../utils/utils.dart'; +import 'bm_write_type.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmWriteCharacteristicRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final BmWriteType writeType; + final bool allowLongWrite; + final List value; + + BmWriteCharacteristicRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.writeType, + required this.allowLongWrite, + required this.value, + }); + + factory BmWriteCharacteristicRequest.fromMap( + Map json, + ) { + return BmWriteCharacteristicRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + writeType: BmWriteType.values[json['write_type'] as int], + allowLongWrite: json['allow_long_write'] != 0, + value: json['value'] != null ? hex.decode(json['value']) : [], + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + writeType.hashCode ^ + allowLongWrite.hashCode ^ + const ListEquality().hash(value); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmWriteCharacteristicRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'write_type': writeType.index, + 'allow_long_write': allowLongWrite ? 1 : 0, + 'value': hex.encode(value), + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart new file mode 100644 index 00000000..5e4ff0ea --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart @@ -0,0 +1,63 @@ +import '../utils/utils.dart'; +import 'device_identifier.dart'; +import 'guid.dart'; + +class BmWriteDescriptorRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + final List value; + + BmWriteDescriptorRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + required this.value, + }); + + factory BmWriteDescriptorRequest.fromMap( + Map json, + ) { + return BmWriteDescriptorRequest( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null + ? Guid(json['secondary_service_uuid']) + : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + value: json['value'] != null ? hex.decode(json['value']) : [], + ); + } + + @override + int get hashCode { + return remoteId.hashCode ^ + serviceUuid.hashCode ^ + secondaryServiceUuid.hashCode ^ + characteristicUuid.hashCode ^ + descriptorUuid.hashCode ^ + const ListEquality().hash(value); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is BmWriteDescriptorRequest && hashCode == other.hashCode; + } + + Map toMap() { + return { + 'remote_id': remoteId.str, + 'service_uuid': serviceUuid.str, + 'secondary_service_uuid': secondaryServiceUuid?.str, + 'characteristic_uuid': characteristicUuid.str, + 'descriptor_uuid': descriptorUuid.str, + 'value': hex.encode(value), + }; + } +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart new file mode 100644 index 00000000..2ffb5318 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart @@ -0,0 +1,4 @@ +enum BmWriteType { + withResponse, // 0 + withoutResponse, // 1 +} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart index 5840a539..7c3913d1 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart @@ -1,4 +1,38 @@ -export 'bluetooth_msgs.dart'; +export 'bm_adapter_state_enum.dart'; +export 'bm_bluetooth_adapter_state.dart'; +export 'bm_bluetooth_characteristic.dart'; +export 'bm_bluetooth_descriptor.dart'; +export 'bm_bluetooth_device.dart'; +export 'bm_bluetooth_service.dart'; +export 'bm_bond_state_enum.dart'; +export 'bm_bond_state_response.dart'; +export 'bm_characteristic_data.dart'; +export 'bm_characteristic_properties.dart'; +export 'bm_connect_request.dart'; +export 'bm_connection_priority_enum.dart'; +export 'bm_connection_priority_request.dart'; +export 'bm_connection_state_enum.dart'; +export 'bm_connection_state_response.dart'; +export 'bm_descriptor_data.dart'; +export 'bm_devices_list.dart'; +export 'bm_discover_services_result.dart'; +export 'bm_msd_filter.dart'; +export 'bm_mtu_change_request.dart'; +export 'bm_mtu_changed_response.dart'; +export 'bm_name_changed.dart'; +export 'bm_preferred_phy.dart'; +export 'bm_read_characteristic_request.dart'; +export 'bm_read_descriptor_request.dart'; +export 'bm_read_rssi_result.dart'; +export 'bm_scan_advertisement.dart'; +export 'bm_scan_response.dart'; +export 'bm_scan_settings.dart'; +export 'bm_service_data_filter.dart'; +export 'bm_set_notify_value_request.dart'; +export 'bm_turn_on_response.dart'; +export 'bm_write_characteristic_request.dart'; +export 'bm_write_descriptor_request.dart'; +export 'bm_write_type.dart'; export 'device_identifier.dart'; export 'guid.dart'; export 'log_level.dart'; From 6dee3c017f02fc84c909c38e9f1e1d40718fa4c8 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:41 +0100 Subject: [PATCH 47/90] Revert "build: remove flutter lints and analysis options" This reverts commit b87e8002fd3c676f7b2575fad9fb81d9c7ed8157. --- packages/flutter_blue_plus/analysis_options.yaml | 1 + packages/flutter_blue_plus/pubspec.yaml | 1 + packages/flutter_blue_plus_android/analysis_options.yaml | 1 + packages/flutter_blue_plus_android/pubspec.yaml | 1 + packages/flutter_blue_plus_darwin/analysis_options.yaml | 1 + packages/flutter_blue_plus_darwin/pubspec.yaml | 1 + .../flutter_blue_plus_platform_interface/analysis_options.yaml | 1 + packages/flutter_blue_plus_platform_interface/pubspec.yaml | 1 + 8 files changed, 8 insertions(+) create mode 100644 packages/flutter_blue_plus/analysis_options.yaml create mode 100644 packages/flutter_blue_plus_android/analysis_options.yaml create mode 100644 packages/flutter_blue_plus_darwin/analysis_options.yaml create mode 100644 packages/flutter_blue_plus_platform_interface/analysis_options.yaml diff --git a/packages/flutter_blue_plus/analysis_options.yaml b/packages/flutter_blue_plus/analysis_options.yaml new file mode 100644 index 00000000..f9b30346 --- /dev/null +++ b/packages/flutter_blue_plus/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus/pubspec.yaml b/packages/flutter_blue_plus/pubspec.yaml index 5fe78f10..33b81ed9 100644 --- a/packages/flutter_blue_plus/pubspec.yaml +++ b/packages/flutter_blue_plus/pubspec.yaml @@ -15,6 +15,7 @@ dependencies: flutter_blue_plus_platform_interface: ^1.0.0 dev_dependencies: + flutter_lints: ^4.0.0 flutter_test: sdk: flutter diff --git a/packages/flutter_blue_plus_android/analysis_options.yaml b/packages/flutter_blue_plus_android/analysis_options.yaml new file mode 100644 index 00000000..f9b30346 --- /dev/null +++ b/packages/flutter_blue_plus_android/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_android/pubspec.yaml b/packages/flutter_blue_plus_android/pubspec.yaml index f3cf56ed..a054daaa 100644 --- a/packages/flutter_blue_plus_android/pubspec.yaml +++ b/packages/flutter_blue_plus_android/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: flutter_blue_plus_platform_interface: ^1.0.0 dev_dependencies: + flutter_lints: ^4.0.0 flutter_test: sdk: flutter diff --git a/packages/flutter_blue_plus_darwin/analysis_options.yaml b/packages/flutter_blue_plus_darwin/analysis_options.yaml new file mode 100644 index 00000000..f9b30346 --- /dev/null +++ b/packages/flutter_blue_plus_darwin/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_darwin/pubspec.yaml b/packages/flutter_blue_plus_darwin/pubspec.yaml index 366342b9..7435458e 100644 --- a/packages/flutter_blue_plus_darwin/pubspec.yaml +++ b/packages/flutter_blue_plus_darwin/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: flutter_blue_plus_platform_interface: ^1.0.0 dev_dependencies: + flutter_lints: ^4.0.0 flutter_test: sdk: flutter diff --git a/packages/flutter_blue_plus_platform_interface/analysis_options.yaml b/packages/flutter_blue_plus_platform_interface/analysis_options.yaml new file mode 100644 index 00000000..f9b30346 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index 053e17d8..ec5fe6e4 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -12,5 +12,6 @@ dependencies: sdk: flutter dev_dependencies: + flutter_lints: ^4.0.0 flutter_test: sdk: flutter From 692c4406cb353559ae5cade38acf3e7d183bf8fe Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:41 +0100 Subject: [PATCH 48/90] Revert "build: remove plugin platform interface" This reverts commit c3c98633e025eb5f833e1a1e5bea1b3f9c359ac7. --- packages/flutter_blue_plus/pubspec.yaml | 4 ++-- packages/flutter_blue_plus_android/pubspec.yaml | 4 ++-- packages/flutter_blue_plus_darwin/pubspec.yaml | 4 ++-- .../method_channel/method_channel_flutter_blue_plus.dart | 2 +- .../platform_interface/flutter_blue_plus_platform.dart | 9 ++++++++- .../flutter_blue_plus_platform_interface/pubspec.yaml | 5 +++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/flutter_blue_plus/pubspec.yaml b/packages/flutter_blue_plus/pubspec.yaml index 33b81ed9..4758aa4c 100644 --- a/packages/flutter_blue_plus/pubspec.yaml +++ b/packages/flutter_blue_plus/pubspec.yaml @@ -4,8 +4,8 @@ version: 1.33.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: - sdk: ">=3.0.0 <4.0.0" - flutter: ">=3.10.0" + sdk: ">=2.12.0 <4.0.0" + flutter: ">=2.0.0" dependencies: flutter: diff --git a/packages/flutter_blue_plus_android/pubspec.yaml b/packages/flutter_blue_plus_android/pubspec.yaml index a054daaa..761ec1a0 100644 --- a/packages/flutter_blue_plus_android/pubspec.yaml +++ b/packages/flutter_blue_plus_android/pubspec.yaml @@ -4,8 +4,8 @@ version: 1.33.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: - sdk: ">=3.0.0 <4.0.0" - flutter: ">=3.10.0" + sdk: ">=2.12.0 <4.0.0" + flutter: ">=2.0.0" dependencies: flutter: diff --git a/packages/flutter_blue_plus_darwin/pubspec.yaml b/packages/flutter_blue_plus_darwin/pubspec.yaml index 7435458e..3392cb0f 100644 --- a/packages/flutter_blue_plus_darwin/pubspec.yaml +++ b/packages/flutter_blue_plus_darwin/pubspec.yaml @@ -4,8 +4,8 @@ version: 1.33.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: - sdk: ">=3.0.0 <4.0.0" - flutter: ">=3.10.0" + sdk: ">=2.12.0 <4.0.0" + flutter: ">=3.7.0" dependencies: flutter: diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart index 42f27e68..f30e1111 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart @@ -7,7 +7,7 @@ import '../platform_interface/flutter_blue_plus_platform.dart'; import '../types/types.dart'; /// An implementation of [FlutterBluePlusPlatform] that uses method channels. -final class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { +class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @visibleForTesting final channel = const MethodChannel('flutter_blue_plus/methods'); diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart index 7b5786ae..d99a4de9 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart @@ -1,12 +1,18 @@ // coverage:ignore-file +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + import '../method_channel/method_channel_flutter_blue_plus.dart'; import '../types/types.dart'; /// The interface that implementations of flutter_blue_plus must implement. -abstract base class FlutterBluePlusPlatform { +abstract class FlutterBluePlusPlatform extends PlatformInterface { + static final _token = Object(); + static FlutterBluePlusPlatform _instance = MethodChannelFlutterBluePlus(); + FlutterBluePlusPlatform() : super(token: _token); + /// The default instance of [FlutterBluePlusPlatform] to use. /// /// Defaults to [MethodChannelFlutterBluePlus]. @@ -18,6 +24,7 @@ abstract base class FlutterBluePlusPlatform { static set instance( FlutterBluePlusPlatform instance, ) { + PlatformInterface.verify(instance, _token); _instance = instance; } diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index ec5fe6e4..b2952616 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -4,12 +4,13 @@ version: 1.0.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: - sdk: ">=3.0.0 <4.0.0" - flutter: ">=3.10.0" + sdk: ">=2.12.0 <4.0.0" + flutter: ">=2.0.0" dependencies: flutter: sdk: flutter + plugin_platform_interface: ^2.0.0 dev_dependencies: flutter_lints: ^4.0.0 From 2429feb9921164959dfac21aefbbbd713a5b31f9 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:41 +0100 Subject: [PATCH 49/90] Revert "refactor: copy implementations from dependencies" This reverts commit 202356b8172091e639f9ac381dc310163e9ce193. --- .../types/bm_bluetooth_characteristic.dart | 5 +- .../lib/src/types/bm_bluetooth_service.dart | 2 +- .../lib/src/types/bm_characteristic_data.dart | 4 +- .../lib/src/types/bm_descriptor_data.dart | 6 +- .../types/bm_discover_services_result.dart | 3 +- .../lib/src/types/bm_msd_filter.dart | 3 +- .../lib/src/types/bm_scan_advertisement.dart | 6 +- .../lib/src/types/bm_scan_response.dart | 3 +- .../lib/src/types/bm_scan_settings.dart | 3 +- .../lib/src/types/bm_service_data_filter.dart | 4 +- .../bm_write_characteristic_request.dart | 4 +- .../types/bm_write_descriptor_request.dart | 6 +- .../lib/src/types/guid.dart | 2 +- .../lib/src/utils/equality.dart | 501 ------------------ .../lib/src/utils/hex.dart | 363 ------------- .../lib/src/utils/utils.dart | 2 - .../pubspec.yaml | 2 + .../bm_bluetooth_characteristic_test.dart | 2 +- .../test/types/bm_bluetooth_service_test.dart | 2 +- .../types/bm_characteristic_data_test.dart | 3 +- .../test/types/bm_descriptor_data_test.dart | 3 +- .../bm_discover_services_result_test.dart | 2 +- .../test/types/bm_msd_filter_test.dart | 3 +- .../types/bm_scan_advertisement_test.dart | 3 +- .../test/types/bm_scan_response_test.dart | 2 +- .../test/types/bm_scan_settings_test.dart | 2 +- .../types/bm_service_data_filter_test.dart | 3 +- .../bm_write_characteristic_request_test.dart | 3 +- .../bm_write_descriptor_request_test.dart | 3 +- 29 files changed, 55 insertions(+), 895 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/utils/equality.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/utils/hex.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/utils/utils.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart index 2bfcf66c..ca244583 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart @@ -1,8 +1,9 @@ -import '../utils/utils.dart'; +import 'package:collection/collection.dart'; + +import 'guid.dart'; import 'bm_bluetooth_descriptor.dart'; import 'bm_characteristic_properties.dart'; import 'device_identifier.dart'; -import 'guid.dart'; class BmBluetoothCharacteristic { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart index f0102cfe..f527820d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; +import 'guid.dart'; import 'bm_bluetooth_characteristic.dart'; import 'device_identifier.dart'; -import 'guid.dart'; class BmBluetoothService { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart index 076ccee1..f837cf35 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart @@ -1,4 +1,6 @@ -import '../utils/utils.dart'; +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; + import 'device_identifier.dart'; import 'guid.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart index 0f7cae55..ae9999db 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart @@ -1,6 +1,8 @@ -import '../utils/utils.dart'; -import 'device_identifier.dart'; +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; + import 'guid.dart'; +import 'device_identifier.dart'; class BmDescriptorData { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart index 30017f94..b82d5b43 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart @@ -1,4 +1,5 @@ -import '../utils/utils.dart'; +import 'package:collection/collection.dart'; + import 'bm_bluetooth_service.dart'; import 'device_identifier.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart index 89424bdb..32135816 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart @@ -1,4 +1,5 @@ -import '../utils/utils.dart'; +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; class BmMsdFilter { int manufacturerId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart index 4d238e27..4c51b4d3 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart @@ -1,6 +1,8 @@ -import '../utils/utils.dart'; -import 'device_identifier.dart'; +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; + import 'guid.dart'; +import 'device_identifier.dart'; class BmScanAdvertisement { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart index 3a9170b2..b0d86543 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart @@ -1,4 +1,5 @@ -import '../utils/utils.dart'; +import 'package:collection/collection.dart'; + import 'bm_scan_advertisement.dart'; class BmScanResponse { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart index 9b090c53..978beed3 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart @@ -1,4 +1,5 @@ -import '../utils/utils.dart'; +import 'package:collection/collection.dart'; + import 'bm_msd_filter.dart'; import 'bm_service_data_filter.dart'; import 'guid.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart index afb665a5..489bc570 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart @@ -1,4 +1,6 @@ -import '../utils/utils.dart'; +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; + import 'guid.dart'; class BmServiceDataFilter { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart index 1e034cdf..35482049 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart @@ -1,4 +1,6 @@ -import '../utils/utils.dart'; +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; + import 'bm_write_type.dart'; import 'device_identifier.dart'; import 'guid.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart index 5e4ff0ea..6634b1de 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart @@ -1,6 +1,8 @@ -import '../utils/utils.dart'; -import 'device_identifier.dart'; +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; + import 'guid.dart'; +import 'device_identifier.dart'; class BmWriteDescriptorRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart index f18df9a2..4a244914 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart @@ -1,4 +1,4 @@ -import '../utils/utils.dart'; +import 'package:convert/convert.dart'; class Guid { static const _suffix = '-0000-1000-8000-00805f9b34fb'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/utils/equality.dart b/packages/flutter_blue_plus_platform_interface/lib/src/utils/equality.dart deleted file mode 100644 index 2328d5f0..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/utils/equality.dart +++ /dev/null @@ -1,501 +0,0 @@ -// Copyright 2015, the Dart project authors. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// coverage:ignore-file - -import 'dart:collection'; - -const int _hashMask = 0x7fffffff; - -/// A generic equality relation on objects. -abstract class Equality { - const factory Equality() = DefaultEquality; - - /// Compare two elements for being equal. - /// - /// This should be a proper equality relation. - bool equals(E e1, E e2); - - /// Get a hashcode of an element. - /// - /// The hashcode should be compatible with [equals], so that if - /// `equals(a, b)` then `hash(a) == hash(b)`. - int hash(E e); - - /// Test whether an object is a valid argument to [equals] and [hash]. - /// - /// Some implementations may be restricted to only work on specific types - /// of objects. - bool isValidKey(Object? o); -} - -/// Equality of objects based on derived values. -/// -/// For example, given the class: -/// ```dart -/// abstract class Employee { -/// int get employmentId; -/// } -/// ``` -/// -/// The following [Equality] considers employees with the same IDs to be equal: -/// ```dart -/// EqualityBy((Employee e) => e.employmentId); -/// ``` -/// -/// It's also possible to pass an additional equality instance that should be -/// used to compare the value itself. -class EqualityBy implements Equality { - final F Function(E) _comparisonKey; - - final Equality _inner; - - EqualityBy(F Function(E) comparisonKey, - [Equality inner = const DefaultEquality()]) - : _comparisonKey = comparisonKey, - _inner = inner; - - @override - bool equals(E e1, E e2) => - _inner.equals(_comparisonKey(e1), _comparisonKey(e2)); - - @override - int hash(E e) => _inner.hash(_comparisonKey(e)); - - @override - bool isValidKey(Object? o) { - if (o is E) { - final value = _comparisonKey(o); - return _inner.isValidKey(value); - } - return false; - } -} - -/// Equality of objects that compares only the natural equality of the objects. -/// -/// This equality uses the objects' own [Object.==] and [Object.hashCode] for -/// the equality. -/// -/// Note that [equals] and [hash] take `Object`s rather than `E`s. This allows -/// `E` to be inferred as `Null` in const contexts where `E` wouldn't be a -/// compile-time constant, while still allowing the class to be used at runtime. -class DefaultEquality implements Equality { - const DefaultEquality(); - @override - bool equals(Object? e1, Object? e2) => e1 == e2; - @override - int hash(Object? e) => e.hashCode; - @override - bool isValidKey(Object? o) => true; -} - -/// Equality of objects that compares only the identity of the objects. -class IdentityEquality implements Equality { - const IdentityEquality(); - @override - bool equals(E e1, E e2) => identical(e1, e2); - @override - int hash(E e) => identityHashCode(e); - @override - bool isValidKey(Object? o) => true; -} - -/// Equality on iterables. -/// -/// Two iterables are equal if they have the same elements in the same order. -/// -/// The [equals] and [hash] methods accepts `null` values, -/// even if the [isValidKey] returns `false` for `null`. -/// The [hash] of `null` is `null.hashCode`. -class IterableEquality implements Equality> { - final Equality _elementEquality; - const IterableEquality( - [Equality elementEquality = const DefaultEquality()]) - : _elementEquality = elementEquality; - - @override - bool equals(Iterable? elements1, Iterable? elements2) { - if (identical(elements1, elements2)) return true; - if (elements1 == null || elements2 == null) return false; - var it1 = elements1.iterator; - var it2 = elements2.iterator; - while (true) { - var hasNext = it1.moveNext(); - if (hasNext != it2.moveNext()) return false; - if (!hasNext) return true; - if (!_elementEquality.equals(it1.current, it2.current)) return false; - } - } - - @override - int hash(Iterable? elements) { - if (elements == null) return null.hashCode; - // Jenkins's one-at-a-time hash function. - var hash = 0; - for (var element in elements) { - var c = _elementEquality.hash(element); - hash = (hash + c) & _hashMask; - hash = (hash + (hash << 10)) & _hashMask; - hash ^= hash >> 6; - } - hash = (hash + (hash << 3)) & _hashMask; - hash ^= hash >> 11; - hash = (hash + (hash << 15)) & _hashMask; - return hash; - } - - @override - bool isValidKey(Object? o) => o is Iterable; -} - -/// Equality on lists. -/// -/// Two lists are equal if they have the same length and their elements -/// at each index are equal. -/// -/// This is effectively the same as [IterableEquality] except that it -/// accesses elements by index instead of through iteration. -/// -/// The [equals] and [hash] methods accepts `null` values, -/// even if the [isValidKey] returns `false` for `null`. -/// The [hash] of `null` is `null.hashCode`. -class ListEquality implements Equality> { - final Equality _elementEquality; - const ListEquality( - [Equality elementEquality = const DefaultEquality()]) - : _elementEquality = elementEquality; - - @override - bool equals(List? list1, List? list2) { - if (identical(list1, list2)) return true; - if (list1 == null || list2 == null) return false; - var length = list1.length; - if (length != list2.length) return false; - for (var i = 0; i < length; i++) { - if (!_elementEquality.equals(list1[i], list2[i])) return false; - } - return true; - } - - @override - int hash(List? list) { - if (list == null) return null.hashCode; - // Jenkins's one-at-a-time hash function. - // This code is almost identical to the one in IterableEquality, except - // that it uses indexing instead of iterating to get the elements. - var hash = 0; - for (var i = 0; i < list.length; i++) { - var c = _elementEquality.hash(list[i]); - hash = (hash + c) & _hashMask; - hash = (hash + (hash << 10)) & _hashMask; - hash ^= hash >> 6; - } - hash = (hash + (hash << 3)) & _hashMask; - hash ^= hash >> 11; - hash = (hash + (hash << 15)) & _hashMask; - return hash; - } - - @override - bool isValidKey(Object? o) => o is List; -} - -abstract class _UnorderedEquality> - implements Equality { - final Equality _elementEquality; - - const _UnorderedEquality(this._elementEquality); - - @override - bool equals(T? elements1, T? elements2) { - if (identical(elements1, elements2)) return true; - if (elements1 == null || elements2 == null) return false; - var counts = HashMap( - equals: _elementEquality.equals, - hashCode: _elementEquality.hash, - isValidKey: _elementEquality.isValidKey); - var length = 0; - for (var e in elements1) { - var count = counts[e] ?? 0; - counts[e] = count + 1; - length++; - } - for (var e in elements2) { - var count = counts[e]; - if (count == null || count == 0) return false; - counts[e] = count - 1; - length--; - } - return length == 0; - } - - @override - int hash(T? elements) { - if (elements == null) return null.hashCode; - var hash = 0; - for (E element in elements) { - var c = _elementEquality.hash(element); - hash = (hash + c) & _hashMask; - } - hash = (hash + (hash << 3)) & _hashMask; - hash ^= hash >> 11; - hash = (hash + (hash << 15)) & _hashMask; - return hash; - } -} - -/// Equality of the elements of two iterables without considering order. -/// -/// Two iterables are considered equal if they have the same number of elements, -/// and the elements of one set can be paired with the elements -/// of the other iterable, so that each pair are equal. -class UnorderedIterableEquality extends _UnorderedEquality> { - const UnorderedIterableEquality( - [Equality elementEquality = const DefaultEquality()]) - : super(elementEquality); - - @override - bool isValidKey(Object? o) => o is Iterable; -} - -/// Equality of sets. -/// -/// Two sets are considered equal if they have the same number of elements, -/// and the elements of one set can be paired with the elements -/// of the other set, so that each pair are equal. -/// -/// This equality behaves the same as [UnorderedIterableEquality] except that -/// it expects sets instead of iterables as arguments. -/// -/// The [equals] and [hash] methods accepts `null` values, -/// even if the [isValidKey] returns `false` for `null`. -/// The [hash] of `null` is `null.hashCode`. -class SetEquality extends _UnorderedEquality> { - const SetEquality( - [Equality elementEquality = const DefaultEquality()]) - : super(elementEquality); - - @override - bool isValidKey(Object? o) => o is Set; -} - -/// Internal class used by [MapEquality]. -/// -/// The class represents a map entry as a single object, -/// using a combined hashCode and equality of the key and value. -class _MapEntry { - final MapEquality equality; - final Object? key; - final Object? value; - _MapEntry(this.equality, this.key, this.value); - - @override - int get hashCode => - (3 * equality._keyEquality.hash(key) + - 7 * equality._valueEquality.hash(value)) & - _hashMask; - - @override - bool operator ==(Object other) => - other is _MapEntry && - equality._keyEquality.equals(key, other.key) && - equality._valueEquality.equals(value, other.value); -} - -/// Equality on maps. -/// -/// Two maps are equal if they have the same number of entries, and if the -/// entries of the two maps are pairwise equal on both key and value. -/// -/// The [equals] and [hash] methods accepts `null` values, -/// even if the [isValidKey] returns `false` for `null`. -/// The [hash] of `null` is `null.hashCode`. -class MapEquality implements Equality> { - final Equality _keyEquality; - final Equality _valueEquality; - const MapEquality( - {Equality keys = const DefaultEquality(), - Equality values = const DefaultEquality()}) - : _keyEquality = keys, - _valueEquality = values; - - @override - bool equals(Map? map1, Map? map2) { - if (identical(map1, map2)) return true; - if (map1 == null || map2 == null) return false; - var length = map1.length; - if (length != map2.length) return false; - Map<_MapEntry, int> equalElementCounts = HashMap(); - for (var key in map1.keys) { - var entry = _MapEntry(this, key, map1[key]); - var count = equalElementCounts[entry] ?? 0; - equalElementCounts[entry] = count + 1; - } - for (var key in map2.keys) { - var entry = _MapEntry(this, key, map2[key]); - var count = equalElementCounts[entry]; - if (count == null || count == 0) return false; - equalElementCounts[entry] = count - 1; - } - return true; - } - - @override - int hash(Map? map) { - if (map == null) return null.hashCode; - var hash = 0; - for (var key in map.keys) { - var keyHash = _keyEquality.hash(key); - var valueHash = _valueEquality.hash(map[key] as V); - hash = (hash + 3 * keyHash + 7 * valueHash) & _hashMask; - } - hash = (hash + (hash << 3)) & _hashMask; - hash ^= hash >> 11; - hash = (hash + (hash << 15)) & _hashMask; - return hash; - } - - @override - bool isValidKey(Object? o) => o is Map; -} - -/// Combines several equalities into a single equality. -/// -/// Tries each equality in order, using [Equality.isValidKey], and returns -/// the result of the first equality that applies to the argument or arguments. -/// -/// For `equals`, the first equality that matches the first argument is used, -/// and if the second argument of `equals` is not valid for that equality, -/// it returns false. -/// -/// Because the equalities are tried in order, they should generally work on -/// disjoint types. Otherwise the multi-equality may give inconsistent results -/// for `equals(e1, e2)` and `equals(e2, e1)`. This can happen if one equality -/// considers only `e1` a valid key, and not `e2`, but an equality which is -/// checked later, allows both. -class MultiEquality implements Equality { - final Iterable> _equalities; - - const MultiEquality(Iterable> equalities) - : _equalities = equalities; - - @override - bool equals(E e1, E e2) { - for (var eq in _equalities) { - if (eq.isValidKey(e1)) return eq.isValidKey(e2) && eq.equals(e1, e2); - } - return false; - } - - @override - int hash(E e) { - for (var eq in _equalities) { - if (eq.isValidKey(e)) return eq.hash(e); - } - return 0; - } - - @override - bool isValidKey(Object? o) { - for (var eq in _equalities) { - if (eq.isValidKey(o)) return true; - } - return false; - } -} - -/// Deep equality on collections. -/// -/// Recognizes lists, sets, iterables and maps and compares their elements using -/// deep equality as well. -/// -/// Non-iterable/map objects are compared using a configurable base equality. -/// -/// Works in one of two modes: ordered or unordered. -/// -/// In ordered mode, lists and iterables are required to have equal elements -/// in the same order. In unordered mode, the order of elements in iterables -/// and lists are not important. -/// -/// A list is only equal to another list, likewise for sets and maps. All other -/// iterables are compared as iterables only. -class DeepCollectionEquality implements Equality { - final Equality _base; - final bool _unordered; - const DeepCollectionEquality([Equality base = const DefaultEquality()]) - : _base = base, - _unordered = false; - - /// Creates a deep equality on collections where the order of lists and - /// iterables are not considered important. That is, lists and iterables are - /// treated as unordered iterables. - const DeepCollectionEquality.unordered( - [Equality base = const DefaultEquality()]) - : _base = base, - _unordered = true; - - @override - bool equals(Object? e1, Object? e2) { - if (e1 is Set) { - return e2 is Set && SetEquality(this).equals(e1, e2); - } - if (e1 is Map) { - return e2 is Map && MapEquality(keys: this, values: this).equals(e1, e2); - } - if (!_unordered) { - if (e1 is List) { - return e2 is List && ListEquality(this).equals(e1, e2); - } - if (e1 is Iterable) { - return e2 is Iterable && IterableEquality(this).equals(e1, e2); - } - } else if (e1 is Iterable) { - if (e1 is List != e2 is List) return false; - return e2 is Iterable && UnorderedIterableEquality(this).equals(e1, e2); - } - return _base.equals(e1, e2); - } - - @override - int hash(Object? o) { - if (o is Set) return SetEquality(this).hash(o); - if (o is Map) return MapEquality(keys: this, values: this).hash(o); - if (!_unordered) { - if (o is List) return ListEquality(this).hash(o); - if (o is Iterable) return IterableEquality(this).hash(o); - } else if (o is Iterable) { - return UnorderedIterableEquality(this).hash(o); - } - return _base.hash(o); - } - - @override - bool isValidKey(Object? o) => - o is Iterable || o is Map || _base.isValidKey(o); -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/utils/hex.dart b/packages/flutter_blue_plus_platform_interface/lib/src/utils/hex.dart deleted file mode 100644 index 0db508f8..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/utils/hex.dart +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright 2015, the Dart project authors. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// coverage:ignore-file - -import 'dart:convert'; -import 'dart:typed_data'; - -/// The canonical instance of [HexCodec]. -const hex = HexCodec._(); - -/// A codec that converts byte arrays to and from hexadecimal strings, following -/// [the Base16 spec](https://tools.ietf.org/html/rfc4648#section-8). -/// -/// This should be used via the [hex] field. -class HexCodec extends Codec, String> { - const HexCodec._(); - - @override - HexEncoder get encoder { - return const HexEncoder._(); - } - - @override - HexDecoder get decoder { - return const HexDecoder._(); - } -} - -/// A converter that encodes byte arrays into hexadecimal strings. -/// -/// This will throw a [RangeError] if the byte array has any digits that don't -/// fit in the gamut of a byte. -class HexEncoder extends Converter, String> { - const HexEncoder._(); - - @override - String convert(List input) { - return _convert(input, 0, input.length); - } - - @override - ByteConversionSink startChunkedConversion(Sink sink) { - return _HexEncoderSink(sink); - } -} - -/// A conversion sink for chunked hexadecimal encoding. -class _HexEncoderSink extends ByteConversionSinkBase { - /// The underlying sink to which decoded byte arrays will be passed. - final Sink _sink; - - _HexEncoderSink(this._sink); - - @override - void add(List chunk) { - _sink.add(_convert(chunk, 0, chunk.length)); - } - - @override - void addSlice(List chunk, int start, int end, bool isLast) { - RangeError.checkValidRange(start, end, chunk.length); - _sink.add(_convert(chunk, start, end)); - if (isLast) _sink.close(); - } - - @override - void close() { - _sink.close(); - } -} - -String _convert(List bytes, int start, int end) { - // A Uint8List is more efficient than a StringBuffer given that we know that - // we're only emitting ASCII-compatible characters, and that we know the - // length ahead of time. - var buffer = Uint8List((end - start) * 2); - var bufferIndex = 0; - - // A bitwise OR of all bytes in [bytes]. This allows us to check for - // out-of-range bytes without adding more branches than necessary to the - // core loop. - var byteOr = 0; - for (var i = start; i < end; i++) { - var byte = bytes[i]; - byteOr |= byte; - - // The bitwise arithmetic here is equivalent to `byte ~/ 16` and `byte % 16` - // for valid byte values, but is easier for dart2js to optimize given that - // it can't prove that [byte] will always be positive. - buffer[bufferIndex++] = _codeUnitForDigit((byte & 0xF0) >> 4); - buffer[bufferIndex++] = _codeUnitForDigit(byte & 0x0F); - } - - if (byteOr >= 0 && byteOr <= 255) return String.fromCharCodes(buffer); - - // If there was an invalid byte, find it and throw an exception. - for (var i = start; i < end; i++) { - var byte = bytes[i]; - if (byte >= 0 && byte <= 0xff) continue; - throw FormatException( - "Invalid byte ${byte < 0 ? "-" : ""}0x${byte.abs().toRadixString(16)}.", - bytes, - i, - ); - } - - throw StateError('unreachable'); -} - -/// Returns the ASCII/Unicode code unit corresponding to the hexadecimal digit -/// [digit]. -int _codeUnitForDigit(int digit) { - return digit < 10 ? digit + 0x30 : digit + 0x61 - 10; -} - -/// A converter that decodes hexadecimal strings into byte arrays. -/// -/// Because two hexadecimal digits correspond to a single byte, this will throw -/// a [FormatException] if given an odd-length string. It will also throw a -/// [FormatException] if given a string containing non-hexadecimal code units. -class HexDecoder extends Converter> { - const HexDecoder._(); - - @override - Uint8List convert(String input) { - if (!input.length.isEven) { - throw FormatException( - 'Invalid input length, must be even.', - input, - input.length, - ); - } - - var bytes = Uint8List(input.length ~/ 2); - _decode(input.codeUnits, 0, input.length, bytes, 0); - return bytes; - } - - @override - StringConversionSink startChunkedConversion(Sink> sink) { - return _HexDecoderSink(sink); - } -} - -/// A conversion sink for chunked hexadecimal decoding. -class _HexDecoderSink extends StringConversionSinkBase { - /// The underlying sink to which decoded byte arrays will be passed. - final Sink> _sink; - - /// The trailing digit from the previous string. - /// - /// This will be non-`null` if the most recent string had an odd number of - /// hexadecimal digits. Since it's the most significant digit, it's always a - /// multiple of 16. - int? _lastDigit; - - _HexDecoderSink(this._sink); - - @override - void addSlice(String string, int start, int end, bool isLast) { - RangeError.checkValidRange(start, end, string.length); - - if (start == end) { - if (isLast) _close(string, end); - return; - } - - var codeUnits = string.codeUnits; - Uint8List bytes; - int bytesStart; - if (_lastDigit == null) { - bytes = Uint8List((end - start) ~/ 2); - bytesStart = 0; - } else { - var hexPairs = (end - start - 1) ~/ 2; - bytes = Uint8List(1 + hexPairs); - bytes[0] = _lastDigit! + _digitForCodeUnit(codeUnits, start); - start++; - bytesStart = 1; - } - - _lastDigit = _decode(codeUnits, start, end, bytes, bytesStart); - - _sink.add(bytes); - if (isLast) _close(string, end); - } - - @override - ByteConversionSink asUtf8Sink(bool allowMalformed) { - return _HexDecoderByteSink(_sink); - } - - @override - void close() => _close(); - - /// Like [close], but includes [string] and [index] in the [FormatException] - /// if one is thrown. - void _close([String? string, int? index]) { - if (_lastDigit != null) { - throw FormatException( - 'Input ended with incomplete encoded byte.', - string, - index, - ); - } - - _sink.close(); - } -} - -/// A conversion sink for chunked hexadecimal decoding from UTF-8 bytes. -class _HexDecoderByteSink extends ByteConversionSinkBase { - /// The underlying sink to which decoded byte arrays will be passed. - final Sink> _sink; - - /// The trailing digit from the previous string. - /// - /// This will be non-`null` if the most recent string had an odd number of - /// hexadecimal digits. Since it's the most significant digit, it's always a - /// multiple of 16. - int? _lastDigit; - - _HexDecoderByteSink(this._sink); - - @override - void add(List chunk) { - addSlice(chunk, 0, chunk.length, false); - } - - @override - void addSlice(List chunk, int start, int end, bool isLast) { - RangeError.checkValidRange(start, end, chunk.length); - - if (start == end) { - if (isLast) _close(chunk, end); - return; - } - - Uint8List bytes; - int bytesStart; - if (_lastDigit == null) { - bytes = Uint8List((end - start) ~/ 2); - bytesStart = 0; - } else { - var hexPairs = (end - start - 1) ~/ 2; - bytes = Uint8List(1 + hexPairs); - bytes[0] = _lastDigit! + _digitForCodeUnit(chunk, start); - start++; - bytesStart = 1; - } - - _lastDigit = _decode(chunk, start, end, bytes, bytesStart); - - _sink.add(bytes); - if (isLast) _close(chunk, end); - } - - @override - void close() { - _close(); - } - - /// Like [close], but includes [chunk] and [index] in the [FormatException] - /// if one is thrown. - void _close([List? chunk, int? index]) { - if (_lastDigit != null) { - throw FormatException( - 'Input ended with incomplete encoded byte.', - chunk, - index, - ); - } - - _sink.close(); - } -} - -/// Decodes [codeUnits] and writes the result into [destination]. -/// -/// This reads from [codeUnits] between [sourceStart] and [sourceEnd]. It writes -/// the result into [destination] starting at [destinationStart]. -/// -/// If there's a leftover digit at the end of the decoding, this returns that -/// digit. Otherwise it returns `null`. -int? _decode( - List codeUnits, - int sourceStart, - int sourceEnd, - List destination, - int destinationStart, -) { - var destinationIndex = destinationStart; - for (var i = sourceStart; i < sourceEnd - 1; i += 2) { - var firstDigit = _digitForCodeUnit(codeUnits, i); - var secondDigit = _digitForCodeUnit(codeUnits, i + 1); - destination[destinationIndex++] = 16 * firstDigit + secondDigit; - } - - if ((sourceEnd - sourceStart).isEven) return null; - return 16 * _digitForCodeUnit(codeUnits, sourceEnd - 1); -} - -/// Returns the digit (0 through 15) corresponding to the hexadecimal code unit -/// at index [index] in [codeUnits]. -/// -/// If the given code unit isn't valid hexadecimal, throws a [FormatException]. -int _digitForCodeUnit( - List codeUnits, - int index, -) { - // If the code unit is a numeral, get its value. XOR works because 0 in ASCII - // is `0b110000` and the other numerals come after it in ascending order and - // take up at most four bits. - // - // We check for digits first because it ensures there's only a single branch - // for 10 out of 16 of the expected cases. We don't count the `digit >= 0` - // check because branch prediction will always work on it for valid data. - var codeUnit = codeUnits[index]; - var digit = 0x30 ^ codeUnit; - if (digit <= 9) { - if (digit >= 0) return digit; - } else { - // If the code unit is an uppercase letter, convert it to lowercase. This - // works because uppercase letters in ASCII are exactly `0b100000 = 0x20` - // less than lowercase letters, so if we ensure that that bit is 1 we ensure - // that the letter is lowercase. - var letter = 0x20 | codeUnit; - if (0x61 <= letter && letter <= 0x66) return letter - 0x61 + 10; - } - - throw FormatException( - 'Invalid hexadecimal code unit ' - "U+${codeUnit.toRadixString(16).padLeft(4, '0')}.", - codeUnits, - index, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/utils/utils.dart b/packages/flutter_blue_plus_platform_interface/lib/src/utils/utils.dart deleted file mode 100644 index 94a44200..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/utils/utils.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'equality.dart'; -export 'hex.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index b2952616..ad5970e4 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -8,6 +8,8 @@ environment: flutter: ">=2.0.0" dependencies: + collection: ^1.15.0 + convert: ^3.0.0 flutter: sdk: flutter plugin_platform_interface: ^2.0.0 diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart index 48f71e75..79197271 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart @@ -1,5 +1,5 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart index 98c18c2c..7a3f4bef 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart @@ -1,5 +1,5 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart index 5b07e287..57f793d5 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart @@ -1,5 +1,6 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart index e7096be4..f07a30eb 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart @@ -1,5 +1,6 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart index d7df6914..42d7d8f3 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart @@ -1,5 +1,5 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart index 6c482e77..6dad4753 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart @@ -1,5 +1,6 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart index 75200dd3..4606f5bd 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart @@ -1,5 +1,6 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart index 34bc770e..c3890127 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart @@ -1,5 +1,5 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart index c90dbcc3..3132a207 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart @@ -1,5 +1,5 @@ +import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart index 1e241a8d..fedcb704 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart @@ -1,5 +1,6 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart index f4ef3688..4b5c169b 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart @@ -1,5 +1,6 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart index 4a2c8d79..5ec1cf2c 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart @@ -1,5 +1,6 @@ +import 'package:collection/collection.dart'; +import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/utils/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { From 44780db7cae9dad530e37a6466a809cf1ef82066 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:41 +0100 Subject: [PATCH 50/90] Revert "refactor: reorganize based on conventions" This reverts commit cf1667dfa8e9dd90caf63ba87ecaa068956ac35a. --- .../flutter_blue_plus_platform_interface.dart | 43 ++- .../enums}/bm_adapter_state_enum.dart | 0 .../models}/bm_bluetooth_adapter_state.dart | 2 +- .../models}/bm_turn_on_response.dart | 0 .../enums}/bm_write_type.dart | 0 .../models}/bm_bluetooth_characteristic.dart | 6 +- .../models}/bm_characteristic_data.dart | 4 +- .../models}/bm_characteristic_properties.dart | 0 .../bm_read_characteristic_request.dart | 4 +- .../models}/bm_set_notify_value_request.dart | 4 +- .../bm_write_characteristic_request.dart | 6 +- .../{types => common/enums}/log_level.dart | 0 .../models}/device_identifier.dart | 0 .../src/{types => common/models}/guid.dart | 0 .../src/{types => common/models}/options.dart | 0 .../{types => common/models}/phy_support.dart | 0 .../models}/bm_bluetooth_descriptor.dart | 4 +- .../models}/bm_descriptor_data.dart | 4 +- .../models}/bm_read_descriptor_request.dart | 4 +- .../models}/bm_write_descriptor_request.dart | 4 +- .../enums}/bm_bond_state_enum.dart | 0 .../enums}/bm_connection_priority_enum.dart | 0 .../enums}/bm_connection_state_enum.dart | 0 .../models}/bm_bluetooth_device.dart | 2 +- .../models}/bm_bond_state_response.dart | 4 +- .../models}/bm_connect_request.dart | 2 +- .../bm_connection_priority_request.dart | 4 +- .../models}/bm_connection_state_response.dart | 4 +- .../models}/bm_devices_list.dart | 0 .../models}/bm_mtu_change_request.dart | 2 +- .../models}/bm_mtu_changed_response.dart | 2 +- .../models}/bm_name_changed.dart | 2 +- .../models}/bm_preferred_phy.dart | 2 +- .../models}/bm_read_rssi_result.dart | 2 +- .../flutter_blue_plus_platform.dart | 32 +- .../method_channel_flutter_blue_plus.dart | 30 +- .../{types => scan/models}/bm_msd_filter.dart | 0 .../models}/bm_scan_advertisement.dart | 4 +- .../models}/bm_scan_response.dart | 0 .../models}/bm_scan_settings.dart | 2 +- .../models}/bm_service_data_filter.dart | 2 +- .../models}/bm_bluetooth_service.dart | 6 +- .../models}/bm_discover_services_result.dart | 2 +- .../lib/src/types/types.dart | 40 --- .../bm_bluetooth_adapter_state_test.dart | 0 .../bm_bluetooth_characteristic_test.dart | 0 .../bm_bluetooth_descriptor_test.dart | 0 .../bm_bluetooth_service_test.dart | 0 .../bm_bond_state_response_test.dart | 12 +- .../bm_characteristic_data_test.dart | 0 .../bm_characteristic_properties_test.dart | 0 .../bm_connection_priority_request_test.dart | 6 +- .../bm_connection_state_response_test.dart | 6 +- .../{types => }/bm_descriptor_data_test.dart | 0 .../{types => }/bm_devices_list_test.dart | 2 +- .../bm_discover_services_result_test.dart | 0 .../test/{types => }/bm_msd_filter_test.dart | 0 .../bm_mtu_changed_response_test.dart | 6 +- .../bm_read_characteristic_request_test.dart | 0 .../bm_read_descriptor_request_test.dart | 0 .../{types => }/bm_read_rssi_result_test.dart | 6 +- .../bm_scan_advertisement_test.dart | 0 .../{types => }/bm_scan_response_test.dart | 0 .../{types => }/bm_scan_settings_test.dart | 0 .../bm_service_data_filter_test.dart | 0 .../bm_set_notify_value_request_test.dart | 51 ++++ .../{types => }/bm_turn_on_response_test.dart | 0 .../bm_write_characteristic_request_test.dart | 2 +- .../bm_write_descriptor_request_test.dart | 0 .../{types => }/device_identifier_test.dart | 0 .../test/{types => }/guid_test.dart | 0 ...method_channel_flutter_blue_plus_test.dart | 152 +++++----- .../test/{types => }/options_test.dart | 0 .../test/{types => }/phy_support_test.dart | 0 .../bm_set_notify_value_request_test.dart | 284 ------------------ 75 files changed, 286 insertions(+), 470 deletions(-) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => adapter/enums}/bm_adapter_state_enum.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => adapter/models}/bm_bluetooth_adapter_state.dart (93%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => adapter/models}/bm_turn_on_response.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => characteristic/enums}/bm_write_type.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => characteristic/models}/bm_bluetooth_characteristic.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => characteristic/models}/bm_characteristic_data.dart (95%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => characteristic/models}/bm_characteristic_properties.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => characteristic/models}/bm_read_characteristic_request.dart (93%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => characteristic/models}/bm_set_notify_value_request.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => characteristic/models}/bm_write_characteristic_request.dart (93%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => common/enums}/log_level.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => common/models}/device_identifier.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => common/models}/guid.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => common/models}/options.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => common/models}/phy_support.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => descriptor/models}/bm_bluetooth_descriptor.dart (92%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => descriptor/models}/bm_descriptor_data.dart (96%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => descriptor/models}/bm_read_descriptor_request.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => descriptor/models}/bm_write_descriptor_request.dart (95%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/enums}/bm_bond_state_enum.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/enums}/bm_connection_priority_enum.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/enums}/bm_connection_state_enum.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_bluetooth_device.dart (90%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_bond_state_response.dart (89%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_connect_request.dart (90%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_connection_priority_request.dart (86%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_connection_state_response.dart (90%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_devices_list.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_mtu_change_request.dart (89%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_mtu_changed_response.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_name_changed.dart (89%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_preferred_phy.dart (92%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => device/models}/bm_read_rssi_result.dart (94%) rename packages/flutter_blue_plus_platform_interface/lib/src/{platform_interface => }/flutter_blue_plus_platform.dart (86%) rename packages/flutter_blue_plus_platform_interface/lib/src/{method_channel => }/method_channel_flutter_blue_plus.dart (87%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => scan/models}/bm_msd_filter.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => scan/models}/bm_scan_advertisement.dart (96%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => scan/models}/bm_scan_response.dart (100%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => scan/models}/bm_scan_settings.dart (98%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => scan/models}/bm_service_data_filter.dart (96%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => service/models}/bm_bluetooth_service.dart (92%) rename packages/flutter_blue_plus_platform_interface/lib/src/{types => service/models}/bm_discover_services_result.dart (96%) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_bluetooth_adapter_state_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_bluetooth_characteristic_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_bluetooth_descriptor_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_bluetooth_service_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_bond_state_response_test.dart (90%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_characteristic_data_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_characteristic_properties_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_connection_priority_request_test.dart (91%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_connection_state_response_test.dart (91%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_descriptor_data_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_devices_list_test.dart (95%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_discover_services_result_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_msd_filter_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_mtu_changed_response_test.dart (92%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_read_characteristic_request_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_read_descriptor_request_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_read_rssi_result_test.dart (92%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_scan_advertisement_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_scan_response_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_scan_settings_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_service_data_filter_test.dart (100%) create mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_turn_on_response_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_write_characteristic_request_test.dart (99%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/bm_write_descriptor_request_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/device_identifier_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/guid_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{method_channel => }/method_channel_flutter_blue_plus_test.dart (93%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/options_test.dart (100%) rename packages/flutter_blue_plus_platform_interface/test/{types => }/phy_support_test.dart (100%) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 1a25e3b6..e5a9820c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -1,5 +1,44 @@ -export 'src/platform_interface/flutter_blue_plus_platform.dart'; -export 'src/types/types.dart'; +export 'src/adapter/enums/bm_adapter_state_enum.dart'; +export 'src/adapter/models/bm_bluetooth_adapter_state.dart'; +export 'src/adapter/models/bm_turn_on_response.dart'; +export 'src/characteristic/enums/bm_write_type.dart'; +export 'src/characteristic/models/bm_bluetooth_characteristic.dart'; +export 'src/characteristic/models/bm_characteristic_data.dart'; +export 'src/characteristic/models/bm_characteristic_properties.dart'; +export 'src/characteristic/models/bm_read_characteristic_request.dart'; +export 'src/characteristic/models/bm_set_notify_value_request.dart'; +export 'src/characteristic/models/bm_write_characteristic_request.dart'; +export 'src/common/enums/log_level.dart'; +export 'src/common/models/device_identifier.dart'; +export 'src/common/models/guid.dart'; +export 'src/common/models/options.dart'; +export 'src/common/models/phy_support.dart'; +export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; +export 'src/descriptor/models/bm_descriptor_data.dart'; +export 'src/descriptor/models/bm_read_descriptor_request.dart'; +export 'src/descriptor/models/bm_write_descriptor_request.dart'; +export 'src/device/enums/bm_bond_state_enum.dart'; +export 'src/device/enums/bm_connection_priority_enum.dart'; +export 'src/device/enums/bm_connection_state_enum.dart'; +export 'src/device/models/bm_bluetooth_device.dart'; +export 'src/device/models/bm_bond_state_response.dart'; +export 'src/device/models/bm_connect_request.dart'; +export 'src/device/models/bm_connection_priority_request.dart'; +export 'src/device/models/bm_connection_state_response.dart'; +export 'src/device/models/bm_devices_list.dart'; +export 'src/device/models/bm_mtu_change_request.dart'; +export 'src/device/models/bm_mtu_changed_response.dart'; +export 'src/device/models/bm_name_changed.dart'; +export 'src/device/models/bm_preferred_phy.dart'; +export 'src/device/models/bm_read_rssi_result.dart'; +export 'src/flutter_blue_plus_platform.dart'; +export 'src/scan/models/bm_msd_filter.dart'; +export 'src/scan/models/bm_scan_advertisement.dart'; +export 'src/scan/models/bm_scan_response.dart'; +export 'src/scan/models/bm_scan_settings.dart'; +export 'src/scan/models/bm_service_data_filter.dart'; +export 'src/service/models/bm_bluetooth_service.dart'; +export 'src/service/models/bm_discover_services_result.dart'; // random number defined by flutter blue plus int bmUserCanceledErrorCode = 23789258; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_adapter_state_enum.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart similarity index 93% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart index f6dbbc8e..949178f3 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_adapter_state.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart @@ -1,4 +1,4 @@ -import 'bm_adapter_state_enum.dart'; +import '../enums/bm_adapter_state_enum.dart'; class BmBluetoothAdapterState { BmAdapterStateEnum adapterState; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_turn_on_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_type.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart index ca244583..a59ed0e9 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart @@ -1,9 +1,9 @@ import 'package:collection/collection.dart'; -import 'guid.dart'; -import 'bm_bluetooth_descriptor.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; +import '../../descriptor/models/bm_bluetooth_descriptor.dart'; import 'bm_characteristic_properties.dart'; -import 'device_identifier.dart'; class BmBluetoothCharacteristic { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart similarity index 95% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart index f837cf35..df3698d4 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmCharacteristicData { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_characteristic_properties.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart similarity index 93% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart index 9c706891..aae99675 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart @@ -1,5 +1,5 @@ -import 'device_identifier.dart'; -import 'guid.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmReadCharacteristicRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart index 9d831817..4208f91c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_set_notify_value_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart @@ -1,5 +1,5 @@ -import 'device_identifier.dart'; -import 'guid.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmSetNotifyValueRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart similarity index 93% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart index 35482049..95504041 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart @@ -1,9 +1,9 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import 'bm_write_type.dart'; -import 'device_identifier.dart'; -import 'guid.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; +import '../enums/bm_write_type.dart'; class BmWriteCharacteristicRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/log_level.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/log_level.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/device_identifier.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/device_identifier.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/guid.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/options.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/options.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/phy_support.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/phy_support.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart index 9a0160ae..3c0ae230 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_descriptor.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart @@ -1,5 +1,5 @@ -import 'guid.dart'; -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmBluetoothDescriptor { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart similarity index 96% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart index ae9999db..a3d1045c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_descriptor_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import 'guid.dart'; -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmDescriptorData { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart index dec81238..5cb4de6f 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart @@ -1,5 +1,5 @@ -import 'guid.dart'; -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmReadDescriptorRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart similarity index 95% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart index 6634b1de..050cfeb5 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_write_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import 'guid.dart'; -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmWriteDescriptorRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_enum.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_enum.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_enum.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart similarity index 90% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart index 6a16229e..73ccb88b 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_device.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart @@ -1,4 +1,4 @@ -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; class BmBluetoothDevice { DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart similarity index 89% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart index bacb627e..c2258855 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bond_state_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart @@ -1,5 +1,5 @@ -import 'bm_bond_state_enum.dart'; -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; +import '../enums/bm_bond_state_enum.dart'; class BmBondStateResponse { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart similarity index 90% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart index b56394c8..ad0407d8 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connect_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart @@ -1,4 +1,4 @@ -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; class BmConnectRequest { DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart similarity index 86% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart index 118080c1..d9d0c1da 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_priority_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart @@ -1,5 +1,5 @@ -import 'bm_connection_priority_enum.dart'; -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; +import '../enums/bm_connection_priority_enum.dart'; class BmConnectionPriorityRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart similarity index 90% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart index 43553e89..084deb10 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_connection_state_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart @@ -1,5 +1,5 @@ -import 'bm_connection_state_enum.dart'; -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; +import '../enums/bm_connection_state_enum.dart'; class BmConnectionStateResponse { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_devices_list.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart similarity index 89% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart index 4c03df5f..86138397 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_change_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart @@ -1,4 +1,4 @@ -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; class BmMtuChangeRequest { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart index 2ffbc90b..ccd1c2ff 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_mtu_changed_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart @@ -1,4 +1,4 @@ -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; class BmMtuChangedResponse { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart similarity index 89% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart index 54597f3d..75fe4d8b 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_name_changed.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart @@ -1,4 +1,4 @@ -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; class BmNameChanged { DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart index b8accc11..d2c0b630 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_preferred_phy.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart @@ -1,4 +1,4 @@ -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; class BmPreferredPhy { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart similarity index 94% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart index b2436d63..81aa5822 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_read_rssi_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart @@ -1,4 +1,4 @@ -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; class BmReadRssiResult { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart similarity index 86% rename from packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index d99a4de9..31deb750 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -1,9 +1,33 @@ -// coverage:ignore-file - import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import '../method_channel/method_channel_flutter_blue_plus.dart'; -import '../types/types.dart'; +import 'adapter/models/bm_bluetooth_adapter_state.dart'; +import 'adapter/models/bm_turn_on_response.dart'; +import 'characteristic/models/bm_characteristic_data.dart'; +import 'characteristic/models/bm_read_characteristic_request.dart'; +import 'characteristic/models/bm_set_notify_value_request.dart'; +import 'characteristic/models/bm_write_characteristic_request.dart'; +import 'common/enums/log_level.dart'; +import 'common/models/device_identifier.dart'; +import 'common/models/options.dart'; +import 'common/models/phy_support.dart'; +import 'descriptor/models/bm_descriptor_data.dart'; +import 'descriptor/models/bm_read_descriptor_request.dart'; +import 'descriptor/models/bm_write_descriptor_request.dart'; +import 'device/models/bm_bluetooth_device.dart'; +import 'device/models/bm_bond_state_response.dart'; +import 'device/models/bm_connect_request.dart'; +import 'device/models/bm_connection_priority_request.dart'; +import 'device/models/bm_connection_state_response.dart'; +import 'device/models/bm_devices_list.dart'; +import 'device/models/bm_mtu_change_request.dart'; +import 'device/models/bm_mtu_changed_response.dart'; +import 'device/models/bm_name_changed.dart'; +import 'device/models/bm_preferred_phy.dart'; +import 'device/models/bm_read_rssi_result.dart'; +import 'method_channel_flutter_blue_plus.dart'; +import 'scan/models/bm_scan_response.dart'; +import 'scan/models/bm_scan_settings.dart'; +import 'service/models/bm_discover_services_result.dart'; /// The interface that implementations of flutter_blue_plus must implement. abstract class FlutterBluePlusPlatform extends PlatformInterface { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart similarity index 87% rename from packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index f30e1111..3814e1d2 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -3,8 +3,34 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; -import '../platform_interface/flutter_blue_plus_platform.dart'; -import '../types/types.dart'; +import 'adapter/models/bm_bluetooth_adapter_state.dart'; +import 'adapter/models/bm_turn_on_response.dart'; +import 'characteristic/models/bm_characteristic_data.dart'; +import 'characteristic/models/bm_read_characteristic_request.dart'; +import 'characteristic/models/bm_set_notify_value_request.dart'; +import 'characteristic/models/bm_write_characteristic_request.dart'; +import 'common/enums/log_level.dart'; +import 'common/models/device_identifier.dart'; +import 'common/models/options.dart'; +import 'common/models/phy_support.dart'; +import 'descriptor/models/bm_descriptor_data.dart'; +import 'descriptor/models/bm_read_descriptor_request.dart'; +import 'descriptor/models/bm_write_descriptor_request.dart'; +import 'device/models/bm_bluetooth_device.dart'; +import 'device/models/bm_bond_state_response.dart'; +import 'device/models/bm_connect_request.dart'; +import 'device/models/bm_connection_priority_request.dart'; +import 'device/models/bm_connection_state_response.dart'; +import 'device/models/bm_devices_list.dart'; +import 'device/models/bm_mtu_change_request.dart'; +import 'device/models/bm_mtu_changed_response.dart'; +import 'device/models/bm_name_changed.dart'; +import 'device/models/bm_preferred_phy.dart'; +import 'device/models/bm_read_rssi_result.dart'; +import 'flutter_blue_plus_platform.dart'; +import 'scan/models/bm_scan_response.dart'; +import 'scan/models/bm_scan_settings.dart'; +import 'service/models/bm_discover_services_result.dart'; /// An implementation of [FlutterBluePlusPlatform] that uses method channels. class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_msd_filter.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart similarity index 96% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart index 4c51b4d3..f4469fc6 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_advertisement.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import 'guid.dart'; -import 'device_identifier.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmScanAdvertisement { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_response.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart similarity index 98% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart index 978beed3..ab1eb303 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_scan_settings.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; +import '../../common/models/guid.dart'; import 'bm_msd_filter.dart'; import 'bm_service_data_filter.dart'; -import 'guid.dart'; class BmScanSettings { final List withServices; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart similarity index 96% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart index 489bc570..09e1af6e 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_service_data_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart @@ -1,7 +1,7 @@ import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; -import 'guid.dart'; +import '../../common/models/guid.dart'; class BmServiceDataFilter { Guid service; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart index f527820d..97551b18 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_bluetooth_service.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; -import 'guid.dart'; -import 'bm_bluetooth_characteristic.dart'; -import 'device_identifier.dart'; +import '../../characteristic/models/bm_bluetooth_characteristic.dart'; +import '../../common/models/device_identifier.dart'; +import '../../common/models/guid.dart'; class BmBluetoothService { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart similarity index 96% rename from packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart rename to packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart index b82d5b43..689c1eed 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/bm_discover_services_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart @@ -1,7 +1,7 @@ import 'package:collection/collection.dart'; +import '../../common/models/device_identifier.dart'; import 'bm_bluetooth_service.dart'; -import 'device_identifier.dart'; class BmDiscoverServicesResult { final DeviceIdentifier remoteId; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart b/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart deleted file mode 100644 index 7c3913d1..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/types/types.dart +++ /dev/null @@ -1,40 +0,0 @@ -export 'bm_adapter_state_enum.dart'; -export 'bm_bluetooth_adapter_state.dart'; -export 'bm_bluetooth_characteristic.dart'; -export 'bm_bluetooth_descriptor.dart'; -export 'bm_bluetooth_device.dart'; -export 'bm_bluetooth_service.dart'; -export 'bm_bond_state_enum.dart'; -export 'bm_bond_state_response.dart'; -export 'bm_characteristic_data.dart'; -export 'bm_characteristic_properties.dart'; -export 'bm_connect_request.dart'; -export 'bm_connection_priority_enum.dart'; -export 'bm_connection_priority_request.dart'; -export 'bm_connection_state_enum.dart'; -export 'bm_connection_state_response.dart'; -export 'bm_descriptor_data.dart'; -export 'bm_devices_list.dart'; -export 'bm_discover_services_result.dart'; -export 'bm_msd_filter.dart'; -export 'bm_mtu_change_request.dart'; -export 'bm_mtu_changed_response.dart'; -export 'bm_name_changed.dart'; -export 'bm_preferred_phy.dart'; -export 'bm_read_characteristic_request.dart'; -export 'bm_read_descriptor_request.dart'; -export 'bm_read_rssi_result.dart'; -export 'bm_scan_advertisement.dart'; -export 'bm_scan_response.dart'; -export 'bm_scan_settings.dart'; -export 'bm_service_data_filter.dart'; -export 'bm_set_notify_value_request.dart'; -export 'bm_turn_on_response.dart'; -export 'bm_write_characteristic_request.dart'; -export 'bm_write_descriptor_request.dart'; -export 'bm_write_type.dart'; -export 'device_identifier.dart'; -export 'guid.dart'; -export 'log_level.dart'; -export 'options.dart'; -export 'phy_support.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_adapter_state_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_characteristic_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_descriptor_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_bluetooth_service_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart similarity index 90% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart index b3d893c2..e03e9c5a 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_bond_state_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmBondStateResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'bond_state': 0, }).bondState, equals(BmBondStateEnum.none), @@ -26,7 +26,7 @@ void main() { () { expect( BmBondStateResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'bond_state': 0, 'prev_state': 0, }).prevState, @@ -41,7 +41,7 @@ void main() { expect( () { BmBondStateResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'bond_state': 3, }); }, @@ -56,7 +56,7 @@ void main() { expect( () { BmBondStateResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'bond_state': 0, 'prev_state': 3, }); @@ -76,7 +76,7 @@ void main() { () { expect( BmBondStateResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), bondState: BmBondStateEnum.none, ).toMap(), containsPair('bond_state', 0), @@ -89,7 +89,7 @@ void main() { () { expect( BmBondStateResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), bondState: BmBondStateEnum.none, prevState: BmBondStateEnum.none, ).toMap(), diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_data_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_characteristic_properties_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart similarity index 91% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart index 46d33333..03ed371f 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_priority_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmConnectionPriorityRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connection_priority': 0, }).connectionPriority, equals(BmConnectionPriorityEnum.balanced), @@ -27,7 +27,7 @@ void main() { expect( () { BmConnectionPriorityRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connection_priority': 3, }); }, @@ -46,7 +46,7 @@ void main() { () { expect( BmConnectionPriorityRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), connectionPriority: BmConnectionPriorityEnum.balanced, ).toMap(), containsPair('connection_priority', 0), diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart similarity index 91% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart index 4a33d69c..c9425121 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_connection_state_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmConnectionStateResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connection_state': 0, }).connectionState, equals(BmConnectionStateEnum.disconnected), @@ -27,7 +27,7 @@ void main() { expect( () { BmConnectionStateResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connection_state': 2, }); }, @@ -46,7 +46,7 @@ void main() { () { expect( BmConnectionStateResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), connectionState: BmConnectionStateEnum.disconnected, ).toMap(), containsPair('connection_state', 0), diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_descriptor_data_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart similarity index 95% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart index 0beef270..e1edfa34 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_devices_list_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart @@ -15,7 +15,7 @@ void main() { BmDevicesList.fromMap({ 'devices': null, }).devices, - equals([]), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_discover_services_result_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_msd_filter_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart index b2386ec5..4b92659e 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_mtu_changed_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmMtuChangedResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'mtu': 0, 'success': 0, 'error_code': 0, @@ -29,7 +29,7 @@ void main() { () { expect( BmMtuChangedResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'mtu': 0, 'success': null, 'error_code': 0, @@ -45,7 +45,7 @@ void main() { () { expect( BmMtuChangedResponse.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'mtu': 0, 'success': 1, 'error_code': 0, diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_read_characteristic_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_read_descriptor_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart similarity index 92% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart index 4af76ce0..851a4c10 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_read_rssi_result_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart @@ -13,7 +13,7 @@ void main() { () { expect( BmReadRssiResult.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'rssi': 0, 'success': 0, 'error_code': 0, @@ -29,7 +29,7 @@ void main() { () { expect( BmReadRssiResult.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'rssi': 0, 'success': null, 'error_code': 0, @@ -45,7 +45,7 @@ void main() { () { expect( BmReadRssiResult.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'rssi': 0, 'success': 1, 'error_code': 0, diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_scan_advertisement_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_scan_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_scan_settings_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_service_data_filter_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart new file mode 100644 index 00000000..2dcb0ae7 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart @@ -0,0 +1,51 @@ +import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group( + 'BmSetNotifyValueRequest', + () { + group( + 'fromMap', + () { + test( + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', + () { + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': '0102', + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), + ); + }, + ); + + test( + 'deserializes the secondary service uuid property as null if it is null', + () { + expect( + BmSetNotifyValueRequest.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'secondary_service_uuid': null, + 'characteristic_uuid': '0102', + 'force_indications': false, + 'enable': false, + }).secondaryServiceUuid, + isNull, + ); + }, + ); + }, + ); + }, + ); +} diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_turn_on_response_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart similarity index 99% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart index 4b5c169b..c81239b2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart @@ -151,7 +151,7 @@ void main() { 'allow_long_write': 0, 'value': null, }).value, - equals([]), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/bm_write_descriptor_request_test.dart rename to packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart b/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/device_identifier_test.dart rename to packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/guid_test.dart rename to packages/flutter_blue_plus_platform_interface/test/guid_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart similarity index 93% rename from packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart rename to packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart index c799341b..39b821b2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/method_channel/method_channel_flutter_blue_plus_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart @@ -1,6 +1,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/method_channel/method_channel_flutter_blue_plus.dart'; +import 'package:flutter_blue_plus_platform_interface/src/method_channel_flutter_blue_plus.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -72,7 +72,7 @@ void main() { 'deserializes the event', () async { final arguments = BmBondStateResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), bondState: BmBondStateEnum.none, ).toMap(); @@ -98,7 +98,7 @@ void main() { 'handles the method call', () async { final arguments = BmBondStateResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), bondState: BmBondStateEnum.none, ).toMap(); @@ -125,7 +125,7 @@ void main() { 'deserializes the event', () async { final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), value: [], @@ -156,7 +156,7 @@ void main() { 'handles the method call', () async { final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), value: [], @@ -188,7 +188,7 @@ void main() { 'deserializes the event', () async { final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), value: [], @@ -219,7 +219,7 @@ void main() { 'handles the method call', () async { final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), value: [], @@ -251,7 +251,7 @@ void main() { 'deserializes the event', () async { final arguments = BmConnectionStateResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), connectionState: BmConnectionStateEnum.disconnected, ).toMap(); @@ -277,7 +277,7 @@ void main() { 'handles the method call', () async { final arguments = BmConnectionStateResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), connectionState: BmConnectionStateEnum.disconnected, ).toMap(); @@ -304,7 +304,7 @@ void main() { 'deserializes the event', () async { final arguments = BmDescriptorData( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -336,7 +336,7 @@ void main() { 'handles the method call', () async { final arguments = BmDescriptorData( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -369,7 +369,7 @@ void main() { 'deserializes the event', () async { final arguments = BmDescriptorData( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -401,7 +401,7 @@ void main() { 'handles the method call', () async { final arguments = BmDescriptorData( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -455,7 +455,7 @@ void main() { 'deserializes the event', () async { final arguments = BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), services: [], success: true, errorCode: 0, @@ -484,7 +484,7 @@ void main() { 'handles the method call', () async { final arguments = BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), services: [], success: true, errorCode: 0, @@ -514,7 +514,7 @@ void main() { 'deserializes the event', () async { final arguments = BmMtuChangedResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), mtu: 0, success: true, errorCode: 0, @@ -543,7 +543,7 @@ void main() { 'handles the method call', () async { final arguments = BmMtuChangedResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), mtu: 0, success: true, errorCode: 0, @@ -573,7 +573,7 @@ void main() { 'deserializes the event', () async { final arguments = BmNameChanged( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), name: '', ).toMap(); @@ -599,7 +599,7 @@ void main() { 'handles the method call', () async { final arguments = BmNameChanged( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), name: '', ).toMap(); @@ -626,7 +626,7 @@ void main() { 'deserializes the event', () async { final arguments = BmReadRssiResult( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), rssi: 0, success: true, errorCode: 0, @@ -655,7 +655,7 @@ void main() { 'handles the method call', () async { final arguments = BmReadRssiResult( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), rssi: 0, success: true, errorCode: 0, @@ -742,7 +742,7 @@ void main() { 'deserializes the event', () async { final arguments = BmBluetoothDevice( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), ).toMap(); expectLater( @@ -767,7 +767,7 @@ void main() { 'handles the method call', () async { final arguments = BmBluetoothDevice( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), ).toMap(); expectLater( @@ -843,13 +843,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); await flutterBluePlus.clearGattCache(device); expect( log, - equals([ + orderedEquals([ isMethodCall( 'clearGattCache', arguments: device.str, @@ -884,7 +884,7 @@ void main() { 'deserializes the result', () async { final request = BmConnectRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), autoConnect: false, ); @@ -899,7 +899,7 @@ void main() { 'invokes the method', () async { final request = BmConnectRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), autoConnect: false, ); @@ -907,7 +907,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'connect', arguments: request.toMap(), @@ -955,7 +955,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'connectedCount', arguments: null, @@ -989,7 +989,7 @@ void main() { test( 'deserializes the result', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); expect( await flutterBluePlus.createBond(device), @@ -1001,13 +1001,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); await flutterBluePlus.createBond(device); expect( log, - equals([ + orderedEquals([ isMethodCall( 'createBond', arguments: device.str, @@ -1041,7 +1041,7 @@ void main() { test( 'deserializes the result', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); expect( await flutterBluePlus.disconnect(device), @@ -1053,13 +1053,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); await flutterBluePlus.disconnect(device); expect( log, - equals([ + orderedEquals([ isMethodCall( 'disconnect', arguments: device.str, @@ -1077,13 +1077,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); await flutterBluePlus.discoverServices(device); expect( log, - equals([ + orderedEquals([ isMethodCall( 'discoverServices', arguments: device.str, @@ -1131,7 +1131,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'flutterRestart', arguments: null, @@ -1179,7 +1179,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'getAdapterName', arguments: null, @@ -1229,7 +1229,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'getAdapterState', arguments: null, @@ -1245,7 +1245,7 @@ void main() { 'getBondState', () { final result = BmBondStateResponse( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), bondState: BmBondStateEnum.none, ); @@ -1266,7 +1266,7 @@ void main() { test( 'deserializes the result', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); expect( (await flutterBluePlus.getBondState(device)).toMap(), @@ -1278,13 +1278,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); await flutterBluePlus.getBondState(device); expect( log, - equals([ + orderedEquals([ isMethodCall( 'getBondState', arguments: device.str, @@ -1334,7 +1334,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'getBondedDevices', arguments: null, @@ -1385,7 +1385,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'getPhySupport', arguments: null, @@ -1435,7 +1435,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'getSystemDevices', arguments: null, @@ -1483,7 +1483,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'isSupported', arguments: null, @@ -1502,7 +1502,7 @@ void main() { 'invokes the method', () async { final request = BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), ); @@ -1511,7 +1511,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'readCharacteristic', arguments: request.toMap(), @@ -1530,7 +1530,7 @@ void main() { 'invokes the method', () async { final request = BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -1540,7 +1540,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'readDescriptor', arguments: request.toMap(), @@ -1558,13 +1558,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); await flutterBluePlus.readRssi(device); expect( log, - equals([ + orderedEquals([ isMethodCall( 'readRssi', arguments: device.str, @@ -1598,7 +1598,7 @@ void main() { test( 'deserializes the result', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); expect( await flutterBluePlus.removeBond(device), @@ -1610,13 +1610,13 @@ void main() { test( 'invokes the method', () async { - final device = DeviceIdentifier('str'); + final device = DeviceIdentifier(''); await flutterBluePlus.removeBond(device); expect( log, - equals([ + orderedEquals([ isMethodCall( 'removeBond', arguments: device.str, @@ -1635,7 +1635,7 @@ void main() { 'invokes the method', () async { final request = BmConnectionPriorityRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), connectionPriority: BmConnectionPriorityEnum.balanced, ); @@ -1643,7 +1643,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'requestConnectionPriority', arguments: request.toMap(), @@ -1662,7 +1662,7 @@ void main() { 'invokes the method', () async { final request = BmMtuChangeRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), mtu: 0, ); @@ -1670,7 +1670,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'requestMtu', arguments: request.toMap(), @@ -1694,7 +1694,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'setLogLevel', arguments: level.index, @@ -1729,7 +1729,7 @@ void main() { 'deserializes the result', () async { final request = BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), forceIndications: false, @@ -1747,7 +1747,7 @@ void main() { 'invokes the method', () async { final request = BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), forceIndications: false, @@ -1758,7 +1758,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'setNotifyValue', arguments: request.toMap(), @@ -1784,7 +1784,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'setOptions', arguments: options.toMap(), @@ -1803,7 +1803,7 @@ void main() { 'invokes the method', () async { final preferredPhy = BmPreferredPhy( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), txPhy: 0, rxPhy: 0, phyOptions: 0, @@ -1813,7 +1813,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'setPreferredPhy', arguments: preferredPhy.toMap(), @@ -1849,7 +1849,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'startScan', arguments: settings.toMap(), @@ -1871,7 +1871,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'stopScan', arguments: null, @@ -1893,7 +1893,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'turnOff', arguments: null, @@ -1941,7 +1941,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'turnOn', arguments: null, @@ -1960,7 +1960,7 @@ void main() { 'invokes the method', () async { final request = BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), writeType: BmWriteType.withResponse, @@ -1972,7 +1972,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'writeCharacteristic', arguments: request.toMap(), @@ -1991,7 +1991,7 @@ void main() { 'invokes the method', () async { final request = BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), descriptorUuid: Guid('0102'), @@ -2002,7 +2002,7 @@ void main() { expect( log, - equals([ + orderedEquals([ isMethodCall( 'writeDescriptor', arguments: request.toMap(), diff --git a/packages/flutter_blue_plus_platform_interface/test/types/options_test.dart b/packages/flutter_blue_plus_platform_interface/test/options_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/options_test.dart rename to packages/flutter_blue_plus_platform_interface/test/options_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart b/packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart similarity index 100% rename from packages/flutter_blue_plus_platform_interface/test/types/phy_support_test.dart rename to packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart deleted file mode 100644 index 4ce9ebe5..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/types/bm_set_notify_value_request_test.dart +++ /dev/null @@ -1,284 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmSetNotifyValueRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'force_indications': false, - 'enable': false, - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final forceIndications = false; - final enable = false; - - expect( - BmSetNotifyValueRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - forceIndications: forceIndications, - enable: enable, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - forceIndications.hashCode ^ - enable.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ) == - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ) == - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmSetNotifyValueRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmSetNotifyValueRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - }, - ); - }, - ); -} From d4d0ec022a0575d005427fd95edfe724fa840845 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:42 +0100 Subject: [PATCH 51/90] Revert "test: update common models" This reverts commit f23aaaa3751545fb1267cb8ec7ac99623da9f276. --- .../src/common/models/device_identifier.dart | 2 +- .../lib/src/common/models/options.dart | 11 -- .../lib/src/common/models/phy_support.dart | 11 -- .../test/device_identifier_test.dart | 36 +---- .../test/guid_test.dart | 91 +---------- .../test/options_test.dart | 104 ------------- .../test/phy_support_test.dart | 145 ------------------ 7 files changed, 11 insertions(+), 389 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/options_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart index 6206eaa4..2d090b93 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart @@ -19,7 +19,7 @@ class DeviceIdentifier { } @override - bool operator ==(Object other) { + bool operator ==(other) { return other is DeviceIdentifier && hashCode == other.hashCode; } } diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart index eacd2c97..fec83483 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart @@ -14,17 +14,6 @@ class Options { ); } - @override - bool operator ==(Object other) { - return identical(this, other) || - other is Options && hashCode == other.hashCode; - } - - @override - int get hashCode { - return showPowerAlert.hashCode; - } - Map toMap() { return { 'show_power_alert': showPowerAlert, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart index f4530d4c..dc779840 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart @@ -19,17 +19,6 @@ class PhySupport { ); } - @override - int get hashCode { - return le2M.hashCode ^ leCoded.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is PhySupport && hashCode == other.hashCode; - } - Map toMap() { return { 'le_2M': le2M, diff --git a/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart b/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart index 87da0ac3..b08a090d 100644 --- a/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart @@ -40,26 +40,11 @@ void main() { }, ); - group( - 'id', - () { - test( - 'returns the str property', - () { - expect( - DeviceIdentifier('str').id, - equals('str'), - ); - }, - ); - }, - ); - group( '==', () { test( - 'returns false if they are not equal', + 'returns false if the identifiers are not equal', () { expect( DeviceIdentifier('str1') == DeviceIdentifier('str2'), @@ -69,7 +54,7 @@ void main() { ); test( - 'returns true if they are equal', + 'returns true if the identifiers are equal', () { expect( DeviceIdentifier('str') == DeviceIdentifier('str'), @@ -79,7 +64,7 @@ void main() { ); test( - 'returns true if they are equal ignoring case', + 'returns true if the identifiers are equal ignoring case', () { expect( DeviceIdentifier('str') == DeviceIdentifier('STR'), @@ -89,21 +74,6 @@ void main() { ); }, ); - - group( - 'toString', - () { - test( - 'returns the str property', - () { - expect( - DeviceIdentifier('str').toString(), - equals('str'), - ); - }, - ); - }, - ); }, ); } diff --git a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart index 3ec20d5a..14af0716 100644 --- a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart @@ -5,38 +5,6 @@ void main() { group( 'Guid', () { - group( - 'empty', - () { - test( - 'constructs an instance', - () { - expect( - Guid.empty().bytes, - equals([ - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - ]), - ); - }, - ); - }, - ); - group( 'fromBytes', () { @@ -48,7 +16,7 @@ void main() { 0x01, 0x02, ]).bytes, - equals([ + orderedEquals([ 0x01, 0x02, ]), @@ -66,7 +34,7 @@ void main() { 0x03, 0x04, ]).bytes, - equals([ + orderedEquals([ 0x01, 0x02, 0x03, @@ -98,7 +66,7 @@ void main() { 0x34, 0xFB, ]).bytes, - equals([ + orderedEquals([ 0x01, 0x02, 0x03, @@ -146,7 +114,7 @@ void main() { () { expect( Guid.fromString('0102').bytes, - equals([ + orderedEquals([ 0x01, 0x02, ]), @@ -159,7 +127,7 @@ void main() { () { expect( Guid.fromString('01020304').bytes, - equals([ + orderedEquals([ 0x01, 0x02, 0x03, @@ -174,7 +142,7 @@ void main() { () { expect( Guid.fromString('0102030400001000800000805f9b34fb').bytes, - equals([ + orderedEquals([ 0x01, 0x02, 0x03, @@ -201,7 +169,7 @@ void main() { () { expect( Guid.fromString('01020304-0000-1000-8000-00805f9b34fb').bytes, - equals([ + orderedEquals([ 0x01, 0x02, 0x03, @@ -318,49 +286,4 @@ void main() { ); }, ); - - group( - 'uuid', - () { - test( - 'returns the str property', - () { - expect( - Guid('0102').uuid, - equals('0102'), - ); - }, - ); - }, - ); - - group( - 'uuid128', - () { - test( - 'returns the str128 property', - () { - expect( - Guid('0102').uuid128, - equals('00000102-0000-1000-8000-00805f9b34fb'), - ); - }, - ); - }, - ); - - group( - 'toString', - () { - test( - 'returns the str property', - () { - expect( - Guid('0102').toString(), - equals('0102'), - ); - }, - ); - }, - ); } diff --git a/packages/flutter_blue_plus_platform_interface/test/options_test.dart b/packages/flutter_blue_plus_platform_interface/test/options_test.dart deleted file mode 100644 index 9a9e4ee5..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/options_test.dart +++ /dev/null @@ -1,104 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'Options', - () { - group( - 'fromMap', - () { - test( - 'deserializes the show power alert property', - () { - final showPowerAlert = false; - - expect( - Options.fromMap({ - 'show_power_alert': showPowerAlert, - }).showPowerAlert, - equals(showPowerAlert), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final showPowerAlert = false; - - expect( - Options( - showPowerAlert: showPowerAlert, - ).hashCode, - equals(showPowerAlert.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - Options( - showPowerAlert: false, - ) == - Options( - showPowerAlert: true, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - Options( - showPowerAlert: false, - ) == - Options( - showPowerAlert: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the show power alert property', - () { - final showPowerAlert = false; - - expect( - Options( - showPowerAlert: showPowerAlert, - ).toMap(), - containsPair( - 'show_power_alert', - equals(showPowerAlert), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart b/packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart deleted file mode 100644 index 97d72772..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/phy_support_test.dart +++ /dev/null @@ -1,145 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'PhySupport', - () { - group( - 'fromMap', - () { - test( - 'deserializes the le 2m property', - () { - final le2M = false; - - expect( - PhySupport.fromMap({ - 'le_2M': le2M, - 'le_coded': false, - }).le2M, - equals(le2M), - ); - }, - ); - - test( - 'deserializes the le coded property', - () { - final leCoded = false; - - expect( - PhySupport.fromMap({ - 'le_2M': false, - 'le_coded': leCoded, - }).leCoded, - equals(leCoded), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final le2M = false; - final leCoded = false; - - expect( - PhySupport( - le2M: le2M, - leCoded: leCoded, - ).hashCode, - equals(le2M.hashCode ^ leCoded.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - PhySupport( - le2M: false, - leCoded: false, - ) == - PhySupport( - le2M: true, - leCoded: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - PhySupport( - le2M: false, - leCoded: false, - ) == - PhySupport( - le2M: false, - leCoded: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the le 2m property', - () { - final le2M = false; - - expect( - PhySupport( - le2M: le2M, - leCoded: false, - ).toMap(), - containsPair( - 'le_2M', - equals(le2M), - ), - ); - }, - ); - - test( - 'serializes the le coded property', - () { - final leCoded = false; - - expect( - PhySupport( - le2M: false, - leCoded: leCoded, - ).toMap(), - containsPair( - 'le_coded', - equals(leCoded), - ), - ); - }, - ); - }, - ); - }, - ); -} From e2beefffc1d40b9c928915a0cbd8c0c0b50a8485 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:42 +0100 Subject: [PATCH 52/90] Revert "test: update descriptor models" This reverts commit 8b3b3690523d61a3a49c7a78d531830742bcb2c3. --- .../models/bm_bluetooth_descriptor.dart | 14 - .../descriptor/models/bm_descriptor_data.dart | 20 - .../models/bm_read_descriptor_request.dart | 15 - .../models/bm_write_descriptor_request.dart | 17 - .../test/bm_bluetooth_descriptor_test.dart | 244 ---------- .../test/bm_descriptor_data_test.dart | 457 ++---------------- .../test/bm_read_descriptor_request_test.dart | 274 +---------- .../bm_write_descriptor_request_test.dart | 331 +------------ 8 files changed, 56 insertions(+), 1316 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart index 3c0ae230..344124b5 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart @@ -25,20 +25,6 @@ class BmBluetoothDescriptor { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothDescriptor && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart index a3d1045c..7eb0a236 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -47,25 +46,6 @@ class BmDescriptorData { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmDescriptorData && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart index 5cb4de6f..b6ec526e 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart @@ -30,21 +30,6 @@ class BmReadDescriptorRequest { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmReadDescriptorRequest && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart index 050cfeb5..b5449818 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -36,22 +35,6 @@ class BmWriteDescriptorRequest { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmWriteDescriptorRequest && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart deleted file mode 100644 index a94a835c..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_descriptor_test.dart +++ /dev/null @@ -1,244 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBluetoothDescriptor', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmBluetoothDescriptor.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptor_uuid': '0102', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptor uuid property', - () { - final descriptorUuid = '0102'; - - expect( - BmBluetoothDescriptor.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': descriptorUuid, - }).descriptorUuid, - equals(Guid(descriptorUuid)), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmBluetoothDescriptor.fromMap({ - 'remote_id': remoteId, - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmBluetoothDescriptor.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final characteristicUuid = Guid('0102'); - final descriptorUuid = Guid('0102'); - - expect( - BmBluetoothDescriptor( - remoteId: remoteId, - serviceUuid: serviceUuid, - characteristicUuid: characteristicUuid, - descriptorUuid: descriptorUuid, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str1'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ) == - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str2'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ) == - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the descriptor uuid property', - () { - final descriptorUuid = Guid('0102'); - - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: descriptorUuid, - ).toMap(), - containsPair( - 'descriptor_uuid', - equals(descriptorUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmBluetoothDescriptor( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart index f07a30eb..183f5a2f 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart @@ -1,96 +1,32 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { group( - 'BmDescriptorData', + 'BmCharacteristicData', () { group( 'fromMap', () { test( - 'deserializes the characteristic uuid property', + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', () { - final characteristicUuid = '0102'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptor uuid property', - () { - final descriptorUuid = '0102'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': descriptorUuid, - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).descriptorUuid, - equals(Guid(descriptorUuid)), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - expect( BmDescriptorData.fromMap({ - 'remote_id': remoteId, + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', 'success': 1, 'error_code': 0, 'error_string': '', - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), ); }, ); @@ -100,7 +36,7 @@ void main() { () { expect( BmDescriptorData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -115,34 +51,14 @@ void main() { }, ); - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmDescriptorData.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - test( 'deserializes the success property as false if it is 0', () { expect( BmDescriptorData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', @@ -160,8 +76,9 @@ void main() { () { expect( BmDescriptorData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', @@ -179,8 +96,9 @@ void main() { () { expect( BmDescriptorData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', @@ -196,20 +114,23 @@ void main() { test( 'deserializes the value property', () { - final value = '010203'; - expect( BmDescriptorData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - 'value': value, + 'value': '010203', 'success': 1, 'error_code': 0, 'error_string': '', }).value, - equals(hex.decode(value)), + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), ); }, ); @@ -219,8 +140,9 @@ void main() { () { expect( BmDescriptorData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': null, @@ -228,332 +150,7 @@ void main() { 'error_code': 0, 'error_string': '', }).value, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final descriptorUuid = Guid('0102'); - final value = []; - final success = true; - final errorCode = 0; - final errorString = ''; - - expect( - BmDescriptorData( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - descriptorUuid: descriptorUuid, - value: value, - success: success, - errorCode: errorCode, - errorString: errorString, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: false, - errorCode: 0, - errorString: '', - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the descriptor uuid property', - () { - final descriptorUuid = Guid('0102'); - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: descriptorUuid, - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'descriptor_uuid', - equals(descriptorUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmDescriptorData( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: false, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the value property', - () { - final value = [0x01, 0x02, 0x03]; - - expect( - BmDescriptorData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: value, - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'value', - hex.encode(value), - ), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart index 2a1d1479..1d600b87 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart @@ -9,53 +9,20 @@ void main() { 'fromMap', () { test( - 'deserializes the characteristic uuid property', + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', () { - final characteristicUuid = '0102'; - expect( BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptor_uuid': '0102', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptor uuid property', - () { - final descriptorUuid = '0102'; - - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': descriptorUuid, - }).descriptorUuid, - equals(Guid(descriptorUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), ); }, ); @@ -65,7 +32,7 @@ void main() { () { expect( BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -75,229 +42,6 @@ void main() { ); }, ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final descriptorUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - descriptorUuid: descriptorUuid, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ) == - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ) == - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the characteristic uuid property', - () { - final descriptorUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: descriptorUuid, - ).toMap(), - containsPair( - 'descriptor_uuid', - equals(descriptorUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmReadDescriptorRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmReadDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); }, ); }, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart index 5ec1cf2c..d398ab6d 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -11,56 +9,21 @@ void main() { 'fromMap', () { test( - 'deserializes the characteristic uuid property', + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', () { - final characteristicUuid = '0102'; - expect( BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptor_uuid': '0102', - 'value': '', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptor uuid property', - () { - final descriptorUuid = '0102'; - - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': descriptorUuid, - 'value': '', - }).descriptorUuid, - equals(Guid(descriptorUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': '', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), ); }, ); @@ -70,7 +33,7 @@ void main() { () { expect( BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -82,38 +45,23 @@ void main() { }, ); - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - test( 'deserializes the value property', () { - final value = '010203'; - expect( BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - 'value': value, + 'value': '010203', }).value, - equals(hex.decode(value)), + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), ); }, ); @@ -123,253 +71,14 @@ void main() { () { expect( BmWriteDescriptorRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', 'value': null, }).value, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final descriptorUuid = Guid('0102'); - final value = []; - - expect( - BmWriteDescriptorRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - descriptorUuid: descriptorUuid, - value: value, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - descriptorUuid.hashCode ^ - const ListEquality().hash(value), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ) == - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ) == - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the characteristic uuid property', - () { - final descriptorUuid = Guid('0102'); - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: descriptorUuid, - value: [], - ).toMap(), - containsPair( - 'descriptor_uuid', - equals(descriptorUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmWriteDescriptorRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the value property', - () { - final value = [0x01, 0x02, 0x03]; - - expect( - BmWriteDescriptorRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: value, - ).toMap(), - containsPair( - 'value', - hex.encode(value), - ), + isEmpty, ); }, ); From d7a9e561bc4308630f961e31e04820f8b62e1ed6 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:43 +0100 Subject: [PATCH 53/90] Revert "test: update scan models" This reverts commit c22887cf2777f9c555d8a4a22d6a6561849b573c. --- .../lib/src/scan/models/bm_msd_filter.dart | 14 - .../scan/models/bm_scan_advertisement.dart | 21 - .../lib/src/scan/models/bm_scan_response.dart | 16 - .../lib/src/scan/models/bm_scan_settings.dart | 23 - .../scan/models/bm_service_data_filter.dart | 14 - .../test/bm_msd_filter_test.dart | 163 +----- .../test/bm_scan_advertisement_test.dart | 436 ++-------------- .../test/bm_scan_response_test.dart | 188 +------ .../test/bm_scan_settings_test.dart | 470 +----------------- .../test/bm_service_data_filter_test.dart | 168 +------ 10 files changed, 90 insertions(+), 1423 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart index 32135816..ecd77a4f 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; class BmMsdFilter { @@ -22,19 +21,6 @@ class BmMsdFilter { ); } - @override - int get hashCode { - return manufacturerId.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmMsdFilter && hashCode == other.hashCode; - } - Map toMap() { return { 'manufacturer_id': manufacturerId, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart index f4469fc6..5d0e3d89 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -53,26 +52,6 @@ class BmScanAdvertisement { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - platformName.hashCode ^ - advName.hashCode ^ - connectable.hashCode ^ - txPowerLevel.hashCode ^ - appearance.hashCode ^ - const MapEquality>().hash(manufacturerData) ^ - const MapEquality>().hash(serviceData) ^ - const ListEquality().hash(serviceUuids) ^ - rssi.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanAdvertisement && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart index b0d86543..c6053b1a 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; - import 'bm_scan_advertisement.dart'; class BmScanResponse { @@ -32,20 +30,6 @@ class BmScanResponse { ); } - @override - int get hashCode { - return const ListEquality().hash(advertisements) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanResponse && hashCode == other.hashCode; - } - Map toMap() { return { 'advertisements': diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart index ab1eb303..0f18f305 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; - import '../../common/models/guid.dart'; import 'bm_msd_filter.dart'; import 'bm_service_data_filter.dart'; @@ -60,27 +58,6 @@ class BmScanSettings { ); } - @override - int get hashCode { - return const ListEquality().hash(withServices) ^ - const ListEquality().hash(withRemoteIds) ^ - const ListEquality().hash(withNames) ^ - const ListEquality().hash(withKeywords) ^ - const ListEquality().hash(withMsd) ^ - const ListEquality().hash(withServiceData) ^ - continuousUpdates.hashCode ^ - continuousDivisor.hashCode ^ - androidLegacy.hashCode ^ - androidScanMode.hashCode ^ - androidUsesFineLocation.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmScanSettings && hashCode == other.hashCode; - } - Map toMap() { return { 'with_services': withServices.map((uuid) => uuid.str).toList(), diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart index 09e1af6e..4f3a9d60 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/guid.dart'; @@ -24,19 +23,6 @@ class BmServiceDataFilter { ); } - @override - int get hashCode { - return service.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmServiceDataFilter && hashCode == other.hashCode; - } - Map toMap() { return { 'service': service.str, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart index 6dad4753..de385abc 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -10,24 +8,6 @@ void main() { group( 'fromMap', () { - test( - 'deserializes the data property', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': '010203', - 'mask': null, - }).data, - equals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - test( 'deserializes the data property as null if it is null', () { @@ -43,15 +23,15 @@ void main() { ); test( - 'deserializes the mask property', + 'deserializes the data property', () { expect( BmMsdFilter.fromMap({ 'manufacturer_id': 0, - 'data': null, - 'mask': '010203', - }).mask, - equals([ + 'data': '010203', + 'mask': null, + }).data, + orderedEquals([ 0x01, 0x02, 0x03, @@ -73,132 +53,21 @@ void main() { ); }, ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final manufacturerId = 0; - final data = []; - final mask = []; - - expect( - BmMsdFilter( - manufacturerId, - data, - mask, - ).hashCode, - equals( - manufacturerId.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmMsdFilter(0, [], []) == BmMsdFilter(1, [], []), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmMsdFilter(0, [], []) == BmMsdFilter(0, [], []), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the data property', - () { - final data = [0x01, 0x02, 0x03]; - - expect( - BmMsdFilter( - 0, - data, - [], - ).toMap(), - containsPair( - 'data', - hex.encode(data), - ), - ); - }, - ); - - test( - 'serializes the data property as null if it is null', - () { - expect( - BmMsdFilter( - 0, - null, - [], - ).toMap(), - containsPair( - 'data', - isNull, - ), - ); - }, - ); test( - 'serializes the mask property', - () { - final mask = [0x01, 0x02, 0x03]; - - expect( - BmMsdFilter( - 0, - [], - mask, - ).toMap(), - containsPair( - 'mask', - hex.encode(mask), - ), - ); - }, - ); - - test( - 'serializes the mask property as null if it is null', + 'deserializes the mask property', () { expect( - BmMsdFilter( - 0, - [], - null, - ).toMap(), - containsPair( - 'mask', - isNull, - ), + BmMsdFilter.fromMap({ + 'manufacturer_id': 0, + 'data': null, + 'mask': '010203', + }).mask, + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart index 4606f5bd..2a55567b 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -10,62 +8,26 @@ void main() { group( 'fromMap', () { - test( - 'deserializes the connectable property as false if it is not 1', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 0, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': 0, - }).connectable, - isFalse, - ); - }, - ); - - test( - 'deserializes the connectable property as true if it is 1', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': 0, - }).connectable, - isTrue, - ); - }, - ); - test( 'deserializes the manufacturer data property', () { - final manufacturerData = { - 1: '010203', - }; - expect( BmScanAdvertisement.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connectable': 1, - 'manufacturer_data': manufacturerData, + 'manufacturer_data': { + 1: '010203', + }, 'service_data': {}, 'service_uuids': [], - 'rssi': 0, }).manufacturerData, - equals( - manufacturerData.map( - (key, value) { - return MapEntry(key, hex.decode(value)); - }, - ), + containsPair( + 1, + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), ), ); }, @@ -76,69 +38,13 @@ void main() { () { expect( BmScanAdvertisement.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connectable': 1, 'manufacturer_data': null, 'service_data': {}, 'service_uuids': [], - 'rssi': 0, }).manufacturerData, - equals({}), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': remoteId, - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': 0, - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the rssi property', - () { - final rssi = 0; - - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': rssi, - }).rssi, - equals(rssi), - ); - }, - ); - - test( - 'deserializes the rssi property as 0 if it is null', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - 'rssi': null, - }).rssi, - equals(0), + isEmpty, ); }, ); @@ -146,25 +52,23 @@ void main() { test( 'deserializes the service data property', () { - final serviceData = { - '0102': '010203', - }; - expect( BmScanAdvertisement.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connectable': 1, 'manufacturer_data': {}, - 'service_data': serviceData, + 'service_data': { + '0102': '010203', + }, 'service_uuids': [], - 'rssi': 0, }).serviceData, - equals( - serviceData.map( - (key, value) { - return MapEntry(Guid(key), hex.decode(value)); - }, - ), + containsPair( + Guid('0102'), + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), ), ); }, @@ -175,14 +79,13 @@ void main() { () { expect( BmScanAdvertisement.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connectable': 1, 'manufacturer_data': {}, 'service_data': null, 'service_uuids': [], - 'rssi': 0, }).serviceData, - equals({}), + isEmpty, ); }, ); @@ -190,26 +93,19 @@ void main() { test( 'deserializes the service uuids property', () { - final serviceUuids = [ - '0102', - ]; - expect( BmScanAdvertisement.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connectable': 1, 'manufacturer_data': {}, 'service_data': {}, - 'service_uuids': serviceUuids, - 'rssi': 0, + 'service_uuids': [ + '0102', + ], }).serviceUuids, - equals( - serviceUuids.map( - (serviceUuid) { - return Guid(serviceUuid); - }, - ), - ), + orderedEquals([ + Guid('0102'), + ]), ); }, ); @@ -219,275 +115,13 @@ void main() { () { expect( BmScanAdvertisement.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'connectable': 1, 'manufacturer_data': {}, 'service_data': {}, 'service_uuids': null, - 'rssi': 0, }).serviceUuids, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final platformName = null; - final advName = null; - final connectable = true; - final txPowerLevel = 0; - final appearance = 0; - final manufacturerData = >{}; - final serviceData = >{}; - final serviceUuids = []; - final rssi = 0; - - expect( - BmScanAdvertisement( - remoteId: remoteId, - platformName: platformName, - advName: advName, - connectable: connectable, - txPowerLevel: txPowerLevel, - appearance: appearance, - manufacturerData: manufacturerData, - serviceData: serviceData, - serviceUuids: serviceUuids, - rssi: rssi, - ).hashCode, - equals( - remoteId.hashCode ^ - platformName.hashCode ^ - advName.hashCode ^ - connectable.hashCode ^ - txPowerLevel.hashCode ^ - appearance.hashCode ^ - const MapEquality>() - .hash(manufacturerData) ^ - const MapEquality>().hash(serviceData) ^ - const ListEquality().hash(serviceUuids) ^ - rssi.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ) == - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: false, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ) == - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the connectable property as 0 if it is false', - () { - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: false, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'connectable', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the connectable property as 1 if it is true', - () { - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'connectable', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the manufacturer data property', - () { - final manufacturerData = { - 0: [0x01, 0x02, 0x03], - }; - - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: manufacturerData, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'manufacturer_data', - equals( - manufacturerData.map( - (key, value) { - return MapEntry(key, hex.encode(value)); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmScanAdvertisement( - remoteId: remoteId, - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the service data property', - () { - final serviceData = { - Guid('0102'): [0x01, 0x02, 0x03], - }; - - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: serviceData, - serviceUuids: [], - rssi: 0, - ).toMap(), - containsPair( - 'service_data', - equals( - serviceData.map( - (key, value) { - return MapEntry(key.str, hex.encode(value)); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the service uuids property', - () { - final serviceUuids = [ - Guid('0102'), - ]; - - expect( - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: serviceUuids, - rssi: 0, - ).toMap(), - containsPair( - 'service_uuids', - equals( - serviceUuids.map( - (serviceUuid) { - return serviceUuid.str; - }, - ), - ), - ), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart index c3890127..8636986b 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,37 +8,6 @@ void main() { group( 'fromMap', () { - test( - 'deserializes the advertisements property', - () { - final advertisements = [ - { - 'remote_id': 'str', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [], - } - ]; - - expect( - BmScanResponse.fromMap({ - 'advertisements': advertisements, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).advertisements, - equals( - advertisements.map( - (advertisement) { - return BmScanAdvertisement.fromMap(advertisement); - }, - ), - ), - ); - }, - ); - test( 'deserializes the advertisements property as [] if it is null', () { @@ -50,7 +18,7 @@ void main() { 'error_code': 0, 'error_string': '', }).advertisements, - equals([]), + isEmpty, ); }, ); @@ -101,160 +69,6 @@ void main() { ); }, ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final advertisements = []; - final success = true; - final errorCode = 0; - final errorString = ''; - - expect( - BmScanResponse( - advertisements: advertisements, - success: success, - errorCode: errorCode, - errorString: errorString, - ).hashCode, - equals( - const ListEquality() - .hash(advertisements) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmScanResponse( - advertisements: [], - success: false, - errorCode: 0, - errorString: '', - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the services property', - () { - final advertisements = [ - BmScanAdvertisement( - remoteId: DeviceIdentifier('str'), - connectable: true, - manufacturerData: {}, - serviceData: {}, - serviceUuids: [], - rssi: 0, - ), - ]; - - expect( - BmScanResponse( - advertisements: advertisements, - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'advertisements', - equals( - advertisements.map( - (advertisement) { - return advertisement.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmScanResponse( - advertisements: [], - success: false, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(1), - ), - ); - }, - ); - }, - ); }, ); } diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart index 3132a207..fbbd6085 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -10,124 +9,36 @@ void main() { 'fromMap', () { test( - 'deserializes the with keywords property', - () { - final withKeywords = [ - 'keyword', - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': withKeywords, - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withKeywords, - equals(withKeywords), - ); - }, - ); - - test( - 'deserializes the with keywords property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': null, - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withKeywords, - equals([]), - ); - }, - ); - - test( - 'deserializes the with msd property', + 'deserializes the with services property as [] if it is null', () { - final withMsd = [ - { - 'manufacturer_id': 0, - 'data': '', - 'mask': '', - }, - ]; - expect( BmScanSettings.fromMap({ - 'with_services': [], + 'with_services': null, 'with_remote_ids': [], 'with_names': [], 'with_keywords': [], - 'with_msd': withMsd, + 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, - }).withMsd, - equals( - withMsd.map( - (manufacturerData) { - return BmMsdFilter.fromMap(manufacturerData); - }, - ), - ), + }).withServices, + isEmpty, ); }, ); test( - 'deserializes the with msd property as [] if it is null', + 'deserializes the with remote ids property as [] if it is null', () { expect( BmScanSettings.fromMap({ 'with_services': [], - 'with_remote_ids': [], + 'with_remote_ids': null, 'with_names': [], 'with_keywords': [], - 'with_msd': null, - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withMsd, - equals([]), - ); - }, - ); - - test( - 'deserializes the with names property', - () { - final withNames = [ - 'name', - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': withNames, - 'with_keywords': [], 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, @@ -135,8 +46,8 @@ void main() { 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, - }).withNames, - equals(withNames), + }).withRemoteIds, + isEmpty, ); }, ); @@ -158,46 +69,20 @@ void main() { 'android_scan_mode': 0, 'android_uses_fine_location': false, }).withNames, - equals([]), - ); - }, - ); - - test( - 'deserializes the with remote ids property', - () { - final withRemoteIds = [ - 'str', - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': withRemoteIds, - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withRemoteIds, - equals(withRemoteIds), + isEmpty, ); }, ); test( - 'deserializes the with remote ids property as [] if it is null', + 'deserializes the with keywords property as [] if it is null', () { expect( BmScanSettings.fromMap({ 'with_services': [], - 'with_remote_ids': null, + 'with_remote_ids': [], 'with_names': [], - 'with_keywords': [], + 'with_keywords': null, 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, @@ -205,44 +90,30 @@ void main() { 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, - }).withRemoteIds, - equals([]), + }).withKeywords, + isEmpty, ); }, ); test( - 'deserializes the with service data property', + 'deserializes the with msd property as [] if it is null', () { - final withServiceData = [ - { - 'service': '0102', - 'data': '010203', - 'mask': '010203', - }, - ]; - expect( BmScanSettings.fromMap({ 'with_services': [], 'with_remote_ids': [], 'with_names': [], 'with_keywords': [], - 'with_msd': [], - 'with_service_data': withServiceData, + 'with_msd': null, + 'with_service_data': [], 'continuous_updates': false, 'continuous_divisor': 1, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, - }).withServiceData, - equals( - withServiceData.map( - (serviceData) { - return BmServiceDataFilter.fromMap(serviceData); - }, - ), - ), + }).withMsd, + isEmpty, ); }, ); @@ -264,306 +135,7 @@ void main() { 'android_scan_mode': 0, 'android_uses_fine_location': false, }).withServiceData, - equals([]), - ); - }, - ); - - test( - 'deserializes the with services property', - () { - final withServices = [ - '0102', - ]; - - expect( - BmScanSettings.fromMap({ - 'with_services': withServices, - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withServices, - equals( - withServices.map( - (service) { - return Guid(service); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the with services property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': null, - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 1, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withServices, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final withServices = []; - final withRemoteIds = []; - final withNames = []; - final withKeywords = []; - final withMsd = []; - final withServiceData = []; - final continuousUpdates = false; - final continuousDivisor = 1; - final androidLegacy = false; - final androidScanMode = 0; - final androidUsesFineLocation = false; - - expect( - BmScanSettings( - withServices: withServices, - withRemoteIds: withRemoteIds, - withNames: withNames, - withKeywords: withKeywords, - withMsd: withMsd, - withServiceData: withServiceData, - continuousUpdates: continuousUpdates, - continuousDivisor: continuousDivisor, - androidLegacy: androidLegacy, - androidScanMode: androidScanMode, - androidUsesFineLocation: androidUsesFineLocation, - ).hashCode, - equals( - const ListEquality().hash(withServices) ^ - const ListEquality().hash(withRemoteIds) ^ - const ListEquality().hash(withNames) ^ - const ListEquality().hash(withKeywords) ^ - const ListEquality().hash(withMsd) ^ - const ListEquality() - .hash(withServiceData) ^ - continuousUpdates.hashCode ^ - continuousDivisor.hashCode ^ - androidLegacy.hashCode ^ - androidScanMode.hashCode ^ - androidUsesFineLocation.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ) == - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: true, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ) == - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the with msd property', - () { - final withMsd = [ - BmMsdFilter( - 0, - [], - [], - ), - ]; - - expect( - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: withMsd, - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ).toMap(), - containsPair( - 'with_msd', - equals( - withMsd.map( - (manufacturerData) { - return manufacturerData.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the with service data property', - () { - final withServiceData = [ - BmServiceDataFilter( - Guid('0102'), - [], - [], - ), - ]; - - expect( - BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: withServiceData, - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ).toMap(), - containsPair( - 'with_service_data', - equals( - withServiceData.map( - (serviceData) { - return serviceData.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the with services property', - () { - final withServices = [ - Guid('0102'), - ]; - - expect( - BmScanSettings( - withServices: withServices, - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ).toMap(), - containsPair( - 'with_services', - equals( - withServices.map( - (service) { - return service.str; - }, - ), - ), - ), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart index fedcb704..1eac1ef9 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -10,24 +8,6 @@ void main() { group( 'fromMap', () { - test( - 'deserializes the data property', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': '010203', - 'mask': '010203', - }).data, - equals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - test( 'deserializes the data property as [] if it is null', () { @@ -35,23 +15,23 @@ void main() { BmServiceDataFilter.fromMap({ 'service': '0102', 'data': null, - 'mask': '010203', + 'mask': null, }).data, - equals([]), + isEmpty, ); }, ); test( - 'deserializes the mask property', + 'deserializes the data property', () { expect( BmServiceDataFilter.fromMap({ 'service': '0102', 'data': '010203', - 'mask': '010203', - }).mask, - equals([ + 'mask': null, + }).data, + orderedEquals([ 0x01, 0x02, 0x03, @@ -66,142 +46,28 @@ void main() { expect( BmServiceDataFilter.fromMap({ 'service': '0102', - 'data': '010203', + 'data': null, 'mask': null, }).mask, - equals([]), + isEmpty, ); }, ); test( - 'deserializes the service property', + 'deserializes the mask property', () { - final service = '0102'; - expect( BmServiceDataFilter.fromMap({ - 'service': service, - 'data': '010203', + 'service': '0102', + 'data': null, 'mask': '010203', - }).service, - equals(Guid(service)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final service = Guid('0102'); - final data = []; - final mask = []; - - expect( - BmServiceDataFilter( - service, - data, - mask, - ).hashCode, - equals( - service.hashCode ^ - const ListEquality().hash(data) ^ - const ListEquality().hash(mask), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmServiceDataFilter(Guid('0102'), [], []) == - BmServiceDataFilter(Guid('0304'), [], []), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmServiceDataFilter(Guid('0102'), [], []) == - BmServiceDataFilter(Guid('0102'), [], []), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the data property', - () { - final data = [0x01, 0x02, 0x03]; - - expect( - BmServiceDataFilter( - Guid('0102'), - data, - [], - ).toMap(), - containsPair( - 'data', - hex.encode(data), - ), - ); - }, - ); - - test( - 'serializes the mask property', - () { - final mask = [0x01, 0x02, 0x03]; - - expect( - BmServiceDataFilter( - Guid('0102'), - [], - mask, - ).toMap(), - containsPair( - 'mask', - hex.encode(mask), - ), - ); - }, - ); - - test( - 'serializes the characteristic uuid property', - () { - final service = Guid('0102'); - - expect( - BmServiceDataFilter( - service, - [], - [], - ).toMap(), - containsPair( - 'service', - equals(service.str), - ), + }).mask, + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), ); }, ); From 602c5529800635d514f68f1be7b7c0bc82417fbc Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:43 +0100 Subject: [PATCH 54/90] Revert "test: update service models" This reverts commit f2fd3c3030d4990687cbf2012fea71edfbbdc090. --- .../service/models/bm_bluetooth_service.dart | 19 +- .../models/bm_discover_services_result.dart | 17 - .../test/bm_bluetooth_service_test.dart | 394 +----------------- .../bm_discover_services_result_test.dart | 244 +---------- 4 files changed, 10 insertions(+), 664 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart index 97551b18..29aa7214 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; - import '../../characteristic/models/bm_bluetooth_characteristic.dart'; import '../../common/models/device_identifier.dart'; import '../../common/models/guid.dart'; @@ -12,8 +10,8 @@ class BmBluetoothService { List includedServices; BmBluetoothService({ - required this.remoteId, required this.serviceUuid, + required this.remoteId, required this.isPrimary, required this.characteristics, required this.includedServices, @@ -39,21 +37,6 @@ class BmBluetoothService { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - isPrimary.hashCode ^ - const ListEquality().hash(characteristics) ^ - const ListEquality().hash(includedServices); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothService && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart index 689c1eed..5979e00c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; - import '../../common/models/device_identifier.dart'; import 'bm_bluetooth_service.dart'; @@ -36,21 +34,6 @@ class BmDiscoverServicesResult { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - const ListEquality().hash(services) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmDiscoverServicesResult && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart index 7a3f4bef..6f1da7da 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,83 +8,18 @@ void main() { group( 'fromMap', () { - test( - 'deserializes the characteristics property', - () { - final characteristics = [ - { - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'descriptors': [], - 'properties': {}, - }, - ]; - - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': characteristics, - 'included_services': [], - }).characteristics, - equals( - characteristics.map( - (characteristic) { - return BmBluetoothCharacteristic.fromMap(characteristic); - }, - ), - ), - ); - }, - ); - test( 'deserializes the characteristics property as [] if it is null', () { expect( BmBluetoothService.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'is_primary': 1, 'characteristics': null, 'included_services': [], }).characteristics, - equals([]), - ); - }, - ); - - test( - 'deserializes the included services property', - () { - final includedServices = [ - { - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': [], - }, - ]; - - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': includedServices, - }).includedServices, - equals( - includedServices.map( - (includedService) { - return BmBluetoothService.fromMap(includedService); - }, - ), - ), + isEmpty, ); }, ); @@ -95,333 +29,13 @@ void main() { () { expect( BmBluetoothService.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'is_primary': 1, 'characteristics': [], 'included_services': null, }).includedServices, - equals([]), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmBluetoothService.fromMap({ - 'remote_id': remoteId, - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': null, - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'is_primary': 1, - 'characteristics': [], - 'included_services': null, - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - - test( - 'deserializes the is primary property as false if it is not 1', - () { - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 0, - 'characteristics': [], - 'included_services': null, - }).isPrimary, - isFalse, - ); - }, - ); - - test( - 'deserializes the is primary property as true if it is 1', - () { - expect( - BmBluetoothService.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': null, - }).isPrimary, - isTrue, - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final isPrimary = true; - final characteristics = []; - final includedServices = []; - - expect( - BmBluetoothService( - remoteId: remoteId, - serviceUuid: serviceUuid, - isPrimary: isPrimary, - characteristics: characteristics, - includedServices: includedServices, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - isPrimary.hashCode ^ - const ListEquality() - .hash(characteristics) ^ - const ListEquality() - .hash(includedServices), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ) == - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: false, - characteristics: [], - includedServices: [], - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ) == - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristics property', - () { - final characteristics = [ - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - ]; - - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: characteristics, - includedServices: [], - ).toMap(), - containsPair( - 'characteristics', - equals( - characteristics.map( - (characteristic) { - return characteristic.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the included services property', - () { - final includedServices = [ - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ), - ]; - - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: includedServices, - ).toMap(), - containsPair( - 'included_services', - equals( - includedServices.map( - (includedService) { - return includedService.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the is primary property as 0 if it is false', - () { - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: false, - characteristics: [], - includedServices: [], - ).toMap(), - containsPair( - 'is_primary', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the is primary property as 1 if it is true', - () { - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ).toMap(), - containsPair( - 'is_primary', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmBluetoothService( - remoteId: remoteId, - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - isPrimary: true, - characteristics: [], - includedServices: [], - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart index 42d7d8f3..7cf5894f 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,68 +8,18 @@ void main() { group( 'fromMap', () { - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': remoteId, - 'services': [], - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the services property', - () { - final services = [ - { - 'remote_id': 'str', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': [], - } - ]; - - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', - 'services': services, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).services, - equals( - services.map( - (service) { - return BmBluetoothService.fromMap(service); - }, - ), - ), - ); - }, - ); - test( 'deserializes the services property as [] if it is null', () { expect( BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'services': null, 'success': 1, 'error_code': 0, 'error_string': '', }).services, - equals([]), + isEmpty, ); }, ); @@ -80,7 +29,7 @@ void main() { () { expect( BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'services': [], 'success': 0, 'error_code': 0, @@ -96,7 +45,7 @@ void main() { () { expect( BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'services': [], 'success': null, 'error_code': 0, @@ -112,7 +61,7 @@ void main() { () { expect( BmDiscoverServicesResult.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'services': [], 'success': 1, 'error_code': 0, @@ -124,189 +73,6 @@ void main() { ); }, ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final services = []; - final success = true; - final errorCode = 0; - final errorString = ''; - - expect( - BmDiscoverServicesResult( - remoteId: remoteId, - services: services, - success: success, - errorCode: errorCode, - errorString: errorString, - ).hashCode, - equals( - remoteId.hashCode ^ - const ListEquality().hash(services) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: false, - errorCode: 0, - errorString: '', - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmDiscoverServicesResult( - remoteId: remoteId, - services: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the services property', - () { - final services = [ - BmBluetoothService( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - isPrimary: true, - characteristics: [], - includedServices: [], - ), - ]; - - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: services, - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'services', - equals( - services.map( - (service) { - return service.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: false, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmDiscoverServicesResult( - remoteId: DeviceIdentifier('str'), - services: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(1), - ), - ); - }, - ); - }, - ); }, ); } From b0568a0ed7a36f70e7bbb412b96c1b50551bd285 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:43 +0100 Subject: [PATCH 55/90] Revert "test: update characteristic models" This reverts commit 07663694c248cdeac5463414c990036db07a025a. --- .../models/bm_bluetooth_characteristic.dart | 18 - .../models/bm_characteristic_data.dart | 19 - .../models/bm_characteristic_properties.dart | 20 - .../bm_read_characteristic_request.dart | 14 - .../models/bm_set_notify_value_request.dart | 16 - .../bm_write_characteristic_request.dart | 18 - .../pubspec.yaml | 1 - .../bm_bluetooth_characteristic_test.dart | 545 +----------------- .../test/bm_characteristic_data_test.dart | 392 +------------ .../bm_characteristic_properties_test.dart | 359 ++++-------- .../bm_read_characteristic_request_test.dart | 223 +------ .../bm_write_characteristic_request_test.dart | 385 +------------ 12 files changed, 205 insertions(+), 1805 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart index a59ed0e9..1fec7092 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; - import '../../common/models/device_identifier.dart'; import '../../common/models/guid.dart'; import '../../descriptor/models/bm_bluetooth_descriptor.dart'; @@ -53,22 +51,6 @@ class BmBluetoothCharacteristic { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality().hash(descriptors) ^ - properties.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothCharacteristic && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart index df3698d4..3e2a97e4 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -44,24 +43,6 @@ class BmCharacteristicData { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmCharacteristicData && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart index 30745221..0204ab0f 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart @@ -40,26 +40,6 @@ class BmCharacteristicProperties { ); } - @override - int get hashCode { - return broadcast.hashCode ^ - read.hashCode ^ - writeWithoutResponse.hashCode ^ - write.hashCode ^ - notify.hashCode ^ - indicate.hashCode ^ - authenticatedSignedWrites.hashCode ^ - extendedProperties.hashCode ^ - notifyEncryptionRequired.hashCode ^ - indicateEncryptionRequired.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmCharacteristicProperties && hashCode == other.hashCode; - } - Map toMap() { return { 'broadcast': broadcast ? 1 : 0, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart index aae99675..3638432a 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart @@ -27,20 +27,6 @@ class BmReadCharacteristicRequest { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmReadCharacteristicRequest && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart index 4208f91c..6bc2315e 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart @@ -33,22 +33,6 @@ class BmSetNotifyValueRequest { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - forceIndications.hashCode ^ - enable.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmSetNotifyValueRequest && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart index 95504041..e516eb13 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import '../../common/models/device_identifier.dart'; @@ -40,23 +39,6 @@ class BmWriteCharacteristicRequest { ); } - @override - int get hashCode { - return remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - writeType.hashCode ^ - allowLongWrite.hashCode ^ - const ListEquality().hash(value); - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmWriteCharacteristicRequest && hashCode == other.hashCode; - } - Map toMap() { return { 'remote_id': remoteId.str, diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index ad5970e4..b524581a 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -8,7 +8,6 @@ environment: flutter: ">=2.0.0" dependencies: - collection: ^1.15.0 convert: ^3.0.0 flutter: sdk: flutter diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart index 79197271..3092b3b8 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,133 +8,44 @@ void main() { group( 'fromMap', () { - test( - 'deserializes the characteristic uuid property', - () { - final characteristicUuid = '0102'; - - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'descriptors': [], - 'properties': {}, - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the descriptors property', - () { - final descriptors = [ - { - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }, - ]; - - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptors': descriptors, - 'properties': {}, - }).descriptors, - equals( - descriptors.map( - (descriptor) { - return BmBluetoothDescriptor.fromMap(descriptor); - }, - ), - ), - ); - }, - ); - - test( - 'deserializes the descriptors property as [] if it is null', - () { - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptors': null, - 'properties': {}, - }).descriptors, - equals([]), - ); - }, - ); - test( 'deserializes the properties property properties as false if it is null', () { - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptors': [], - 'properties': null, - }).properties, - equals( - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; + final properties = BmBluetoothCharacteristic.fromMap({ + 'remote_id': '', + 'service_uuid': '0102', + 'characteristic_uuid': '0102', + 'properties': null, + }).properties; - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': remoteId, - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptors': [], - 'properties': {}, - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); + expect(properties.broadcast, isFalse); + expect(properties.read, isFalse); + expect(properties.writeWithoutResponse, isFalse); + expect(properties.write, isFalse); + expect(properties.notify, isFalse); + expect(properties.indicate, isFalse); + expect(properties.authenticatedSignedWrites, isFalse); + expect(properties.extendedProperties, isFalse); + expect(properties.notifyEncryptionRequired, isFalse); + expect(properties.indicateEncryptionRequired, isFalse); }, ); test( - 'deserializes the secondary service uuid property', + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', () { - final secondaryServiceUuid = '0102'; - expect( BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', - 'descriptors': [], 'properties': {}, - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), ); }, ); @@ -145,421 +55,16 @@ void main() { () { expect( BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', - 'descriptors': [], 'properties': {}, }).secondaryServiceUuid, isNull, ); }, ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'descriptors': [], - 'properties': {}, - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final descriptors = []; - final properties = BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ); - - expect( - BmBluetoothCharacteristic( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - descriptors: descriptors, - properties: properties, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality() - .hash(descriptors) ^ - properties.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ) == - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ) == - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the descriptors property', - () { - final descriptors = [ - BmBluetoothDescriptor( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ), - ]; - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: descriptors, - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'descriptors', - equals( - descriptors.map( - (descriptor) { - return descriptor.toMap(); - }, - ), - ), - ), - ); - }, - ); - - test( - 'serializes the properties property', - () { - final properties = BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ); - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: properties, - ).toMap(), - containsPair( - 'properties', - equals(properties.toMap()), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmBluetoothCharacteristic( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmBluetoothCharacteristic( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - descriptors: [], - properties: BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); }, ); }, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart index 57f793d5..eadc64fe 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -11,62 +9,23 @@ void main() { 'fromMap', () { test( - 'deserializes the characteristic uuid property', + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', () { - final characteristicUuid = '0102'; - expect( BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the remote id property', - () { - final remoteId = 'str'; - - expect( - BmCharacteristicData.fromMap({ - 'remote_id': remoteId, + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'value': '', 'success': 1, 'error_code': 0, 'error_string': '', - }).remoteId, - equals(DeviceIdentifier(remoteId)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, - 'characteristic_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), ); }, ); @@ -76,7 +35,7 @@ void main() { () { expect( BmCharacteristicData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -90,33 +49,14 @@ void main() { }, ); - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmCharacteristicData.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'value': '', - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - test( 'deserializes the success property as false if it is 0', () { expect( BmCharacteristicData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': '', 'success': 0, @@ -133,8 +73,9 @@ void main() { () { expect( BmCharacteristicData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': '', 'success': null, @@ -151,8 +92,9 @@ void main() { () { expect( BmCharacteristicData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': '', 'success': 1, @@ -167,19 +109,22 @@ void main() { test( 'deserializes the value property', () { - final value = '010203'; - expect( BmCharacteristicData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', - 'value': value, + 'value': '010203', 'success': 1, 'error_code': 0, 'error_string': '', }).value, - equals(hex.decode(value)), + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), ); }, ); @@ -189,301 +134,16 @@ void main() { () { expect( BmCharacteristicData.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': null, 'success': 1, 'error_code': 0, 'error_string': '', }).value, - equals([]), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final value = []; - final success = true; - final errorCode = 0; - final errorString = ''; - - expect( - BmCharacteristicData( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - value: value, - success: success, - errorCode: errorCode, - errorString: errorString, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - const ListEquality().hash(value) ^ - success.hashCode ^ - errorCode.hashCode ^ - errorString.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: false, - errorCode: 0, - errorString: '', - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ) == - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmCharacteristicData( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: false, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'success', - equals(1), - ), - ); - }, - ); - - test( - 'serializes the value property', - () { - final value = [0x01, 0x02, 0x03]; - - expect( - BmCharacteristicData( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: value, - success: true, - errorCode: 0, - errorString: '', - ).toMap(), - containsPair( - 'value', - hex.encode(value), - ), + isEmpty, ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart index 75301ba1..4ede2c27 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart @@ -11,185 +11,116 @@ void main() { test( 'deserializes the properties as false if they are not 1', () { + final properties = BmCharacteristicProperties.fromMap({ + 'broadcast': 0, + 'read': 0, + 'write_without_response': 0, + 'write': 0, + 'notify': 0, + 'indicate': 0, + 'authenticated_signed_writes': 0, + 'extended_properties': 0, + 'notify_encryption_required': 0, + 'indicate_encryption_required': 0, + }); + expect( - BmCharacteristicProperties.fromMap({ - 'broadcast': 0, - 'read': 0, - 'write_without_response': 0, - 'write': 0, - 'notify': 0, - 'indicate': 0, - 'authenticated_signed_writes': 0, - 'extended_properties': 0, - 'notify_encryption_required': 0, - 'indicate_encryption_required': 0, - }), - equals( - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ), + properties.broadcast, + isFalse, ); - }, - ); - - test( - 'deserializes the properties as true if they are 1', - () { expect( - BmCharacteristicProperties.fromMap({ - 'broadcast': 1, - 'read': 1, - 'write_without_response': 1, - 'write': 1, - 'notify': 1, - 'indicate': 1, - 'authenticated_signed_writes': 1, - 'extended_properties': 1, - 'notify_encryption_required': 1, - 'indicate_encryption_required': 1, - }), - equals( - BmCharacteristicProperties( - broadcast: true, - read: true, - writeWithoutResponse: true, - write: true, - notify: true, - indicate: true, - authenticatedSignedWrites: true, - extendedProperties: true, - notifyEncryptionRequired: true, - indicateEncryptionRequired: true, - ), - ), + properties.read, + isFalse, ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final broadcast = false; - final read = false; - final writeWithoutResponse = false; - final write = false; - final notify = false; - final indicate = false; - final authenticatedSignedWrites = false; - final extendedProperties = false; - final notifyEncryptionRequired = false; - final indicateEncryptionRequired = false; - expect( - BmCharacteristicProperties( - broadcast: broadcast, - read: read, - writeWithoutResponse: writeWithoutResponse, - write: write, - notify: notify, - indicate: indicate, - authenticatedSignedWrites: authenticatedSignedWrites, - extendedProperties: extendedProperties, - notifyEncryptionRequired: notifyEncryptionRequired, - indicateEncryptionRequired: indicateEncryptionRequired, - ).hashCode, - equals( - broadcast.hashCode ^ - read.hashCode ^ - writeWithoutResponse.hashCode ^ - write.hashCode ^ - notify.hashCode ^ - indicate.hashCode ^ - authenticatedSignedWrites.hashCode ^ - extendedProperties.hashCode ^ - notifyEncryptionRequired.hashCode ^ - indicateEncryptionRequired.hashCode, - ), + properties.writeWithoutResponse, + isFalse, + ); + expect( + properties.write, + isFalse, + ); + expect( + properties.notify, + isFalse, + ); + expect( + properties.indicate, + isFalse, ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { expect( - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ) == - BmCharacteristicProperties( - broadcast: true, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), + properties.authenticatedSignedWrites, + isFalse, + ); + expect( + properties.extendedProperties, + isFalse, + ); + expect( + properties.notifyEncryptionRequired, + isFalse, + ); + expect( + properties.indicateEncryptionRequired, isFalse, ); }, ); test( - 'returns true if they are equal', + 'deserializes the properties as true if they are 1', () { + final properties = BmCharacteristicProperties.fromMap({ + 'broadcast': 1, + 'read': 1, + 'write_without_response': 1, + 'write': 1, + 'notify': 1, + 'indicate': 1, + 'authenticated_signed_writes': 1, + 'extended_properties': 1, + 'notify_encryption_required': 1, + 'indicate_encryption_required': 1, + }); + + expect( + properties.broadcast, + isTrue, + ); + expect( + properties.read, + isTrue, + ); + expect( + properties.writeWithoutResponse, + isTrue, + ); + expect( + properties.write, + isTrue, + ); + expect( + properties.notify, + isTrue, + ); + expect( + properties.indicate, + isTrue, + ); + expect( + properties.authenticatedSignedWrites, + isTrue, + ); + expect( + properties.extendedProperties, + isTrue, + ); + expect( + properties.notifyEncryptionRequired, + isTrue, + ); expect( - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ) == - BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), + properties.indicateEncryptionRequired, isTrue, ); }, @@ -218,73 +149,43 @@ void main() { expect( map, - containsPair( - 'broadcast', - equals(0), - ), + containsPair('broadcast', equals(0)), ); expect( map, - containsPair( - 'read', - equals(0), - ), + containsPair('read', equals(0)), ); expect( map, - containsPair( - 'write_without_response', - equals(0), - ), + containsPair('write_without_response', equals(0)), ); expect( map, - containsPair( - 'write', - equals(0), - ), + containsPair('write', equals(0)), ); expect( map, - containsPair( - 'notify', - equals(0), - ), + containsPair('notify', equals(0)), ); expect( map, - containsPair( - 'indicate', - equals(0), - ), + containsPair('indicate', equals(0)), ); expect( map, - containsPair( - 'authenticated_signed_writes', - equals(0), - ), + containsPair('authenticated_signed_writes', equals(0)), ); expect( map, - containsPair( - 'extended_properties', - equals(0), - ), + containsPair('extended_properties', equals(0)), ); expect( map, - containsPair( - 'notify_encryption_required', - equals(0), - ), + containsPair('notify_encryption_required', equals(0)), ); expect( map, - containsPair( - 'indicate_encryption_required', - equals(0), - ), + containsPair('indicate_encryption_required', equals(0)), ); }, ); @@ -307,73 +208,43 @@ void main() { expect( map, - containsPair( - 'broadcast', - equals(1), - ), + containsPair('broadcast', equals(1)), ); expect( map, - containsPair( - 'read', - equals(1), - ), + containsPair('read', equals(1)), ); expect( map, - containsPair( - 'write_without_response', - equals(1), - ), + containsPair('write_without_response', equals(1)), ); expect( map, - containsPair( - 'write', - equals(1), - ), + containsPair('write', equals(1)), ); expect( map, - containsPair( - 'notify', - equals(1), - ), + containsPair('notify', equals(1)), ); expect( map, - containsPair( - 'indicate', - equals(1), - ), + containsPair('indicate', equals(1)), ); expect( map, - containsPair( - 'authenticated_signed_writes', - equals(1), - ), + containsPair('authenticated_signed_writes', equals(1)), ); expect( map, - containsPair( - 'extended_properties', - equals(1), - ), + containsPair('extended_properties', equals(1)), ); expect( map, - containsPair( - 'notify_encryption_required', - equals(1), - ), + containsPair('notify_encryption_required', equals(1)), ); expect( map, - containsPair( - 'indicate_encryption_required', - equals(1), - ), + containsPair('indicate_encryption_required', equals(1)), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart index 415d4a59..f3f06fb6 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart @@ -9,34 +9,19 @@ void main() { 'fromMap', () { test( - 'deserializes the characteristic uuid property', + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', () { - final characteristicUuid = '0102'; - - expect( - BmReadCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - expect( BmReadCharacteristicRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), ); }, ); @@ -46,7 +31,7 @@ void main() { () { expect( BmReadCharacteristicRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', @@ -55,196 +40,6 @@ void main() { ); }, ); - - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmReadCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - }, - ); - - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - - expect( - BmReadCharacteristicRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode, - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ) == - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ) == - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ), - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmReadCharacteristicRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmReadCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); }, ); }, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart index c81239b2..417274e2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart @@ -1,5 +1,3 @@ -import 'package:collection/collection.dart'; -import 'package:convert/convert.dart'; import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -11,40 +9,21 @@ void main() { 'fromMap', () { test( - 'deserializes the characteristic uuid property', + 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', () { - final characteristicUuid = '0102'; - - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': characteristicUuid, - 'write_type': 0, - 'allow_long_write': 0, - 'value': '', - }).characteristicUuid, - equals(Guid(characteristicUuid)), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property', - () { - final secondaryServiceUuid = '0102'; - expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', - 'secondary_service_uuid': secondaryServiceUuid, + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'write_type': 0, - 'allow_long_write': 0, 'value': '', - }).secondaryServiceUuid, - equals(Guid(secondaryServiceUuid)), + }).secondaryServiceUuid?.bytes, + orderedEquals([ + 0x01, + 0x02, + ]), ); }, ); @@ -54,12 +33,11 @@ void main() { () { expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'write_type': 0, - 'allow_long_write': 0, 'value': '', }).secondaryServiceUuid, isNull, @@ -67,74 +45,23 @@ void main() { }, ); - test( - 'deserializes the service uuid property', - () { - final serviceUuid = '0102'; - - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': serviceUuid, - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 0, - 'value': '', - }).serviceUuid, - equals(Guid(serviceUuid)), - ); - }, - ); - - test( - 'deserializes the allow long write property as false if it is 0', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 0, - 'value': '', - }).allowLongWrite, - isFalse, - ); - }, - ); - - test( - 'deserializes the allow long write property as true if it is not 0', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 0, - 'allow_long_write': 1, - 'value': '', - }).allowLongWrite, - isTrue, - ); - }, - ); - test( 'deserializes the value property', () { - final value = '010203'; - expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'write_type': 0, - 'allow_long_write': 0, - 'value': value, + 'value': '010203', }).value, - equals(hex.decode(value)), + orderedEquals([ + 0x01, + 0x02, + 0x03, + ]), ); }, ); @@ -144,11 +71,11 @@ void main() { () { expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'write_type': 0, - 'allow_long_write': 0, 'value': null, }).value, isEmpty, @@ -159,18 +86,16 @@ void main() { test( 'deserializes the write type property', () { - final writeType = BmWriteType.withResponse; - expect( BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', - 'write_type': writeType.index, - 'allow_long_write': 0, - 'value': '', + 'write_type': 0, + 'value': null, }).writeType, - equals(writeType), + equals(BmWriteType.withResponse), ); }, ); @@ -181,12 +106,12 @@ void main() { expect( () { BmWriteCharacteristicRequest.fromMap({ - 'remote_id': 'str', + 'remote_id': '', 'service_uuid': '0102', + 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'write_type': 2, - 'allow_long_write': 0, - 'value': '', + 'value': null, }); }, throwsRangeError, @@ -196,272 +121,22 @@ void main() { }, ); - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final remoteId = DeviceIdentifier('str'); - final serviceUuid = Guid('0102'); - final secondaryServiceUuid = null; - final characteristicUuid = Guid('0102'); - final writeType = BmWriteType.withResponse; - final allowLongWrite = false; - final value = []; - - expect( - BmWriteCharacteristicRequest( - remoteId: remoteId, - serviceUuid: serviceUuid, - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: characteristicUuid, - writeType: writeType, - allowLongWrite: allowLongWrite, - value: value, - ).hashCode, - equals( - remoteId.hashCode ^ - serviceUuid.hashCode ^ - secondaryServiceUuid.hashCode ^ - characteristicUuid.hashCode ^ - writeType.hashCode ^ - allowLongWrite.hashCode ^ - const ListEquality().hash(value), - ), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ) == - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ) == - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ), - isTrue, - ); - }, - ); - }, - ); - group( 'toMap', () { - test( - 'serializes the characteristic uuid property', - () { - final characteristicUuid = Guid('0102'); - - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: characteristicUuid, - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'characteristic_uuid', - equals(characteristicUuid.str), - ), - ); - }, - ); - - test( - 'serializes the remote id property', - () { - final remoteId = DeviceIdentifier('str'); - - expect( - BmWriteCharacteristicRequest( - remoteId: remoteId, - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'remote_id', - equals(remoteId.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property', - () { - final secondaryServiceUuid = Guid('0102'); - - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: secondaryServiceUuid, - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'secondary_service_uuid', - equals(secondaryServiceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the secondary service uuid property as null if it is null', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - secondaryServiceUuid: null, - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'secondary_service_uuid', - isNull, - ), - ); - }, - ); - - test( - 'serializes the service uuid property', - () { - final serviceUuid = Guid('0102'); - - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: serviceUuid, - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'service_uuid', - equals(serviceUuid.str), - ), - ); - }, - ); - - test( - 'serializes the success property as 0 if it is false', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair( - 'allow_long_write', - equals(0), - ), - ); - }, - ); - - test( - 'serializes the success property as 1 if it is true', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: true, - value: [], - ).toMap(), - containsPair( - 'allow_long_write', - equals(1), - ), - ); - }, - ); - test( 'serializes the write type property', () { - final writeType = BmWriteType.withResponse; - expect( BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier('str'), + remoteId: DeviceIdentifier(''), serviceUuid: Guid('0102'), characteristicUuid: Guid('0102'), - writeType: writeType, + writeType: BmWriteType.withResponse, allowLongWrite: false, value: [], ).toMap(), - containsPair( - 'write_type', - equals(writeType.index), - ), + containsPair('write_type', 0), ); }, ); From db7aeb0cdca2bd3a1c41b3ea3bcde77f8ed37d67 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:43 +0100 Subject: [PATCH 56/90] Revert "test: update adapter models" This reverts commit 7dc7355bef9a80daf13c88f2009f9f4fb19cafdc. --- .../models/bm_bluetooth_adapter_state.dart | 11 --- .../adapter/models/bm_turn_on_response.dart | 11 --- .../test/bm_bluetooth_adapter_state_test.dart | 69 +-------------- .../test/bm_turn_on_response_test.dart | 84 ++----------------- 4 files changed, 9 insertions(+), 166 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart index 949178f3..699b2a2d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart @@ -15,17 +15,6 @@ class BmBluetoothAdapterState { ); } - @override - int get hashCode { - return adapterState.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmBluetoothAdapterState && hashCode == other.hashCode; - } - Map toMap() { return { 'adapter_state': adapterState.index, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart index 8719a1b6..524d25b6 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart @@ -13,17 +13,6 @@ class BmTurnOnResponse { ); } - @override - int get hashCode { - return userAccepted.hashCode; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - other is BmTurnOnResponse && hashCode == other.hashCode; - } - Map toMap() { return { 'user_accepted': userAccepted, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart index 4bc542ec..eeca9a52 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart @@ -11,13 +11,11 @@ void main() { test( 'deserializes the adapter state property', () { - final adapterState = BmAdapterStateEnum.unknown; - expect( BmBluetoothAdapterState.fromMap({ - 'adapter_state': adapterState.index, + 'adapter_state': 0, }).adapterState, - equals(adapterState), + equals(BmAdapterStateEnum.unknown), ); }, ); @@ -38,76 +36,17 @@ void main() { }, ); - group( - 'hashCode', - () { - test( - 'returns the hash code', - () { - final adapterState = BmAdapterStateEnum.unknown; - - expect( - BmBluetoothAdapterState( - adapterState: adapterState, - ).hashCode, - equals(adapterState.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ) == - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unavailable, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ) == - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ), - isTrue, - ); - }, - ); - }, - ); - group( 'toMap', () { test( 'serializes the adapter state property', () { - final adapterState = BmAdapterStateEnum.unknown; - expect( BmBluetoothAdapterState( - adapterState: adapterState, + adapterState: BmAdapterStateEnum.unknown, ).toMap(), - containsPair( - 'adapter_state', - equals(adapterState.index), - ), + containsPair('adapter_state', 0), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart index 61fb826f..1a7065bb 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart @@ -9,19 +9,7 @@ void main() { 'fromMap', () { test( - 'deserializes the user accepted property', - () { - expect( - BmTurnOnResponse.fromMap({ - 'user_accepted': true, - }).userAccepted, - isTrue, - ); - }, - ); - - test( - 'deserializes the user accepted property as false if it is null', + 'deserializes the user accepted property as false if the user accepted property is null', () { expect( BmTurnOnResponse.fromMap({ @@ -31,82 +19,20 @@ void main() { ); }, ); - }, - ); - group( - 'hashCode', - () { test( - 'returns the hash code', + 'deserializes the user accepted property as true if the user accepted property is true', () { - final userAccepted = true; - expect( - BmTurnOnResponse( - userAccepted: userAccepted, - ).hashCode, - equals(userAccepted.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if they are not equal', - () { - expect( - BmTurnOnResponse( - userAccepted: true, - ) == - BmTurnOnResponse( - userAccepted: false, - ), - isFalse, - ); - }, - ); - - test( - 'returns true if they are equal', - () { - expect( - BmTurnOnResponse( - userAccepted: true, - ) == - BmTurnOnResponse( - userAccepted: true, - ), + BmTurnOnResponse.fromMap({ + 'user_accepted': true, + }).userAccepted, isTrue, ); }, ); }, ); - - group( - 'toMap', - () { - test( - 'serializes the user accepted property', - () { - expect( - BmTurnOnResponse( - userAccepted: true, - ).toMap(), - containsPair( - 'user_accepted', - isTrue, - ), - ); - }, - ); - }, - ); }, ); } From d8ea6d2f2ce65ba703824aec4cd2fb3c22f26a93 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:44 +0100 Subject: [PATCH 57/90] Revert "refactor: align example gradle files with flutter changes" This reverts commit 23ee3ee98e33b830d972e7f495c4ff7f92c9d023. --- .../example/android/app/build.gradle | 64 ++++++++++++------- .../example/android/build.gradle | 15 ++++- .../example/android/settings.gradle | 30 +++------ 3 files changed, 62 insertions(+), 47 deletions(-) diff --git a/packages/flutter_blue_plus/example/android/app/build.gradle b/packages/flutter_blue_plus/example/android/app/build.gradle index cb0f88ff..7484f6d8 100644 --- a/packages/flutter_blue_plus/example/android/app/build.gradle +++ b/packages/flutter_blue_plus/example/android/app/build.gradle @@ -1,44 +1,62 @@ -plugins { - id "com.android.application" - id "kotlin-android" - // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. - id "dev.flutter.flutter-gradle-plugin" +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' } +apply plugin: 'com.android.application' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + android { - namespace = "com.lib.flutter_blue_plus_example" - compileSdk = flutter.compileSdkVersion - ndkVersion = flutter.ndkVersion + compileSdkVersion 33 compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { - applicationId = "com.lib.flutter_blue_plus_example" - minSdk = flutter.minSdkVersion - targetSdk = flutter.targetSdkVersion - versionCode = flutter.versionCode - versionName = flutter.versionName + applicationId "com.lib.flutter_blue_plus_example" + minSdkVersion 21 + targetSdkVersion 33 + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig = signingConfigs.debug + signingConfig signingConfigs.debug // FIXME: Work-around for https://github.com/pauldemarco/flutter_blue/issues/772 - shrinkResources = false - minifyEnabled = false + shrinkResources false + minifyEnabled false } } + + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'com.lib.flutter_blue_plus_example' + } } flutter { - source = "../.." + source '../..' } diff --git a/packages/flutter_blue_plus/example/android/build.gradle b/packages/flutter_blue_plus/example/android/build.gradle index d2ffbffa..22cf3b71 100644 --- a/packages/flutter_blue_plus/example/android/build.gradle +++ b/packages/flutter_blue_plus/example/android/build.gradle @@ -1,3 +1,14 @@ +buildscript { + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:8.0.2' + } +} + allprojects { repositories { google() @@ -5,12 +16,12 @@ allprojects { } } -rootProject.buildDir = "../build" +rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { - project.evaluationDependsOn(":app") + project.evaluationDependsOn(':app') } tasks.register("clean", Delete) { diff --git a/packages/flutter_blue_plus/example/android/settings.gradle b/packages/flutter_blue_plus/example/android/settings.gradle index 536165d3..44e62bcf 100644 --- a/packages/flutter_blue_plus/example/android/settings.gradle +++ b/packages/flutter_blue_plus/example/android/settings.gradle @@ -1,25 +1,11 @@ -pluginManagement { - def flutterSdkPath = { - def properties = new Properties() - file("local.properties").withInputStream { properties.load(it) } - def flutterSdkPath = properties.getProperty("flutter.sdk") - assert flutterSdkPath != null, "flutter.sdk not set in local.properties" - return flutterSdkPath - }() +include ':app' - includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() - repositories { - google() - mavenCentral() - gradlePluginPortal() - } -} +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } -plugins { - id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "7.3.0" apply false - id "org.jetbrains.kotlin.android" version "1.7.10" apply false -} - -include ":app" +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" From 15c19fb6c62d6909bd172b15a746645d69c03e80 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:44 +0100 Subject: [PATCH 58/90] Revert "fix: method channel on detached from engine stream" This reverts commit b067cd97c74cd4e6e99364a2ab10e1c611910a4d. --- .../lib/src/method_channel_flutter_blue_plus.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index 3814e1d2..42c1dc71 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -110,8 +110,6 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Stream get onDetachedFromEngine { return _calls.stream.where((call) { return call.method == 'OnDetachedFromEngine'; - }).map((_) { - return null; }); } From 7b2672028950557f1e28f81b7c5dde2c4c1f9287 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:44 +0100 Subject: [PATCH 59/90] Revert "fix: remove erroneous android package directives" This reverts commit 3b034b55c894ae9e4fdd4743cc1210a5e386392c. --- packages/flutter_blue_plus_android/android/build.gradle | 2 ++ packages/flutter_blue_plus_android/android/settings.gradle | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/flutter_blue_plus_android/android/build.gradle b/packages/flutter_blue_plus_android/android/build.gradle index 2c6f5f39..04f31190 100644 --- a/packages/flutter_blue_plus_android/android/build.gradle +++ b/packages/flutter_blue_plus_android/android/build.gradle @@ -1,3 +1,5 @@ +package packages.flutter_blue_plus_android.android + group 'com.lib.flutter_blue_plus' version '1.0' diff --git a/packages/flutter_blue_plus_android/android/settings.gradle b/packages/flutter_blue_plus_android/android/settings.gradle index 943eabda..902780c0 100644 --- a/packages/flutter_blue_plus_android/android/settings.gradle +++ b/packages/flutter_blue_plus_android/android/settings.gradle @@ -1 +1,3 @@ +package packages.flutter_blue_plus_android.android + rootProject.name = 'flutter_blue_plus' From fe9f717fffafa0d1e78f9b951c15e166ab57df02 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:45 +0100 Subject: [PATCH 60/90] Revert "refactor: migrate core package" This reverts commit a585953b47ab1b49d8d884fbc56c6f033a4cd630. --- .../CHANGELOG.md => CHANGELOG.md | 2 - .../example => example}/.gitignore | 0 .../example => example}/.metadata | 0 .../example => example}/.vscode/settings.json | 0 .../example => example}/README.md | 0 .../example => example}/analysis_options.yaml | 0 .../example => example}/android/.gitignore | 0 .../android/app/build.gradle | 0 .../android/app/src/debug/AndroidManifest.xml | 0 .../android/app/src/main/AndroidManifest.xml | 0 .../MainActivity.java | 0 .../res/drawable-v21/launch_background.xml | 0 .../main/res/drawable/launch_background.xml | 0 .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin .../app/src/main/res/values-night/styles.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../app/src/profile/AndroidManifest.xml | 0 .../example => example}/android/build.gradle | 0 .../android/gradle.properties | 0 .../gradle/wrapper/gradle-wrapper.properties | 0 .../android/settings.gradle | 0 .../example => example}/ios/.gitignore | 0 .../ios/Flutter/AppFrameworkInfo.plist | 0 .../ios/Flutter/Debug.xcconfig | 0 .../ios/Flutter/Release.xcconfig | 0 .../example => example}/ios/Podfile | 0 .../ios/Runner.xcodeproj/project.pbxproj | 0 .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/WorkspaceSettings.xcsettings | 0 .../xcshareddata/xcschemes/Runner.xcscheme | 0 .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/WorkspaceSettings.xcsettings | 0 .../ios/Runner/AppDelegate.swift | 0 .../AppIcon.appiconset/Contents.json | 0 .../Icon-App-1024x1024@1x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@1x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@2x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@3x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@1x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@2x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@3x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@1x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@2x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@3x.png | Bin .../AppIcon.appiconset/Icon-App-60x60@2x.png | Bin .../AppIcon.appiconset/Icon-App-60x60@3x.png | Bin .../AppIcon.appiconset/Icon-App-76x76@1x.png | Bin .../AppIcon.appiconset/Icon-App-76x76@2x.png | Bin .../Icon-App-83.5x83.5@2x.png | Bin .../LaunchImage.imageset/Contents.json | 0 .../LaunchImage.imageset/LaunchImage.png | Bin .../LaunchImage.imageset/LaunchImage@2x.png | Bin .../LaunchImage.imageset/LaunchImage@3x.png | Bin .../LaunchImage.imageset/README.md | 0 .../Runner/Base.lproj/LaunchScreen.storyboard | 0 .../ios/Runner/Base.lproj/Main.storyboard | 0 .../example => example}/ios/Runner/Info.plist | 0 .../ios/Runner/Runner-Bridging-Header.h | 0 .../example => example}/lib/main.dart | 0 .../lib/screens/bluetooth_off_screen.dart | 0 .../lib/screens/device_screen.dart | 0 .../lib/screens/scan_screen.dart | 0 .../example => example}/lib/utils/extra.dart | 0 .../lib/utils/snackbar.dart | 0 .../example => example}/lib/utils/utils.dart | 0 .../lib/widgets/characteristic_tile.dart | 0 .../lib/widgets/descriptor_tile.dart | 0 .../lib/widgets/scan_result_tile.dart | 0 .../lib/widgets/service_tile.dart | 0 .../lib/widgets/system_device_tile.dart | 0 .../example => example}/macos/.gitignore | 0 .../macos/Flutter/Flutter-Debug.xcconfig | 0 .../macos/Flutter/Flutter-Release.xcconfig | 0 .../Flutter/GeneratedPluginRegistrant.swift | 2 +- .../example => example}/macos/Podfile | 0 example/macos/Podfile.lock | 22 + .../macos/Runner.xcodeproj/project.pbxproj | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/xcschemes/Runner.xcscheme | 0 .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../macos/Runner/AppDelegate.swift | 0 .../AppIcon.appiconset/Contents.json | 0 .../AppIcon.appiconset/app_icon_1024.png | Bin .../AppIcon.appiconset/app_icon_128.png | Bin .../AppIcon.appiconset/app_icon_16.png | Bin .../AppIcon.appiconset/app_icon_256.png | Bin .../AppIcon.appiconset/app_icon_32.png | Bin .../AppIcon.appiconset/app_icon_512.png | Bin .../AppIcon.appiconset/app_icon_64.png | Bin .../macos/Runner/Base.lproj/MainMenu.xib | 0 .../macos/Runner/Configs/AppInfo.xcconfig | 0 .../macos/Runner/Configs/Debug.xcconfig | 0 .../macos/Runner/Configs/Release.xcconfig | 0 .../macos/Runner/Configs/Warnings.xcconfig | 0 .../macos/Runner/DebugProfile.entitlements | 0 .../macos/Runner/Info.plist | 0 .../macos/Runner/MainFlutterWindow.swift | 0 .../macos/Runner/Release.entitlements | 0 .../macos/RunnerTests/RunnerTests.swift | 0 example/pubspec.yaml | 21 + .../lib => lib}/flutter_blue_plus.dart | 8 +- .../src/bluetooth_characteristic.dart | 35 +- .../lib => lib}/src/bluetooth_descriptor.dart | 26 +- .../lib => lib}/src/bluetooth_device.dart | 83 +- .../lib => lib}/src/bluetooth_events.dart | 60 +- lib/src/bluetooth_msgs.dart | 861 +++++++++++++ .../lib => lib}/src/bluetooth_service.dart | 2 +- .../lib => lib}/src/bluetooth_utils.dart | 4 - .../lib => lib}/src/flutter_blue_plus.dart | 233 ++-- lib/src/guid.dart | 92 ++ .../lib => lib}/src/utils.dart | 77 +- packages/flutter_blue_plus/.gitignore | 29 - packages/flutter_blue_plus/.metadata | 10 - packages/flutter_blue_plus/LICENSE | 28 - packages/flutter_blue_plus/README.md | 1142 ----------------- .../flutter_blue_plus/analysis_options.yaml | 1 - .../flutter_blue_plus/example/pubspec.lock | 107 -- .../flutter_blue_plus/example/pubspec.yaml | 29 - packages/flutter_blue_plus/pubspec.yaml | 38 - .../FlutterBluePlusPlugin.java | 4 +- 127 files changed, 1362 insertions(+), 1554 deletions(-) rename packages/flutter_blue_plus/CHANGELOG.md => CHANGELOG.md (99%) rename {packages/flutter_blue_plus/example => example}/.gitignore (100%) rename {packages/flutter_blue_plus/example => example}/.metadata (100%) rename {packages/flutter_blue_plus/example => example}/.vscode/settings.json (100%) rename {packages/flutter_blue_plus/example => example}/README.md (100%) rename {packages/flutter_blue_plus/example => example}/analysis_options.yaml (100%) rename {packages/flutter_blue_plus/example => example}/android/.gitignore (100%) rename {packages/flutter_blue_plus/example => example}/android/app/build.gradle (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/debug/AndroidManifest.xml (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/AndroidManifest.xml (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/drawable-v21/launch_background.xml (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/drawable/launch_background.xml (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/mipmap-hdpi/ic_launcher.png (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/mipmap-mdpi/ic_launcher.png (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/values-night/styles.xml (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/main/res/values/styles.xml (100%) rename {packages/flutter_blue_plus/example => example}/android/app/src/profile/AndroidManifest.xml (100%) rename {packages/flutter_blue_plus/example => example}/android/build.gradle (100%) rename {packages/flutter_blue_plus/example => example}/android/gradle.properties (100%) rename {packages/flutter_blue_plus/example => example}/android/gradle/wrapper/gradle-wrapper.properties (100%) rename {packages/flutter_blue_plus/example => example}/android/settings.gradle (100%) rename {packages/flutter_blue_plus/example => example}/ios/.gitignore (100%) rename {packages/flutter_blue_plus/example => example}/ios/Flutter/AppFrameworkInfo.plist (100%) rename {packages/flutter_blue_plus/example => example}/ios/Flutter/Debug.xcconfig (100%) rename {packages/flutter_blue_plus/example => example}/ios/Flutter/Release.xcconfig (100%) rename {packages/flutter_blue_plus/example => example}/ios/Podfile (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner.xcodeproj/project.pbxproj (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner.xcworkspace/contents.xcworkspacedata (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/AppDelegate.swift (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Base.lproj/LaunchScreen.storyboard (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Base.lproj/Main.storyboard (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Info.plist (100%) rename {packages/flutter_blue_plus/example => example}/ios/Runner/Runner-Bridging-Header.h (100%) rename {packages/flutter_blue_plus/example => example}/lib/main.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/screens/bluetooth_off_screen.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/screens/device_screen.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/screens/scan_screen.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/utils/extra.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/utils/snackbar.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/utils/utils.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/widgets/characteristic_tile.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/widgets/descriptor_tile.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/widgets/scan_result_tile.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/widgets/service_tile.dart (100%) rename {packages/flutter_blue_plus/example => example}/lib/widgets/system_device_tile.dart (100%) rename {packages/flutter_blue_plus/example => example}/macos/.gitignore (100%) rename {packages/flutter_blue_plus/example => example}/macos/Flutter/Flutter-Debug.xcconfig (100%) rename {packages/flutter_blue_plus/example => example}/macos/Flutter/Flutter-Release.xcconfig (100%) rename {packages/flutter_blue_plus/example => example}/macos/Flutter/GeneratedPluginRegistrant.swift (88%) rename {packages/flutter_blue_plus/example => example}/macos/Podfile (100%) create mode 100644 example/macos/Podfile.lock rename {packages/flutter_blue_plus/example => example}/macos/Runner.xcodeproj/project.pbxproj (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner.xcworkspace/contents.xcworkspacedata (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/AppDelegate.swift (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Base.lproj/MainMenu.xib (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Configs/AppInfo.xcconfig (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Configs/Debug.xcconfig (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Configs/Release.xcconfig (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Configs/Warnings.xcconfig (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/DebugProfile.entitlements (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Info.plist (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/MainFlutterWindow.swift (100%) rename {packages/flutter_blue_plus/example => example}/macos/Runner/Release.entitlements (100%) rename {packages/flutter_blue_plus/example => example}/macos/RunnerTests/RunnerTests.swift (100%) create mode 100644 example/pubspec.yaml rename {packages/flutter_blue_plus/lib => lib}/flutter_blue_plus.dart (63%) rename {packages/flutter_blue_plus/lib => lib}/src/bluetooth_characteristic.dart (89%) rename {packages/flutter_blue_plus/lib => lib}/src/bluetooth_descriptor.dart (83%) rename {packages/flutter_blue_plus/lib => lib}/src/bluetooth_device.dart (88%) rename {packages/flutter_blue_plus/lib => lib}/src/bluetooth_events.dart (76%) create mode 100644 lib/src/bluetooth_msgs.dart rename {packages/flutter_blue_plus/lib => lib}/src/bluetooth_service.dart (94%) rename {packages/flutter_blue_plus/lib => lib}/src/bluetooth_utils.dart (95%) rename {packages/flutter_blue_plus/lib => lib}/src/flutter_blue_plus.dart (82%) create mode 100644 lib/src/guid.dart rename {packages/flutter_blue_plus/lib => lib}/src/utils.dart (87%) delete mode 100644 packages/flutter_blue_plus/.gitignore delete mode 100644 packages/flutter_blue_plus/.metadata delete mode 100644 packages/flutter_blue_plus/LICENSE delete mode 100644 packages/flutter_blue_plus/README.md delete mode 100644 packages/flutter_blue_plus/analysis_options.yaml delete mode 100644 packages/flutter_blue_plus/example/pubspec.lock delete mode 100644 packages/flutter_blue_plus/example/pubspec.yaml delete mode 100644 packages/flutter_blue_plus/pubspec.yaml diff --git a/packages/flutter_blue_plus/CHANGELOG.md b/CHANGELOG.md similarity index 99% rename from packages/flutter_blue_plus/CHANGELOG.md rename to CHANGELOG.md index fb2d1a23..bccc790f 100644 --- a/packages/flutter_blue_plus/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,3 @@ -## 1.33.0 -* **[Improve]** move Android, iOS, macOS implementations to federated packages ## 1.32.12 * **[Fix]** Android: further improve `disconnect(queue:false)` reliability diff --git a/packages/flutter_blue_plus/example/.gitignore b/example/.gitignore similarity index 100% rename from packages/flutter_blue_plus/example/.gitignore rename to example/.gitignore diff --git a/packages/flutter_blue_plus/example/.metadata b/example/.metadata similarity index 100% rename from packages/flutter_blue_plus/example/.metadata rename to example/.metadata diff --git a/packages/flutter_blue_plus/example/.vscode/settings.json b/example/.vscode/settings.json similarity index 100% rename from packages/flutter_blue_plus/example/.vscode/settings.json rename to example/.vscode/settings.json diff --git a/packages/flutter_blue_plus/example/README.md b/example/README.md similarity index 100% rename from packages/flutter_blue_plus/example/README.md rename to example/README.md diff --git a/packages/flutter_blue_plus/example/analysis_options.yaml b/example/analysis_options.yaml similarity index 100% rename from packages/flutter_blue_plus/example/analysis_options.yaml rename to example/analysis_options.yaml diff --git a/packages/flutter_blue_plus/example/android/.gitignore b/example/android/.gitignore similarity index 100% rename from packages/flutter_blue_plus/example/android/.gitignore rename to example/android/.gitignore diff --git a/packages/flutter_blue_plus/example/android/app/build.gradle b/example/android/app/build.gradle similarity index 100% rename from packages/flutter_blue_plus/example/android/app/build.gradle rename to example/android/app/build.gradle diff --git a/packages/flutter_blue_plus/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/debug/AndroidManifest.xml rename to example/android/app/src/debug/AndroidManifest.xml diff --git a/packages/flutter_blue_plus/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/AndroidManifest.xml rename to example/android/app/src/main/AndroidManifest.xml diff --git a/packages/flutter_blue_plus/example/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java b/example/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java rename to example/android/app/src/main/java/com/boskokg/flutter_blue_plus_example/MainActivity.java diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/drawable-v21/launch_background.xml b/example/android/app/src/main/res/drawable-v21/launch_background.xml similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/drawable-v21/launch_background.xml rename to example/android/app/src/main/res/drawable-v21/launch_background.xml diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/drawable/launch_background.xml b/example/android/app/src/main/res/drawable/launch_background.xml similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/drawable/launch_background.xml rename to example/android/app/src/main/res/drawable/launch_background.xml diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/values-night/styles.xml rename to example/android/app/src/main/res/values-night/styles.xml diff --git a/packages/flutter_blue_plus/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/main/res/values/styles.xml rename to example/android/app/src/main/res/values/styles.xml diff --git a/packages/flutter_blue_plus/example/android/app/src/profile/AndroidManifest.xml b/example/android/app/src/profile/AndroidManifest.xml similarity index 100% rename from packages/flutter_blue_plus/example/android/app/src/profile/AndroidManifest.xml rename to example/android/app/src/profile/AndroidManifest.xml diff --git a/packages/flutter_blue_plus/example/android/build.gradle b/example/android/build.gradle similarity index 100% rename from packages/flutter_blue_plus/example/android/build.gradle rename to example/android/build.gradle diff --git a/packages/flutter_blue_plus/example/android/gradle.properties b/example/android/gradle.properties similarity index 100% rename from packages/flutter_blue_plus/example/android/gradle.properties rename to example/android/gradle.properties diff --git a/packages/flutter_blue_plus/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from packages/flutter_blue_plus/example/android/gradle/wrapper/gradle-wrapper.properties rename to example/android/gradle/wrapper/gradle-wrapper.properties diff --git a/packages/flutter_blue_plus/example/android/settings.gradle b/example/android/settings.gradle similarity index 100% rename from packages/flutter_blue_plus/example/android/settings.gradle rename to example/android/settings.gradle diff --git a/packages/flutter_blue_plus/example/ios/.gitignore b/example/ios/.gitignore similarity index 100% rename from packages/flutter_blue_plus/example/ios/.gitignore rename to example/ios/.gitignore diff --git a/packages/flutter_blue_plus/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist similarity index 100% rename from packages/flutter_blue_plus/example/ios/Flutter/AppFrameworkInfo.plist rename to example/ios/Flutter/AppFrameworkInfo.plist diff --git a/packages/flutter_blue_plus/example/ios/Flutter/Debug.xcconfig b/example/ios/Flutter/Debug.xcconfig similarity index 100% rename from packages/flutter_blue_plus/example/ios/Flutter/Debug.xcconfig rename to example/ios/Flutter/Debug.xcconfig diff --git a/packages/flutter_blue_plus/example/ios/Flutter/Release.xcconfig b/example/ios/Flutter/Release.xcconfig similarity index 100% rename from packages/flutter_blue_plus/example/ios/Flutter/Release.xcconfig rename to example/ios/Flutter/Release.xcconfig diff --git a/packages/flutter_blue_plus/example/ios/Podfile b/example/ios/Podfile similarity index 100% rename from packages/flutter_blue_plus/example/ios/Podfile rename to example/ios/Podfile diff --git a/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.pbxproj rename to example/ios/Runner.xcodeproj/project.pbxproj diff --git a/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/packages/flutter_blue_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/packages/flutter_blue_plus/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner.xcworkspace/contents.xcworkspacedata rename to example/ios/Runner.xcworkspace/contents.xcworkspacedata diff --git a/packages/flutter_blue_plus/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/flutter_blue_plus/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/packages/flutter_blue_plus/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/AppDelegate.swift rename to example/ios/Runner/AppDelegate.swift diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json rename to example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png rename to example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png rename to example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png rename to example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png diff --git a/packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md rename to example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md diff --git a/packages/flutter_blue_plus/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/example/ios/Runner/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Base.lproj/LaunchScreen.storyboard rename to example/ios/Runner/Base.lproj/LaunchScreen.storyboard diff --git a/packages/flutter_blue_plus/example/ios/Runner/Base.lproj/Main.storyboard b/example/ios/Runner/Base.lproj/Main.storyboard similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Base.lproj/Main.storyboard rename to example/ios/Runner/Base.lproj/Main.storyboard diff --git a/packages/flutter_blue_plus/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Info.plist rename to example/ios/Runner/Info.plist diff --git a/packages/flutter_blue_plus/example/ios/Runner/Runner-Bridging-Header.h b/example/ios/Runner/Runner-Bridging-Header.h similarity index 100% rename from packages/flutter_blue_plus/example/ios/Runner/Runner-Bridging-Header.h rename to example/ios/Runner/Runner-Bridging-Header.h diff --git a/packages/flutter_blue_plus/example/lib/main.dart b/example/lib/main.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/main.dart rename to example/lib/main.dart diff --git a/packages/flutter_blue_plus/example/lib/screens/bluetooth_off_screen.dart b/example/lib/screens/bluetooth_off_screen.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/screens/bluetooth_off_screen.dart rename to example/lib/screens/bluetooth_off_screen.dart diff --git a/packages/flutter_blue_plus/example/lib/screens/device_screen.dart b/example/lib/screens/device_screen.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/screens/device_screen.dart rename to example/lib/screens/device_screen.dart diff --git a/packages/flutter_blue_plus/example/lib/screens/scan_screen.dart b/example/lib/screens/scan_screen.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/screens/scan_screen.dart rename to example/lib/screens/scan_screen.dart diff --git a/packages/flutter_blue_plus/example/lib/utils/extra.dart b/example/lib/utils/extra.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/utils/extra.dart rename to example/lib/utils/extra.dart diff --git a/packages/flutter_blue_plus/example/lib/utils/snackbar.dart b/example/lib/utils/snackbar.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/utils/snackbar.dart rename to example/lib/utils/snackbar.dart diff --git a/packages/flutter_blue_plus/example/lib/utils/utils.dart b/example/lib/utils/utils.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/utils/utils.dart rename to example/lib/utils/utils.dart diff --git a/packages/flutter_blue_plus/example/lib/widgets/characteristic_tile.dart b/example/lib/widgets/characteristic_tile.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/widgets/characteristic_tile.dart rename to example/lib/widgets/characteristic_tile.dart diff --git a/packages/flutter_blue_plus/example/lib/widgets/descriptor_tile.dart b/example/lib/widgets/descriptor_tile.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/widgets/descriptor_tile.dart rename to example/lib/widgets/descriptor_tile.dart diff --git a/packages/flutter_blue_plus/example/lib/widgets/scan_result_tile.dart b/example/lib/widgets/scan_result_tile.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/widgets/scan_result_tile.dart rename to example/lib/widgets/scan_result_tile.dart diff --git a/packages/flutter_blue_plus/example/lib/widgets/service_tile.dart b/example/lib/widgets/service_tile.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/widgets/service_tile.dart rename to example/lib/widgets/service_tile.dart diff --git a/packages/flutter_blue_plus/example/lib/widgets/system_device_tile.dart b/example/lib/widgets/system_device_tile.dart similarity index 100% rename from packages/flutter_blue_plus/example/lib/widgets/system_device_tile.dart rename to example/lib/widgets/system_device_tile.dart diff --git a/packages/flutter_blue_plus/example/macos/.gitignore b/example/macos/.gitignore similarity index 100% rename from packages/flutter_blue_plus/example/macos/.gitignore rename to example/macos/.gitignore diff --git a/packages/flutter_blue_plus/example/macos/Flutter/Flutter-Debug.xcconfig b/example/macos/Flutter/Flutter-Debug.xcconfig similarity index 100% rename from packages/flutter_blue_plus/example/macos/Flutter/Flutter-Debug.xcconfig rename to example/macos/Flutter/Flutter-Debug.xcconfig diff --git a/packages/flutter_blue_plus/example/macos/Flutter/Flutter-Release.xcconfig b/example/macos/Flutter/Flutter-Release.xcconfig similarity index 100% rename from packages/flutter_blue_plus/example/macos/Flutter/Flutter-Release.xcconfig rename to example/macos/Flutter/Flutter-Release.xcconfig diff --git a/packages/flutter_blue_plus/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift similarity index 88% rename from packages/flutter_blue_plus/example/macos/Flutter/GeneratedPluginRegistrant.swift rename to example/macos/Flutter/GeneratedPluginRegistrant.swift index 75f01990..e56ee822 100644 --- a/packages/flutter_blue_plus/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,7 @@ import FlutterMacOS import Foundation -import flutter_blue_plus_darwin +import flutter_blue_plus func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FlutterBluePlusPlugin.register(with: registry.registrar(forPlugin: "FlutterBluePlusPlugin")) diff --git a/packages/flutter_blue_plus/example/macos/Podfile b/example/macos/Podfile similarity index 100% rename from packages/flutter_blue_plus/example/macos/Podfile rename to example/macos/Podfile diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock new file mode 100644 index 00000000..c6166877 --- /dev/null +++ b/example/macos/Podfile.lock @@ -0,0 +1,22 @@ +PODS: + - flutter_blue_plus (0.0.1): + - FlutterMacOS + - FlutterMacOS (1.0.0) + +DEPENDENCIES: + - flutter_blue_plus (from `Flutter/ephemeral/.symlinks/plugins/flutter_blue_plus/macos`) + - FlutterMacOS (from `Flutter/ephemeral`) + +EXTERNAL SOURCES: + flutter_blue_plus: + :path: Flutter/ephemeral/.symlinks/plugins/flutter_blue_plus/macos + FlutterMacOS: + :path: Flutter/ephemeral + +SPEC CHECKSUMS: + flutter_blue_plus: e2868679021f19d12a8c0c58a33f1df66ec7fa6a + FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 + +PODFILE CHECKSUM: b5ff078e9cf81bae88fdc8e0ce3668e57b68e9b6 + +COCOAPODS: 1.14.3 diff --git a/packages/flutter_blue_plus/example/macos/Runner.xcodeproj/project.pbxproj b/example/macos/Runner.xcodeproj/project.pbxproj similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner.xcodeproj/project.pbxproj rename to example/macos/Runner.xcodeproj/project.pbxproj diff --git a/packages/flutter_blue_plus/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/flutter_blue_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/packages/flutter_blue_plus/example/macos/Runner.xcworkspace/contents.xcworkspacedata b/example/macos/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner.xcworkspace/contents.xcworkspacedata rename to example/macos/Runner.xcworkspace/contents.xcworkspacedata diff --git a/packages/flutter_blue_plus/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/flutter_blue_plus/example/macos/Runner/AppDelegate.swift b/example/macos/Runner/AppDelegate.swift similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/AppDelegate.swift rename to example/macos/Runner/AppDelegate.swift diff --git a/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png rename to example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png diff --git a/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png rename to example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png diff --git a/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png rename to example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png diff --git a/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png rename to example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png diff --git a/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png rename to example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png diff --git a/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png rename to example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png diff --git a/packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png rename to example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png diff --git a/packages/flutter_blue_plus/example/macos/Runner/Base.lproj/MainMenu.xib b/example/macos/Runner/Base.lproj/MainMenu.xib similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Base.lproj/MainMenu.xib rename to example/macos/Runner/Base.lproj/MainMenu.xib diff --git a/packages/flutter_blue_plus/example/macos/Runner/Configs/AppInfo.xcconfig b/example/macos/Runner/Configs/AppInfo.xcconfig similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Configs/AppInfo.xcconfig rename to example/macos/Runner/Configs/AppInfo.xcconfig diff --git a/packages/flutter_blue_plus/example/macos/Runner/Configs/Debug.xcconfig b/example/macos/Runner/Configs/Debug.xcconfig similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Configs/Debug.xcconfig rename to example/macos/Runner/Configs/Debug.xcconfig diff --git a/packages/flutter_blue_plus/example/macos/Runner/Configs/Release.xcconfig b/example/macos/Runner/Configs/Release.xcconfig similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Configs/Release.xcconfig rename to example/macos/Runner/Configs/Release.xcconfig diff --git a/packages/flutter_blue_plus/example/macos/Runner/Configs/Warnings.xcconfig b/example/macos/Runner/Configs/Warnings.xcconfig similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Configs/Warnings.xcconfig rename to example/macos/Runner/Configs/Warnings.xcconfig diff --git a/packages/flutter_blue_plus/example/macos/Runner/DebugProfile.entitlements b/example/macos/Runner/DebugProfile.entitlements similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/DebugProfile.entitlements rename to example/macos/Runner/DebugProfile.entitlements diff --git a/packages/flutter_blue_plus/example/macos/Runner/Info.plist b/example/macos/Runner/Info.plist similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Info.plist rename to example/macos/Runner/Info.plist diff --git a/packages/flutter_blue_plus/example/macos/Runner/MainFlutterWindow.swift b/example/macos/Runner/MainFlutterWindow.swift similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/MainFlutterWindow.swift rename to example/macos/Runner/MainFlutterWindow.swift diff --git a/packages/flutter_blue_plus/example/macos/Runner/Release.entitlements b/example/macos/Runner/Release.entitlements similarity index 100% rename from packages/flutter_blue_plus/example/macos/Runner/Release.entitlements rename to example/macos/Runner/Release.entitlements diff --git a/packages/flutter_blue_plus/example/macos/RunnerTests/RunnerTests.swift b/example/macos/RunnerTests/RunnerTests.swift similarity index 100% rename from packages/flutter_blue_plus/example/macos/RunnerTests/RunnerTests.swift rename to example/macos/RunnerTests/RunnerTests.swift diff --git a/example/pubspec.yaml b/example/pubspec.yaml new file mode 100644 index 00000000..8794903a --- /dev/null +++ b/example/pubspec.yaml @@ -0,0 +1,21 @@ +name: flutter_blue_plus_example +description: Demonstrates how to use the flutter_blue_plus plugin. + +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' + +environment: + sdk: ">=2.15.1 <3.0.0" + +dependencies: + flutter: + sdk: flutter + + flutter_blue_plus: + # Note: We use a path dependency because the example app & plugin are bundled together. + # In *your* app you should use ^1.17.3 or similar + path: ../ + +flutter: + uses-material-design: true diff --git a/packages/flutter_blue_plus/lib/flutter_blue_plus.dart b/lib/flutter_blue_plus.dart similarity index 63% rename from packages/flutter_blue_plus/lib/flutter_blue_plus.dart rename to lib/flutter_blue_plus.dart index 06215d33..b174f6a2 100644 --- a/packages/flutter_blue_plus/lib/flutter_blue_plus.dart +++ b/lib/flutter_blue_plus.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -7,15 +7,15 @@ library flutter_blue_plus; import 'dart:async'; import 'dart:io'; -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; - -export 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; +import 'package:flutter/services.dart'; part 'src/bluetooth_characteristic.dart'; part 'src/bluetooth_descriptor.dart'; part 'src/bluetooth_device.dart'; +part 'src/bluetooth_msgs.dart'; part 'src/bluetooth_events.dart'; part 'src/bluetooth_service.dart'; part 'src/bluetooth_utils.dart'; part 'src/flutter_blue_plus.dart'; +part 'src/guid.dart'; part 'src/utils.dart'; diff --git a/packages/flutter_blue_plus/lib/src/bluetooth_characteristic.dart b/lib/src/bluetooth_characteristic.dart similarity index 89% rename from packages/flutter_blue_plus/lib/src/bluetooth_characteristic.dart rename to lib/src/bluetooth_characteristic.dart index 5f7fe266..0ef7610b 100644 --- a/packages/flutter_blue_plus/lib/src/bluetooth_characteristic.dart +++ b/lib/src/bluetooth_characteristic.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -56,7 +56,10 @@ class BluetoothCharacteristic { /// - anytime `write()` is called /// - anytime a notification arrives (if subscribed) /// - and when first listened to, it re-emits the last value for convenience - Stream> get lastValueStream => _mergeStreams([FlutterBluePlusPlatform.instance.onCharacteristicReceived, FlutterBluePlusPlatform.instance.onCharacteristicWritten]) + Stream> get lastValueStream => FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnCharacteristicReceived" || m.method == "OnCharacteristicWritten") + .map((m) => m.arguments) + .map((args) => BmCharacteristicData.fromMap(args)) .where((p) => p.remoteId == remoteId) .where((p) => p.serviceUuid == serviceUuid) .where((p) => p.characteristicUuid == characteristicUuid) @@ -67,7 +70,10 @@ class BluetoothCharacteristic { /// this stream emits values: /// - anytime `read()` is called /// - anytime a notification arrives (if subscribed) - Stream> get onValueReceived => FlutterBluePlusPlatform.instance.onCharacteristicReceived + Stream> get onValueReceived => FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnCharacteristicReceived") + .map((m) => m.arguments) + .map((args) => BmCharacteristicData.fromMap(args)) .where((p) => p.remoteId == remoteId) .where((p) => p.serviceUuid == serviceUuid) .where((p) => p.characteristicUuid == characteristicUuid) @@ -109,7 +115,10 @@ class BluetoothCharacteristic { secondaryServiceUuid: null, ); - var responseStream = FlutterBluePlusPlatform.instance.onCharacteristicReceived + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnCharacteristicReceived") + .map((m) => m.arguments) + .map((args) => BmCharacteristicData.fromMap(args)) .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid); @@ -118,7 +127,7 @@ class BluetoothCharacteristic { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.readCharacteristic(request), 'readCharacteristic', request.toMap()); + await FlutterBluePlus._invokeMethod('readCharacteristic', request.toMap()); // wait for response BmCharacteristicData response = await futureResponse @@ -141,7 +150,7 @@ class BluetoothCharacteristic { } /// Writes a characteristic. - /// - [withoutResponse]: + /// - [withoutResponse]: /// If `true`, the write is not guaranteed and always returns immediately with success. /// If `false`, the write returns error on failure. /// - [allowLongWrite]: if set, larger writes > MTU are allowed (up to 512 bytes). @@ -180,7 +189,10 @@ class BluetoothCharacteristic { value: value, ); - var responseStream = FlutterBluePlusPlatform.instance.onCharacteristicWritten + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnCharacteristicWritten") + .map((m) => m.arguments) + .map((args) => BmCharacteristicData.fromMap(args)) .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid); @@ -189,7 +201,7 @@ class BluetoothCharacteristic { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.writeCharacteristic(request), 'writeCharacteristic', request.toMap()); + await FlutterBluePlus._invokeMethod('writeCharacteristic', request.toMap()); // wait for response so that we can: // 1. check for success (writeWithResponse) @@ -242,7 +254,10 @@ class BluetoothCharacteristic { // Notifications & Indications are configured by writing to the // Client Characteristic Configuration Descriptor (CCCD) - Stream responseStream = FlutterBluePlusPlatform.instance.onDescriptorWritten + Stream responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDescriptorWritten") + .map((m) => m.arguments) + .map((args) => BmDescriptorData.fromMap(args)) .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid) @@ -252,7 +267,7 @@ class BluetoothCharacteristic { Future futureResponse = responseStream.first; // invoke - bool hasCCCD = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.setNotifyValue(request), 'setNotifyValue', request.toMap()); + bool hasCCCD = await FlutterBluePlus._invokeMethod('setNotifyValue', request.toMap()); // wait for CCCD descriptor to be written? if (hasCCCD) { diff --git a/packages/flutter_blue_plus/lib/src/bluetooth_descriptor.dart b/lib/src/bluetooth_descriptor.dart similarity index 83% rename from packages/flutter_blue_plus/lib/src/bluetooth_descriptor.dart rename to lib/src/bluetooth_descriptor.dart index 2f7b6f6c..041feb46 100644 --- a/packages/flutter_blue_plus/lib/src/bluetooth_descriptor.dart +++ b/lib/src/bluetooth_descriptor.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -42,7 +42,10 @@ class BluetoothDescriptor { /// - anytime `read()` is called /// - anytime `write()` is called /// - and when first listened to, it re-emits the last value for convenience - Stream> get lastValueStream => _mergeStreams([FlutterBluePlusPlatform.instance.onDescriptorRead, FlutterBluePlusPlatform.instance.onDescriptorWritten]) + Stream> get lastValueStream => FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDescriptorRead" || m.method == "OnDescriptorWritten") + .map((m) => m.arguments) + .map((args) => BmDescriptorData.fromMap(args)) .where((p) => p.remoteId == remoteId) .where((p) => p.characteristicUuid == characteristicUuid) .where((p) => p.serviceUuid == serviceUuid) @@ -53,7 +56,10 @@ class BluetoothDescriptor { /// this stream emits values: /// - anytime `read()` is called - Stream> get onValueReceived => FlutterBluePlusPlatform.instance.onDescriptorRead + Stream> get onValueReceived => FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDescriptorRead") + .map((m) => m.arguments) + .map((args) => BmDescriptorData.fromMap(args)) .where((p) => p.remoteId == remoteId) .where((p) => p.characteristicUuid == characteristicUuid) .where((p) => p.serviceUuid == serviceUuid) @@ -85,7 +91,10 @@ class BluetoothDescriptor { descriptorUuid: descriptorUuid, ); - Stream responseStream = FlutterBluePlusPlatform.instance.onDescriptorRead + Stream responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDescriptorRead") + .map((m) => m.arguments) + .map((args) => BmDescriptorData.fromMap(args)) .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid) @@ -95,7 +104,7 @@ class BluetoothDescriptor { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.readDescriptor(request), 'readDescriptor', request.toMap()); + await FlutterBluePlus._invokeMethod('readDescriptor', request.toMap()); // wait for response BmDescriptorData response = await futureResponse @@ -138,7 +147,10 @@ class BluetoothDescriptor { value: value, ); - Stream responseStream = FlutterBluePlusPlatform.instance.onDescriptorWritten + Stream responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDescriptorWritten") + .map((m) => m.arguments) + .map((args) => BmDescriptorData.fromMap(args)) .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid) @@ -148,7 +160,7 @@ class BluetoothDescriptor { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.writeDescriptor(request), 'writeDescriptor', request.toMap()); + await FlutterBluePlus._invokeMethod('writeDescriptor', request.toMap()); // wait for response BmDescriptorData response = await futureResponse diff --git a/packages/flutter_blue_plus/lib/src/bluetooth_device.dart b/lib/src/bluetooth_device.dart similarity index 88% rename from packages/flutter_blue_plus/lib/src/bluetooth_device.dart rename to lib/src/bluetooth_device.dart index 36b59454..ded23e7b 100644 --- a/packages/flutter_blue_plus/lib/src/bluetooth_device.dart +++ b/lib/src/bluetooth_device.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -120,7 +120,10 @@ class BluetoothDevice { autoConnect: autoConnect, ); - var responseStream = FlutterBluePlusPlatform.instance.onConnectionStateChanged + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnConnectionStateChanged") + .map((m) => m.arguments) + .map((args) => BmConnectionStateResponse.fromMap(args)) .where((p) => p.remoteId == remoteId); // Start listening now, before invokeMethod, to ensure we don't miss the response @@ -132,7 +135,7 @@ class BluetoothDevice { } // invoke - bool changed = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.connect(request), 'connect', request.toMap()); + bool changed = await FlutterBluePlus._invokeMethod('connect', request.toMap()); // we return the disconnect mutex now so that this // connection attempt can be canceled by calling disconnect @@ -145,7 +148,7 @@ class BluetoothDevice { .fbpTimeout(timeout.inSeconds, "connect") .catchError((e) async { if (e is FlutterBluePlusException && e.code == FbpErrorCode.timeout.index) { - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.disconnect(remoteId), 'disconnect', remoteId.str); // cancel connection attempt + await FlutterBluePlus._invokeMethod('disconnect', remoteId.str); // cancel connection attempt } throw e; }); @@ -203,7 +206,10 @@ class BluetoothDevice { // remove from auto connect list if there FlutterBluePlus._autoConnect.remove(remoteId); - var responseStream = FlutterBluePlusPlatform.instance.onConnectionStateChanged + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnConnectionStateChanged") + .map((m) => m.arguments) + .map((args) => BmConnectionStateResponse.fromMap(args)) .where((p) => p.remoteId == remoteId) .where((p) => p.connectionState == BmConnectionStateEnum.disconnected); @@ -214,7 +220,7 @@ class BluetoothDevice { await _ensureAndroidDisconnectionDelay(androidDelay); // invoke - bool changed = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.disconnect(remoteId), 'disconnect', remoteId.str); + bool changed = await FlutterBluePlus._invokeMethod('disconnect', remoteId.str); // only wait for disconnection if weren't already disconnected if (changed) { @@ -251,14 +257,17 @@ class BluetoothDevice { List result = []; try { - var responseStream = FlutterBluePlusPlatform.instance.onDiscoveredServices + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDiscoveredServices") + .map((m) => m.arguments) + .map((args) => BmDiscoverServicesResult.fromMap(args)) .where((p) => p.remoteId == remoteId); // Start listening now, before invokeMethod, to ensure we don't miss the response Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.discoverServices(remoteId), 'discoverServices', remoteId.str); + await FlutterBluePlus._invokeMethod('discoverServices', remoteId.str); // wait for response BmDiscoverServicesResult response = await futureResponse @@ -308,7 +317,10 @@ class BluetoothDevice { if (FlutterBluePlus._connectionStates[remoteId] != null) { initialValue = _bmToConnectionState(FlutterBluePlus._connectionStates[remoteId]!.connectionState); } - return FlutterBluePlusPlatform.instance.onConnectionStateChanged + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnConnectionStateChanged") + .map((m) => m.arguments) + .map((args) => BmConnectionStateResponse.fromMap(args)) .where((p) => p.remoteId == remoteId) .map((p) => _bmToConnectionState(p.connectionState)) .newStreamWithInitialValue(initialValue); @@ -326,7 +338,10 @@ class BluetoothDevice { Stream get mtu { // get initial value from our cache int initialValue = FlutterBluePlus._mtuValues[remoteId]?.mtu ?? 23; - return FlutterBluePlus._onMtuChanged + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnMtuChanged") + .map((m) => m.arguments) + .map((args) => BmMtuChangedResponse.fromMap(args)) .where((p) => p.remoteId == remoteId) .map((p) => p.mtu) .newStreamWithInitialValue(initialValue); @@ -336,7 +351,10 @@ class BluetoothDevice { /// - uses the GAP Services Changed characteristic (0x2A05) /// - you must re-call discoverServices() when services are reset Stream get onServicesReset { - return FlutterBluePlusPlatform.instance.onServicesReset + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnServicesReset") + .map((m) => m.arguments) + .map((args) => BmBluetoothDevice.fromMap(args)) .where((p) => p.remoteId == remoteId) .map((m) => null); } @@ -356,14 +374,17 @@ class BluetoothDevice { int rssi = 0; try { - var responseStream = FlutterBluePlusPlatform.instance.onReadRssi + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnReadRssi") + .map((m) => m.arguments) + .map((args) => BmReadRssiResult.fromMap(args)) .where((p) => (p.remoteId == remoteId)); // Start listening now, before invokeMethod, to ensure we don't miss the response Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.readRssi(remoteId), 'readRssi', remoteId.str); + await FlutterBluePlus._invokeMethod('readRssi', remoteId.str); // wait for response BmReadRssiResult response = await futureResponse @@ -431,7 +452,10 @@ class BluetoothDevice { mtu: desiredMtu, ); - var responseStream = FlutterBluePlus._onMtuChanged + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnMtuChanged") + .map((m) => m.arguments) + .map((args) => BmMtuChangedResponse.fromMap(args)) .where((p) => p.remoteId == remoteId) .map((p) => p.mtu); @@ -439,7 +463,7 @@ class BluetoothDevice { Future futureResponse = responseStream.first; // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.requestMtu(request), 'requestMtu', request.toMap()); + await FlutterBluePlus._invokeMethod('requestMtu', request.toMap()); // wait for response mtu = await futureResponse @@ -473,7 +497,7 @@ class BluetoothDevice { ); // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.requestConnectionPriority(request), 'requestConnectionPriority', request.toMap()); + await FlutterBluePlus._invokeMethod('requestConnectionPriority', request.toMap()); } /// Set the preferred connection (Android Only) @@ -506,7 +530,7 @@ class BluetoothDevice { ); // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.setPreferredPhy(request), 'setPreferredPhy', request.toMap()); + await FlutterBluePlus._invokeMethod('setPreferredPhy', request.toMap()); } /// Force the bonding popup to show now (Android Only) @@ -528,7 +552,10 @@ class BluetoothDevice { await mtx.take(); try { - var responseStream = FlutterBluePlusPlatform.instance.onBondStateChanged + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnBondStateChanged") + .map((m) => m.arguments) + .map((args) => BmBondStateResponse.fromMap(args)) .where((p) => p.remoteId == remoteId) .where((p) => p.bondState != BmBondStateEnum.bonding); @@ -536,7 +563,7 @@ class BluetoothDevice { Future futureResponse = responseStream.first; // invoke - bool changed = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.createBond(remoteId), 'createBond', remoteId.str); + bool changed = await FlutterBluePlus._invokeMethod('createBond', remoteId.str); // only wait for 'bonded' if we weren't already bonded if (changed) { @@ -568,7 +595,10 @@ class BluetoothDevice { await mtx.take(); try { - var responseStream = FlutterBluePlusPlatform.instance.onBondStateChanged + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnBondStateChanged") + .map((m) => m.arguments) + .map((args) => BmBondStateResponse.fromMap(args)) .where((p) => p.remoteId == remoteId) .where((p) => p.bondState != BmBondStateEnum.bonding); @@ -576,7 +606,7 @@ class BluetoothDevice { Future futureResponse = responseStream.first; // invoke - bool changed = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.removeBond(remoteId), 'removeBond', remoteId.str); + bool changed = await FlutterBluePlus._invokeMethod('removeBond', remoteId.str); // only wait for 'unbonded' state if we weren't already unbonded if (changed) { @@ -611,7 +641,7 @@ class BluetoothDevice { } // invoke - await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.clearGattCache(remoteId), 'clearGattCache', remoteId.str); + await FlutterBluePlus._invokeMethod('clearGattCache', remoteId.str); } /// Get the current bondState of the device (Android Only) @@ -623,14 +653,19 @@ class BluetoothDevice { // get current state if needed if (FlutterBluePlus._bondStates[remoteId] == null) { - var val = await FlutterBluePlus._invokeMethod(() => FlutterBluePlusPlatform.instance.getBondState(remoteId), 'getBondState', remoteId.str); + var val = await FlutterBluePlus._methodChannel + .invokeMethod('getBondState', remoteId.str) + .then((args) => BmBondStateResponse.fromMap(args)); // update _bondStates if it is still null after the await if (FlutterBluePlus._bondStates[remoteId] == null) { FlutterBluePlus._bondStates[remoteId] = val; } } - yield* FlutterBluePlusPlatform.instance.onBondStateChanged + yield* FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnBondStateChanged") + .map((m) => m.arguments) + .map((args) => BmBondStateResponse.fromMap(args)) .where((p) => p.remoteId == remoteId) .map((p) => _bmToBondState(p.bondState)) .newStreamWithInitialValue(_bmToBondState(FlutterBluePlus._bondStates[remoteId]!.bondState)); diff --git a/packages/flutter_blue_plus/lib/src/bluetooth_events.dart b/lib/src/bluetooth_events.dart similarity index 76% rename from packages/flutter_blue_plus/lib/src/bluetooth_events.dart rename to lib/src/bluetooth_events.dart index d493fba2..e74bde23 100644 --- a/packages/flutter_blue_plus/lib/src/bluetooth_events.dart +++ b/lib/src/bluetooth_events.dart @@ -1,63 +1,91 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. -// All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - part of flutter_blue_plus; class BluetoothEvents { Stream get onConnectionStateChanged { - return FlutterBluePlusPlatform.instance.onConnectionStateChanged + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnConnectionStateChanged") + .map((m) => m.arguments) + .map((args) => BmConnectionStateResponse.fromMap(args)) .map((p) => OnConnectionStateChangedEvent(p)); } Stream get onMtuChanged { - return FlutterBluePlus._onMtuChanged + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnMtuChanged") + .map((m) => m.arguments) + .map((args) => BmMtuChangedResponse.fromMap(args)) .map((p) => OnMtuChangedEvent(p)); } Stream get onReadRssi { - return FlutterBluePlusPlatform.instance.onReadRssi + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnReadRssi") + .map((m) => m.arguments) + .map((args) => BmReadRssiResult.fromMap(args)) .map((p) => OnReadRssiEvent(p)); } Stream get onServicesReset { - return FlutterBluePlusPlatform.instance.onServicesReset + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnServicesReset") + .map((m) => m.arguments) + .map((args) => BmBluetoothDevice.fromMap(args)) .map((p) => OnServicesResetEvent(p)); } Stream get onDiscoveredServices { - return FlutterBluePlusPlatform.instance.onDiscoveredServices + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDiscoveredServices") + .map((m) => m.arguments) + .map((args) => BmDiscoverServicesResult.fromMap(args)) .map((p) => OnDiscoveredServicesEvent(p)); } Stream get onCharacteristicReceived { - return FlutterBluePlusPlatform.instance.onCharacteristicReceived + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnCharacteristicReceived") + .map((m) => m.arguments) + .map((args) => BmCharacteristicData.fromMap(args)) .map((p) => OnCharacteristicReceivedEvent(p)); } Stream get onCharacteristicWritten { - return FlutterBluePlusPlatform.instance.onCharacteristicWritten + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnCharacteristicWritten") + .map((m) => m.arguments) + .map((args) => BmCharacteristicData.fromMap(args)) .map((p) => OnCharacteristicWrittenEvent(p)); } Stream get onDescriptorRead { - return FlutterBluePlusPlatform.instance.onDescriptorRead + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDescriptorRead") + .map((m) => m.arguments) + .map((args) => BmDescriptorData.fromMap(args)) .map((p) => OnDescriptorReadEvent(p)); } Stream get onDescriptorWritten { - return FlutterBluePlusPlatform.instance.onDescriptorWritten + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnDescriptorWritten") + .map((m) => m.arguments) + .map((args) => BmDescriptorData.fromMap(args)) .map((p) => OnDescriptorWrittenEvent(p)); } Stream get onNameChanged { - return FlutterBluePlusPlatform.instance.onNameChanged - .map((p) => BmBluetoothDevice(remoteId: p.remoteId, platformName: p.name)) + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnNameChanged") + .map((m) => m.arguments) + .map((args) => BmBluetoothDevice.fromMap(args)) .map((p) => OnNameChangedEvent(p)); } Stream get onBondStateChanged { - return FlutterBluePlusPlatform.instance.onBondStateChanged + return FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnBondStateChanged") + .map((m) => m.arguments) + .map((args) => BmBondStateResponse.fromMap(args)) .map((p) => OnBondStateChangedEvent(p)); } } diff --git a/lib/src/bluetooth_msgs.dart b/lib/src/bluetooth_msgs.dart new file mode 100644 index 00000000..1e80a2b4 --- /dev/null +++ b/lib/src/bluetooth_msgs.dart @@ -0,0 +1,861 @@ +part of flutter_blue_plus; + +enum BmAdapterStateEnum { + unknown, // 0 + unavailable, // 1 + unauthorized, // 2 + turningOn, // 3 + on, // 4 + turningOff, // 5 + off, // 6 +} + +class BmBluetoothAdapterState { + BmAdapterStateEnum adapterState; + + BmBluetoothAdapterState({required this.adapterState}); + + Map toMap() { + final Map data = {}; + data['adapter_state'] = adapterState.index; + return data; + } + + factory BmBluetoothAdapterState.fromMap(Map json) { + return BmBluetoothAdapterState( + adapterState: BmAdapterStateEnum.values[json['adapter_state']], + ); + } +} + +class BmMsdFilter { + int manufacturerId; + List? data; + List? mask; + BmMsdFilter(this.manufacturerId, this.data, this.mask); + Map toMap() { + final Map map = {}; + map['manufacturer_id'] = manufacturerId; + map['data'] = _hexEncode(data ?? []); + map['mask'] = _hexEncode(mask ?? []); + return map; + } +} + +class BmServiceDataFilter { + Guid service; + List data; + List mask; + BmServiceDataFilter(this.service, this.data, this.mask); + Map toMap() { + final Map map = {}; + map['service'] = service.str; + map['data'] = _hexEncode(data); + map['mask'] = _hexEncode(mask); + return map; + } +} + +class BmScanSettings { + final List withServices; + final List withRemoteIds; + final List withNames; + final List withKeywords; + final List withMsd; + final List withServiceData; + final bool continuousUpdates; + final int continuousDivisor; + final bool androidLegacy; + final int androidScanMode; + final bool androidUsesFineLocation; + + BmScanSettings({ + required this.withServices, + required this.withRemoteIds, + required this.withNames, + required this.withKeywords, + required this.withMsd, + required this.withServiceData, + required this.continuousUpdates, + required this.continuousDivisor, + required this.androidLegacy, + required this.androidScanMode, + required this.androidUsesFineLocation, + }); + + Map toMap() { + final Map data = {}; + data['with_services'] = withServices.map((s) => s.str).toList(); + data['with_remote_ids'] = withRemoteIds; + data['with_names'] = withNames; + data['with_keywords'] = withKeywords; + data['with_msd'] = withMsd.map((d) => d.toMap()).toList(); + data['with_service_data'] = withServiceData.map((d) => d.toMap()).toList(); + data['continuous_updates'] = continuousUpdates; + data['continuous_divisor'] = continuousDivisor; + data['android_legacy'] = androidLegacy; + data['android_scan_mode'] = androidScanMode; + data['android_uses_fine_location'] = androidUsesFineLocation; + return data; + } +} + +class BmScanAdvertisement { + final DeviceIdentifier remoteId; + final String? platformName; + final String? advName; + final bool connectable; + final int? txPowerLevel; + final int? appearance; // not supported on iOS / macOS + final Map> manufacturerData; + final Map> serviceData; + final List serviceUuids; + final int rssi; + + BmScanAdvertisement({ + required this.remoteId, + required this.platformName, + required this.advName, + required this.connectable, + required this.txPowerLevel, + required this.appearance, + required this.manufacturerData, + required this.serviceData, + required this.serviceUuids, + required this.rssi, + }); + + factory BmScanAdvertisement.fromMap(Map json) { + // Get raw data + var rawManufacturerData = json['manufacturer_data'] ?? {}; + var rawServiceData = json['service_data'] ?? {}; + var rawServiceUuids = json['service_uuids'] ?? []; + + // Cast the data to the right type + Map> manufacturerData = {}; + for (var key in rawManufacturerData.keys) { + manufacturerData[key] = _hexDecode(rawManufacturerData[key]); + } + + // Cast the data to the right type + Map> serviceData = {}; + for (var key in rawServiceData.keys) { + serviceData[Guid(key)] = _hexDecode(rawServiceData[key]); + } + + // Cast the data to the right type + List serviceUuids = []; + for (var val in rawServiceUuids) { + serviceUuids.add(Guid(val)); + } + + return BmScanAdvertisement( + remoteId: DeviceIdentifier(json['remote_id']), + platformName: json['platform_name'], + advName: json['adv_name'], + connectable: json['connectable'] != null ? json['connectable'] != 0 : false, + txPowerLevel: json['tx_power_level'], + appearance: json['appearance'], + manufacturerData: manufacturerData, + serviceData: serviceData, + serviceUuids: serviceUuids, + rssi: json['rssi'] != null ? json['rssi'] : 0, + ); + } +} + +class BmScanResponse { + final List advertisements; + final bool success; + final int errorCode; + final String errorString; + + BmScanResponse({ + required this.advertisements, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmScanResponse.fromMap(Map json) { + List advertisements = []; + for (var item in json['advertisements']) { + advertisements.add(BmScanAdvertisement.fromMap(item)); + } + + bool success = json['success'] == null || json['success'] != 0; + + return BmScanResponse( + advertisements: advertisements, + success: success, + errorCode: !success ? json['error_code'] : 0, + errorString: !success ? json['error_string'] : "", + ); + } +} + +class BmConnectRequest { + DeviceIdentifier remoteId; + bool autoConnect; + + BmConnectRequest({ + required this.remoteId, + required this.autoConnect, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['auto_connect'] = autoConnect ? 1 : 0; + return data; + } +} + +class BmBluetoothDevice { + DeviceIdentifier remoteId; + String? platformName; + + BmBluetoothDevice({ + required this.remoteId, + required this.platformName, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['platform_name'] = platformName; + return data; + } + + factory BmBluetoothDevice.fromMap(Map json) { + return BmBluetoothDevice( + remoteId: DeviceIdentifier(json['remote_id']), + platformName: json['platform_name'], + ); + } +} + +class BmNameChanged { + DeviceIdentifier remoteId; + String name; + + BmNameChanged({ + required this.remoteId, + required this.name, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['name'] = name; + return data; + } + + factory BmNameChanged.fromMap(Map json) { + return BmNameChanged( + remoteId: DeviceIdentifier(json['remote_id']), + name: json['name'], + ); + } +} + +class BmBluetoothService { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + bool isPrimary; + List characteristics; + List includedServices; + + BmBluetoothService({ + required this.serviceUuid, + required this.remoteId, + required this.isPrimary, + required this.characteristics, + required this.includedServices, + }); + + factory BmBluetoothService.fromMap(Map json) { + // convert characteristics + List chrs = []; + for (var v in json['characteristics']) { + chrs.add(BmBluetoothCharacteristic.fromMap(v)); + } + + // convert services + List svcs = []; + for (var v in json['included_services']) { + svcs.add(BmBluetoothService.fromMap(v)); + } + + return BmBluetoothService( + serviceUuid: Guid(json['service_uuid']), + remoteId: DeviceIdentifier(json['remote_id']), + isPrimary: json['is_primary'] != 0, + characteristics: chrs, + includedServices: svcs, + ); + } +} + +class BmBluetoothCharacteristic { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + List descriptors; + BmCharacteristicProperties properties; + + BmBluetoothCharacteristic({ + required this.remoteId, + required this.serviceUuid, + required this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptors, + required this.properties, + }); + + factory BmBluetoothCharacteristic.fromMap(Map json) { + // convert descriptors + List descs = []; + for (var v in json['descriptors']) { + descs.add(BmBluetoothDescriptor.fromMap(v)); + } + + return BmBluetoothCharacteristic( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptors: descs, + properties: BmCharacteristicProperties.fromMap(json['properties']), + ); + } +} + +class BmBluetoothDescriptor { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + + BmBluetoothDescriptor({ + required this.remoteId, + required this.serviceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + }); + + factory BmBluetoothDescriptor.fromMap(Map json) { + return BmBluetoothDescriptor( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + ); + } +} + +class BmCharacteristicProperties { + bool broadcast; + bool read; + bool writeWithoutResponse; + bool write; + bool notify; + bool indicate; + bool authenticatedSignedWrites; + bool extendedProperties; + bool notifyEncryptionRequired; + bool indicateEncryptionRequired; + + BmCharacteristicProperties({ + required this.broadcast, + required this.read, + required this.writeWithoutResponse, + required this.write, + required this.notify, + required this.indicate, + required this.authenticatedSignedWrites, + required this.extendedProperties, + required this.notifyEncryptionRequired, + required this.indicateEncryptionRequired, + }); + + factory BmCharacteristicProperties.fromMap(Map json) { + return BmCharacteristicProperties( + broadcast: json['broadcast'] != 0, + read: json['read'] != 0, + writeWithoutResponse: json['write_without_response'] != 0, + write: json['write'] != 0, + notify: json['notify'] != 0, + indicate: json['indicate'] != 0, + authenticatedSignedWrites: json['authenticated_signed_writes'] != 0, + extendedProperties: json['extended_properties'] != 0, + notifyEncryptionRequired: json['notify_encryption_required'] != 0, + indicateEncryptionRequired: json['indicate_encryption_required'] != 0, + ); + } +} + +class BmDiscoverServicesResult { + final DeviceIdentifier remoteId; + final List services; + final bool success; + final int errorCode; + final String errorString; + + BmDiscoverServicesResult({ + required this.remoteId, + required this.services, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmDiscoverServicesResult.fromMap(Map json) { + return BmDiscoverServicesResult( + remoteId: DeviceIdentifier(json['remote_id']), + services: (json['services'] as List) + .map((e) => BmBluetoothService.fromMap(e as Map)) + .toList(), + success: json['success'] != 0, + errorCode: json['error_code'], + errorString: json['error_string'], + ); + } +} + +class BmReadCharacteristicRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + + BmReadCharacteristicRequest({ + required this.remoteId, + required this.serviceUuid, + this.secondaryServiceUuid, + required this.characteristicUuid, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['service_uuid'] = serviceUuid.str; + data['secondary_service_uuid'] = secondaryServiceUuid?.str; + data['characteristic_uuid'] = characteristicUuid.str; + return data; + } +} + +class BmCharacteristicData { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final List value; + final bool success; + final int errorCode; + final String errorString; + + BmCharacteristicData({ + required this.remoteId, + required this.serviceUuid, + required this.secondaryServiceUuid, + required this.characteristicUuid, + required this.value, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmCharacteristicData.fromMap(Map json) { + return BmCharacteristicData( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, + characteristicUuid: Guid(json['characteristic_uuid']), + value: _hexDecode(json['value']), + success: json['success'] != 0, + errorCode: json['error_code'], + errorString: json['error_string'], + ); + } +} + +class BmReadDescriptorRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + + BmReadDescriptorRequest({ + required this.remoteId, + required this.serviceUuid, + required this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['service_uuid'] = serviceUuid.str; + data['secondary_service_uuid'] = secondaryServiceUuid?.str; + data['characteristic_uuid'] = characteristicUuid.str; + data['descriptor_uuid'] = descriptorUuid.str; + return data; + } +} + +enum BmWriteType { + withResponse, + withoutResponse, +} + +class BmWriteCharacteristicRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final BmWriteType writeType; + final bool allowLongWrite; + final List value; + + BmWriteCharacteristicRequest({ + required this.remoteId, + required this.serviceUuid, + required this.secondaryServiceUuid, + required this.characteristicUuid, + required this.writeType, + required this.allowLongWrite, + required this.value, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['service_uuid'] = serviceUuid.str; + data['secondary_service_uuid'] = secondaryServiceUuid?.str; + data['characteristic_uuid'] = characteristicUuid.str; + data['write_type'] = writeType.index; + data['allow_long_write'] = allowLongWrite ? 1 : 0; + data['value'] = _hexEncode(value); + return data; + } +} + +class BmWriteDescriptorRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + final List value; + + BmWriteDescriptorRequest({ + required this.remoteId, + required this.serviceUuid, + required this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + required this.value, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['service_uuid'] = serviceUuid.str; + data['secondary_service_uuid'] = secondaryServiceUuid?.str; + data['characteristic_uuid'] = characteristicUuid.str; + data['descriptor_uuid'] = descriptorUuid.str; + data['value'] = _hexEncode(value); + return data; + } +} + +class BmDescriptorData { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final Guid descriptorUuid; + final List value; + final bool success; + final int errorCode; + final String errorString; + + BmDescriptorData({ + required this.remoteId, + required this.serviceUuid, + required this.secondaryServiceUuid, + required this.characteristicUuid, + required this.descriptorUuid, + required this.value, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmDescriptorData.fromMap(Map json) { + return BmDescriptorData( + remoteId: DeviceIdentifier(json['remote_id']), + serviceUuid: Guid(json['service_uuid']), + secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, + characteristicUuid: Guid(json['characteristic_uuid']), + descriptorUuid: Guid(json['descriptor_uuid']), + value: _hexDecode(json['value']), + success: json['success'] != 0, + errorCode: json['error_code'], + errorString: json['error_string'], + ); + } +} + +class BmSetNotifyValueRequest { + final DeviceIdentifier remoteId; + final Guid serviceUuid; + final Guid? secondaryServiceUuid; + final Guid characteristicUuid; + final bool forceIndications; + final bool enable; + + BmSetNotifyValueRequest({ + required this.remoteId, + required this.serviceUuid, + required this.secondaryServiceUuid, + required this.characteristicUuid, + required this.forceIndications, + required this.enable, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['service_uuid'] = serviceUuid.str; + data['secondary_service_uuid'] = secondaryServiceUuid?.str; + data['characteristic_uuid'] = characteristicUuid.str; + data['force_indications'] = forceIndications; + data['enable'] = enable; + return data; + } +} + +enum BmConnectionStateEnum { + disconnected, // 0 + connected, // 1 +} + +class BmConnectionStateResponse { + final DeviceIdentifier remoteId; + final BmConnectionStateEnum connectionState; + final int? disconnectReasonCode; + final String? disconnectReasonString; + + BmConnectionStateResponse({ + required this.remoteId, + required this.connectionState, + required this.disconnectReasonCode, + required this.disconnectReasonString, + }); + + factory BmConnectionStateResponse.fromMap(Map json) { + return BmConnectionStateResponse( + remoteId: DeviceIdentifier(json['remote_id']), + connectionState: BmConnectionStateEnum.values[json['connection_state'] as int], + disconnectReasonCode: json['disconnect_reason_code'], + disconnectReasonString: json['disconnect_reason_string'], + ); + } +} + +class BmDevicesList { + final List devices; + + BmDevicesList({required this.devices}); + + factory BmDevicesList.fromMap(Map json) { + // convert to BmBluetoothDevice + List devices = []; + for (var i = 0; i < json['devices'].length; i++) { + devices.add(BmBluetoothDevice.fromMap(json['devices'][i])); + } + return BmDevicesList(devices: devices); + } +} + +class BmMtuChangeRequest { + final DeviceIdentifier remoteId; + final int mtu; + + BmMtuChangeRequest({required this.remoteId, required this.mtu}); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['mtu'] = mtu; + return data; + } +} + +class BmMtuChangedResponse { + final DeviceIdentifier remoteId; + final int mtu; + final bool success; + final int errorCode; + final String errorString; + + BmMtuChangedResponse({ + required this.remoteId, + required this.mtu, + this.success = true, + this.errorCode = 0, + this.errorString = "", + }); + + factory BmMtuChangedResponse.fromMap(Map json) { + return BmMtuChangedResponse( + remoteId: DeviceIdentifier(json['remote_id']), + mtu: json['mtu'], + success: json['success'] != 0, + errorCode: json['error_code'], + errorString: json['error_string'], + ); + } + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['mtu'] = mtu; + data['success'] = success ? 1 : 0; + data['error_code'] = errorCode; + data['error_string'] = errorString; + return data; + } +} + +class BmReadRssiResult { + final DeviceIdentifier remoteId; + final int rssi; + final bool success; + final int errorCode; + final String errorString; + + BmReadRssiResult({ + required this.remoteId, + required this.rssi, + required this.success, + required this.errorCode, + required this.errorString, + }); + + factory BmReadRssiResult.fromMap(Map json) { + return BmReadRssiResult( + remoteId: DeviceIdentifier(json['remote_id']), + rssi: json['rssi'], + success: json['success'] != 0, + errorCode: json['error_code'], + errorString: json['error_string'], + ); + } +} + +enum BmConnectionPriorityEnum { + balanced, // 0 + high, // 1 + lowPower, // 2 +} + +class BmConnectionPriorityRequest { + final DeviceIdentifier remoteId; + final BmConnectionPriorityEnum connectionPriority; + + BmConnectionPriorityRequest({ + required this.remoteId, + required this.connectionPriority, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['connection_priority'] = connectionPriority.index; + return data; + } +} + +class BmPreferredPhy { + final DeviceIdentifier remoteId; + final int txPhy; + final int rxPhy; + final int phyOptions; + + BmPreferredPhy({ + required this.remoteId, + required this.txPhy, + required this.rxPhy, + required this.phyOptions, + }); + + Map toMap() { + final Map data = {}; + data['remote_id'] = remoteId.str; + data['tx_phy'] = txPhy; + data['rx_phy'] = rxPhy; + data['phy_options'] = phyOptions; + return data; + } + + factory BmPreferredPhy.fromMap(Map json) { + return BmPreferredPhy( + remoteId: DeviceIdentifier(json['remote_id']), + txPhy: json['tx_phy'], + rxPhy: json['rx_phy'], + phyOptions: json['phy_options'], + ); + } +} + +enum BmBondStateEnum { + none, // 0 + bonding, // 1 + bonded, // 2 +} + +class BmBondStateResponse { + final DeviceIdentifier remoteId; + final BmBondStateEnum bondState; + final BmBondStateEnum? prevState; + + BmBondStateResponse({ + required this.remoteId, + required this.bondState, + required this.prevState, + }); + + factory BmBondStateResponse.fromMap(Map json) { + return BmBondStateResponse( + remoteId: DeviceIdentifier(json['remote_id']), + bondState: BmBondStateEnum.values[json['bond_state']], + prevState: json['prev_state'] != null ? BmBondStateEnum.values[json['prev_state']] : null, + ); + } +} + +// BmTurnOnResponse +class BmTurnOnResponse { + bool userAccepted; + + BmTurnOnResponse({ + required this.userAccepted, + }); + + factory BmTurnOnResponse.fromMap(Map json) { + return BmTurnOnResponse( + userAccepted: json['user_accepted'], + ); + } +} + +// random number defined by flutter blue plus. +// Ideally it should not conflict with iOS or Android error codes. +int bmUserCanceledErrorCode = 23789258; diff --git a/packages/flutter_blue_plus/lib/src/bluetooth_service.dart b/lib/src/bluetooth_service.dart similarity index 94% rename from packages/flutter_blue_plus/lib/src/bluetooth_service.dart rename to lib/src/bluetooth_service.dart index 89c6f830..3e3e10ce 100644 --- a/packages/flutter_blue_plus/lib/src/bluetooth_service.dart +++ b/lib/src/bluetooth_service.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. diff --git a/packages/flutter_blue_plus/lib/src/bluetooth_utils.dart b/lib/src/bluetooth_utils.dart similarity index 95% rename from packages/flutter_blue_plus/lib/src/bluetooth_utils.dart rename to lib/src/bluetooth_utils.dart index b3e2de8d..793104cc 100644 --- a/packages/flutter_blue_plus/lib/src/bluetooth_utils.dart +++ b/lib/src/bluetooth_utils.dart @@ -1,7 +1,3 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. -// All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - part of flutter_blue_plus; /// State of the bluetooth adapter. diff --git a/packages/flutter_blue_plus/lib/src/flutter_blue_plus.dart b/lib/src/flutter_blue_plus.dart similarity index 82% rename from packages/flutter_blue_plus/lib/src/flutter_blue_plus.dart rename to lib/src/flutter_blue_plus.dart index f1ccb8c3..1b872201 100644 --- a/packages/flutter_blue_plus/lib/src/flutter_blue_plus.dart +++ b/lib/src/flutter_blue_plus.dart @@ -1,4 +1,4 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. +// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -11,6 +11,13 @@ class FlutterBluePlus { static bool _initialized = false; + /// native platform channel + static final MethodChannel _methodChannel = const MethodChannel('flutter_blue_plus/methods'); + + /// a broadcast stream version of the MethodChannel + // ignore: close_sinks + static final StreamController _methodStream = StreamController.broadcast(); + // always keep track of these device variables static final Map _connectionStates = {}; static final Map _knownServices = {}; @@ -32,12 +39,6 @@ class FlutterBluePlus { /// stream used for the scanResults public api static final _scanResults = _StreamControllerReEmit>(initialValue: []); - /// stream used for merging internal and external changes to the mtu - static final _onMtuChanged = _mergeStreams([_onMtuChangedController.stream, FlutterBluePlusPlatform.instance.onMtuChanged]); - - /// stream used for internal changes to the mtu when the connection state changes - static final _onMtuChangedController = StreamController.broadcast(); - /// buffers the scan results static _BufferStream? _scanBuffer; @@ -61,14 +62,14 @@ class FlutterBluePlus { static LogLevel get logLevel => _logLevel; /// Checks whether the hardware supports Bluetooth - static Future get isSupported async => await _invokeMethod(() => FlutterBluePlusPlatform.instance.isSupported(), 'isSupported'); + static Future get isSupported async => await _invokeMethod('isSupported'); /// The current adapter state static BluetoothAdapterState get adapterStateNow => _adapterStateNow != null ? _bmToAdapterState(_adapterStateNow!) : BluetoothAdapterState.unknown; /// Return the friendly Bluetooth name of the local Bluetooth adapter - static Future get adapterName async => await _invokeMethod(() => FlutterBluePlusPlatform.instance.getAdapterName(), 'getAdapterName'); + static Future get adapterName async => await _invokeMethod('getAdapterName'); /// returns whether we are scanning as a stream static Stream get isScanning => _isScanning.stream; @@ -107,20 +108,21 @@ class FlutterBluePlus { static Future setOptions({ bool showPowerAlert = true, }) async { - final options = Options(showPowerAlert: showPowerAlert); - - await _invokeMethod(() => FlutterBluePlusPlatform.instance.setOptions(options), 'setOptions', options.toMap()); + await _invokeMethod('setOptions', {"show_power_alert": showPowerAlert}); } /// Turn on Bluetooth (Android only), static Future turnOn({int timeout = 60}) async { - var responseStream = FlutterBluePlusPlatform.instance.onTurnOnResponse; + var responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnTurnOnResponse") + .map((m) => m.arguments) + .map((args) => BmTurnOnResponse.fromMap(args)); // Start listening now, before invokeMethod, to ensure we don't miss the response Future futureResponse = responseStream.first; // invoke - bool changed = await _invokeMethod(() => FlutterBluePlusPlatform.instance.turnOn(), 'turnOn'); + bool changed = await _invokeMethod('turnOn'); // only wait if bluetooth was off if (changed) { @@ -141,14 +143,18 @@ class FlutterBluePlus { static Stream get adapterState async* { // get current state if needed if (_adapterStateNow == null) { - var result = await _invokeMethod(() => FlutterBluePlusPlatform.instance.getAdapterState(), 'getAdapterState'); + var result = await _invokeMethod('getAdapterState'); + var value = BmBluetoothAdapterState.fromMap(result).adapterState; // update _adapterStateNow if it is still null after the await if (_adapterStateNow == null) { - _adapterStateNow = result.adapterState; + _adapterStateNow = value; } } - yield* FlutterBluePlusPlatform.instance.onAdapterStateChanged + yield* FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnAdapterStateChanged") + .map((m) => m.arguments) + .map((args) => BmBluetoothAdapterState.fromMap(args)) .map((s) => _bmToAdapterState(s.adapterState)) .newStreamWithInitialValue(_bmToAdapterState(_adapterStateNow!)); } @@ -164,24 +170,26 @@ class FlutterBluePlus { /// - The list includes devices connected to by *any* app /// - You must still call device.connect() to connect them to *your app* static Future> get systemDevices async { - var result = await _invokeMethod(() => FlutterBluePlusPlatform.instance.getSystemDevices(), 'getSystemDevices'); - for (BmBluetoothDevice device in result) { + var result = await _invokeMethod('getSystemDevices'); + var r = BmDevicesList.fromMap(result); + for (BmBluetoothDevice device in r.devices) { if (device.platformName != null) { _platformNames[device.remoteId] = device.platformName!; } } - return result.map((d) => BluetoothDevice.fromId(d.remoteId.str)).toList(); + return r.devices.map((d) => BluetoothDevice.fromId(d.remoteId.str)).toList(); } /// Retrieve a list of bonded devices (Android only) static Future> get bondedDevices async { - var result = await _invokeMethod(() => FlutterBluePlusPlatform.instance.getBondedDevices(), 'getBondedDevices'); - for (BmBluetoothDevice device in result) { + var result = await _invokeMethod('getBondedDevices'); + var r = BmDevicesList.fromMap(result); + for (BmBluetoothDevice device in r.devices) { if (device.platformName != null) { _platformNames[device.remoteId] = device.platformName!; } } - return result.map((d) => BluetoothDevice.fromId(d.remoteId.str)).toList(); + return r.devices.map((d) => BluetoothDevice.fromId(d.remoteId.str)).toList(); } /// Start a scan, and return a stream of results @@ -269,13 +277,16 @@ class FlutterBluePlus { androidScanMode: androidScanMode.value, androidUsesFineLocation: androidUsesFineLocation); - Stream responseStream = FlutterBluePlusPlatform.instance.onScanResponse; + Stream responseStream = FlutterBluePlus._methodStream.stream + .where((m) => m.method == "OnScanResponse") + .map((m) => m.arguments) + .map((args) => BmScanResponse.fromMap(args)); // Start listening now, before invokeMethod, so we do not miss any results _scanBuffer = _BufferStream.listen(responseStream); // invoke platform method - await _invokeMethod(() => FlutterBluePlusPlatform.instance.startScan(settings), 'startScan', settings.toMap()).onError((e, s) => _stopScan(invokePlatform: false)); + await _invokeMethod('startScan', settings.toMap()).onError((e, s) => _stopScan(invokePlatform: false)); // check every 250ms for gone devices? late Stream outputStream = removeIfGone != null @@ -368,7 +379,7 @@ class FlutterBluePlus { subscription.cancel(); } if (invokePlatform) { - await _invokeMethod(() => FlutterBluePlusPlatform.instance.stopScan(), 'stopScan'); + await _invokeMethod('stopScan'); } } @@ -384,7 +395,7 @@ class FlutterBluePlus { static Future setLogLevel(LogLevel level, {color = true}) async { _logLevel = level; _logColor = color; - await _invokeMethod(() => FlutterBluePlusPlatform.instance.setLogLevel(level), 'setLogLevel', level.index); + await _invokeMethod('setLogLevel', level.index); } /// Request Bluetooth PHY support @@ -395,7 +406,7 @@ class FlutterBluePlus { ErrorPlatform.fbp, "getPhySupport", FbpErrorCode.androidOnly.index, "android-only"); } - return await _invokeMethod(() => FlutterBluePlusPlatform.instance.getPhySupport(), 'getPhySupport'); + return await _invokeMethod('getPhySupport').then((args) => PhySupport.fromMap(args)); } static Future _initFlutterBluePlus() async { @@ -405,16 +416,39 @@ class FlutterBluePlus { _initialized = true; + // set platform method handler + _methodChannel.setMethodCallHandler(_methodCallHandler); + + // flutter restart - wait for all devices to disconnect + if ((await _methodChannel.invokeMethod('flutterRestart')) != 0) { + await Future.delayed(Duration(milliseconds: 50)); + while ((await _methodChannel.invokeMethod('connectedCount')) != 0) { + await Future.delayed(Duration(milliseconds: 50)); + } + } + } + + static Future _methodCallHandler(MethodCall call) async { + // log result + if (logLevel == LogLevel.verbose) { + String func = '[[ ${call.method} ]]'; + String result = call.arguments.toString(); + func = _logColor ? _black(func) : func; + result = _logColor ? _brown(result) : result; + print("[FBP] $func result: $result"); + } + // android only - FlutterBluePlusPlatform.instance.onDetachedFromEngine.log('OnDetachedFromEngine').listen((_) async { - await _stopScan(invokePlatform: false); - }); + if (call.method == "OnDetachedFromEngine") { + _stopScan(invokePlatform: false); + } // keep track of adapter states - FlutterBluePlusPlatform.instance.onAdapterStateChanged.log('OnAdapterStateChanged', (r) => r.toMap()).listen((r) async { + if (call.method == "OnAdapterStateChanged") { + BmBluetoothAdapterState r = BmBluetoothAdapterState.fromMap(call.arguments); _adapterStateNow = r.adapterState; if (isScanningNow && r.adapterState != BmAdapterStateEnum.on) { - await _stopScan(invokePlatform: false); + _stopScan(invokePlatform: false); } if (r.adapterState == BmAdapterStateEnum.on) { for (DeviceIdentifier d in _autoConnect) { @@ -425,16 +459,17 @@ class FlutterBluePlus { }); } } - }); + } - // keep track of connection states and cancel delayed subscriptions - FlutterBluePlusPlatform.instance.onConnectionStateChanged.log('OnConnectionStateChanged', (r) => r.toMap()).listen((r) async { + // keep track of connection states + if (call.method == "OnConnectionStateChanged") { + var r = BmConnectionStateResponse.fromMap(call.arguments); _connectionStates[r.remoteId] = r; - if (r.connectionState == BmConnectionStateEnum.disconnected) { // push to mtu stream, if needed if (_mtuValues.containsKey(r.remoteId)) { - _onMtuChangedController.add(BmMtuChangedResponse(remoteId: r.remoteId, mtu: 23)); + var resp = BmMtuChangedResponse(remoteId: r.remoteId, mtu: 23); + _methodStream.add(MethodCall("OnMtuChanged", resp.toMap())); } // clear mtu @@ -468,84 +503,88 @@ class FlutterBluePlus { } } } - - if (_delayedSubscriptions.isNotEmpty) { - if (r.connectionState == BmConnectionStateEnum.disconnected) { - var remoteId = r.remoteId; - // use delayed to update the stream before we cancel it - await Future.delayed(Duration.zero).then((_) { - _delayedSubscriptions[remoteId]?.forEach((s) => s.cancel()); // cancel - _delayedSubscriptions.remove(remoteId); // delete - }); - } - } - }); + } // keep track of device name - FlutterBluePlusPlatform.instance.onNameChanged.log('OnNameChanged', (r) => r.toMap()).listen((r) { + if (call.method == "OnNameChanged") { + var device = BmNameChanged.fromMap(call.arguments); if (Platform.isMacOS || Platform.isIOS) { // iOS & macOS internally use the name changed callback for the platform name - _platformNames[r.remoteId] = r.name; + _platformNames[device.remoteId] = device.name; } - }); + } // keep track of services resets - FlutterBluePlusPlatform.instance.onServicesReset.log('OnServicesReset', (r) => r.toMap()).listen((r) { + if (call.method == "OnServicesReset") { + var r = BmBluetoothDevice.fromMap(call.arguments); _knownServices.remove(r.remoteId); - }); + } // keep track of bond state - FlutterBluePlusPlatform.instance.onBondStateChanged.log('OnBondStateChanged', (r) => r.toMap()).listen((r) { + if (call.method == "OnBondStateChanged") { + var r = BmBondStateResponse.fromMap(call.arguments); _bondStates[r.remoteId] = r; - }); + } // keep track of services - FlutterBluePlusPlatform.instance.onDiscoveredServices.log('OnDiscoveredServices', (r) => r.toMap()).listen((r) { + if (call.method == "OnDiscoveredServices") { + var r = BmDiscoverServicesResult.fromMap(call.arguments); if (r.success == true) { _knownServices[r.remoteId] = r; } - }); + } // keep track of mtu values - FlutterBluePlusPlatform.instance.onMtuChanged.log('OnMtuChanged', (r) => r.toMap()).listen((r) { + if (call.method == "OnMtuChanged") { + var r = BmMtuChangedResponse.fromMap(call.arguments); if (r.success == true) { _mtuValues[r.remoteId] = r; } - }); + } // keep track of characteristic values - _mergeStreams([FlutterBluePlusPlatform.instance.onCharacteristicReceived.log('OnCharacteristicReceived', (r) => r.toMap()), FlutterBluePlusPlatform.instance.onCharacteristicWritten.log('OnCharacteristicWritten', (r) => r.toMap())]).listen((r) { + if (call.method == "OnCharacteristicReceived" || call.method == "OnCharacteristicWritten") { + var r = BmCharacteristicData.fromMap(call.arguments); if (r.success == true) { _lastChrs[r.remoteId] ??= {}; _lastChrs[r.remoteId]!["${r.serviceUuid}:${r.characteristicUuid}"] = r.value; } - }); + } // keep track of descriptor values - _mergeStreams([FlutterBluePlusPlatform.instance.onDescriptorRead.log('OnDescriptorRead', (r) => r.toMap()), FlutterBluePlusPlatform.instance.onDescriptorWritten.log('OnDescriptorWritten', (r) => r.toMap())]).listen((r) { + if (call.method == "OnDescriptorRead" || call.method == "OnDescriptorWritten") { + var r = BmDescriptorData.fromMap(call.arguments); if (r.success == true) { _lastDescs[r.remoteId] ??= {}; _lastDescs[r.remoteId]!["${r.serviceUuid}:${r.characteristicUuid}:${r.descriptorUuid}"] = r.value; } - }); + } - // flutter restart - wait for all devices to disconnect - if ((await _invokeMethod(() => FlutterBluePlusPlatform.instance.flutterRestart(), 'flutterRestart')) != 0) { - await Future.delayed(Duration(milliseconds: 50)); - while ((await _invokeMethod(() => FlutterBluePlusPlatform.instance.connectedCount(), 'connectedCount')) != 0) { - await Future.delayed(Duration(milliseconds: 50)); + _methodStream.add(call); + + // cancel delayed subscriptions + if (call.method == "OnConnectionStateChanged") { + if (_delayedSubscriptions.isNotEmpty) { + var r = BmConnectionStateResponse.fromMap(call.arguments); + if (r.connectionState == BmConnectionStateEnum.disconnected) { + var remoteId = r.remoteId; + // use delayed to update the stream before we cancel it + Future.delayed(Duration.zero).then((_) { + _delayedSubscriptions[remoteId]?.forEach((s) => s.cancel()); // cancel + _delayedSubscriptions.remove(remoteId); // delete + }); + } } } } /// invoke a platform method - static Future _invokeMethod( - Future Function() invoke, + static Future _invokeMethod( String method, [ dynamic arguments, ]) async { // return value - T out; + dynamic out; // only allow 1 invocation at a time (guarantees that hot restart finishes) _Mutex mtx = _MutexFactory.getMutexForKey("invokeMethod"); @@ -567,7 +606,7 @@ class FlutterBluePlus { } // invoke - out = await invoke(); + out = await _methodChannel.invokeMethod(method, arguments); // log result if (logLevel == LogLevel.verbose) { @@ -593,7 +632,7 @@ class FlutterBluePlus { Future futureResponse = responseStream.first; // invoke - await _invokeMethod(() => FlutterBluePlusPlatform.instance.turnOff(), 'turnOff'); + await _invokeMethod('turnOff'); // wait for response await futureResponse.fbpTimeout(timeout, "turnOff"); @@ -622,6 +661,16 @@ class FlutterBluePlus { static Stream scan() => throw Exception; } +/// Log levels for FlutterBlue +enum LogLevel { + none, //0 + error, // 1 + warning, // 2 + info, // 3 + debug, // 4 + verbose, //5 +} + class AndroidScanMode { const AndroidScanMode(this.value); static const lowPower = AndroidScanMode(0); @@ -671,6 +720,23 @@ class ServiceDataFilter { } } +class DeviceIdentifier { + final String str; + const DeviceIdentifier(this.str); + + @override + String toString() => str; + + @override + int get hashCode => str.hashCode; + + @override + bool operator ==(other) => other is DeviceIdentifier && _compareAsciiLowerCase(str, other.str) == 0; + + @Deprecated('Use str instead') + String get id => str; +} + class ScanResult { final BluetoothDevice device; final AdvertisementData advertisementData; @@ -762,6 +828,23 @@ class AdvertisementData { String get localName => advName; } +class PhySupport { + /// High speed (PHY 2M) + final bool le2M; + + /// Long range (PHY codec) + final bool leCoded; + + PhySupport({required this.le2M, required this.leCoded}); + + factory PhySupport.fromMap(Map json) { + return PhySupport( + le2M: json['le_2M'], + leCoded: json['le_coded'], + ); + } +} + enum ErrorPlatform { fbp, android, diff --git a/lib/src/guid.dart b/lib/src/guid.dart new file mode 100644 index 00000000..5bad07b7 --- /dev/null +++ b/lib/src/guid.dart @@ -0,0 +1,92 @@ +// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. +// All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +part of flutter_blue_plus; + +// Supports 16-bit, 32-bit, or 128-bit UUIDs +class Guid { + final List bytes; + + Guid.empty() : bytes = List.filled(16, 0); + + Guid.fromBytes(this.bytes) : assert(_checkLen(bytes.length), 'GUID must be 16, 32, or 128 bit.'); + + Guid.fromString(String input) : bytes = _fromString(input); + + Guid(String input) : bytes = _fromString(input); + + static List _fromString(String input) { + if (input.isEmpty) { + return List.filled(16, 0); + } + + input = input.replaceAll('-', ''); + + List? bytes = _tryHexDecode(input); + if (bytes == null) { + throw FormatException("GUID not hex format: $input"); + } + + _checkLen(bytes.length); + + return bytes; + } + + static bool _checkLen(int len) { + if (!(len == 16 || len == 4 || len == 2)) { + throw FormatException("GUID must be 16, 32, or 128 bit, yours: ${len * 8}-bit"); + } + return true; + } + + // 128-bit representation + String get str128 { + if (bytes.length == 2) { + // 16-bit uuid + return '0000${_hexEncode(bytes)}-0000-1000-8000-00805f9b34fb'.toLowerCase(); + } + if (bytes.length == 4) { + // 32-bit uuid + return '${_hexEncode(bytes)}-0000-1000-8000-00805f9b34fb'.toLowerCase(); + } + // 128-bit uuid + String one = _hexEncode(bytes.sublist(0, 4)); + String two = _hexEncode(bytes.sublist(4, 6)); + String three = _hexEncode(bytes.sublist(6, 8)); + String four = _hexEncode(bytes.sublist(8, 10)); + String five = _hexEncode(bytes.sublist(10, 16)); + return "$one-$two-$three-$four-$five".toLowerCase(); + } + + // shortest representation + String get str { + bool starts = str128.startsWith('0000'); + bool ends = str128.contains('-0000-1000-8000-00805f9b34fb'); + if (starts && ends) { + // 16-bit + return str128.substring(4, 8); + } + if (ends) { + // 32-bit + return str128.substring(0, 8); + } + // 128-bit + return str128; + } + + @override + String toString() => str; + + @override + operator ==(other) => other is Guid && hashCode == other.hashCode; + + @override + int get hashCode => str128.hashCode; + + @Deprecated('use str128 instead') + String get uuid128 => str128; + + @Deprecated('use str instead') + String get uuid => str; +} diff --git a/packages/flutter_blue_plus/lib/src/utils.dart b/lib/src/utils.dart similarity index 87% rename from packages/flutter_blue_plus/lib/src/utils.dart rename to lib/src/utils.dart index 8c0f8da3..f9202d9a 100644 --- a/packages/flutter_blue_plus/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -1,9 +1,58 @@ -// Copyright 2017-2024, Charles Weinberger, Paul DeMarco, Thomas Clark. -// All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - part of flutter_blue_plus; +String _hexEncode(List numbers) { + return numbers.map((n) => (n & 0xFF).toRadixString(16).padLeft(2, '0')).join(); +} + +List? _tryHexDecode(String hex) { + List numbers = []; + for (int i = 0; i < hex.length; i += 2) { + String hexPart = hex.substring(i, i + 2); + int? num = int.tryParse(hexPart, radix: 16); + if (num == null) { + return null; + } + numbers.add(num); + } + return numbers; +} + +List _hexDecode(String hex) { + List numbers = []; + for (int i = 0; i < hex.length; i += 2) { + String hexPart = hex.substring(i, i + 2); + int num = int.parse(hexPart, radix: 16); + numbers.add(num); + } + return numbers; +} + +int _compareAsciiLowerCase(String a, String b) { + const int upperCaseA = 0x41; + const int upperCaseZ = 0x5a; + const int asciiCaseBit = 0x20; + var defaultResult = 0; + for (var i = 0; i < a.length; i++) { + if (i >= b.length) return 1; + var aChar = a.codeUnitAt(i); + var bChar = b.codeUnitAt(i); + if (aChar == bChar) continue; + var aLowerCase = aChar; + var bLowerCase = bChar; + // Upper case if ASCII letters. + if (upperCaseA <= bChar && bChar <= upperCaseZ) { + bLowerCase += asciiCaseBit; + } + if (upperCaseA <= aChar && aChar <= upperCaseZ) { + aLowerCase += asciiCaseBit; + } + if (aLowerCase != bLowerCase) return (aLowerCase - bLowerCase).sign; + if (defaultResult == 0) defaultResult = aChar - bChar; + } + if (b.length > a.length) return -1; + return defaultResult.sign; +} + extension AddOrUpdate on List { /// add an item to a list, or update item if it already exists void addOrUpdate(T item) { @@ -300,26 +349,6 @@ extension _StreamNewStreamWithInitialValue on Stream { } } -extension _StreamLog on Stream { - Stream log(String method, [dynamic Function(T event)? arguments]) { - return transform( - StreamTransformer.fromHandlers( - handleData: (data, sink) { - if (FlutterBluePlus._logLevel == LogLevel.verbose) { - String func = '[[ ${method} ]]'; - String? result = arguments?.call(data)?.toString(); - func = FlutterBluePlus._logColor ? _black(func) : func; - result = result != null && FlutterBluePlus._logColor ? _brown(result) : result; - print("[FBP] $func result: $result"); - } - - sink.add(data); - }, - ), - ); - } -} - // ignore: unused_element Stream _mergeStreams(List> streams) { StreamController controller = StreamController(); diff --git a/packages/flutter_blue_plus/.gitignore b/packages/flutter_blue_plus/.gitignore deleted file mode 100644 index ac5aa989..00000000 --- a/packages/flutter_blue_plus/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ -migrate_working_dir/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. -/pubspec.lock -**/doc/api/ -.dart_tool/ -build/ diff --git a/packages/flutter_blue_plus/.metadata b/packages/flutter_blue_plus/.metadata deleted file mode 100644 index 3bb479b8..00000000 --- a/packages/flutter_blue_plus/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" - channel: "beta" - -project_type: package diff --git a/packages/flutter_blue_plus/LICENSE b/packages/flutter_blue_plus/LICENSE deleted file mode 100644 index 5341ca7c..00000000 --- a/packages/flutter_blue_plus/LICENSE +++ /dev/null @@ -1,28 +0,0 @@ -Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger, Thomas Clark. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Buffalo PC Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus/README.md b/packages/flutter_blue_plus/README.md deleted file mode 100644 index deb42558..00000000 --- a/packages/flutter_blue_plus/README.md +++ /dev/null @@ -1,1142 +0,0 @@ -[![pub package](https://img.shields.io/pub/v/flutter_blue_plus.svg)](https://pub.dartlang.org/packages/flutter_blue_plus) -[![Chat](https://img.shields.io/discord/634853295160033301.svg?style=flat-square&colorB=758ED3)](https://discord.gg/Yk5Efra) - -
-

-FlutterBlue -

-

- -**Note: this plugin is continuous work from [FlutterBlue](https://github.com/pauldemarco/flutter_blue).** - -Migrating from [FlutterBlue](https://github.com/pauldemarco/flutter_blue)? See [Migration Guide](MIGRATION.md) - -## Contents - -- [Introduction](#introduction) -- [Usage](#usage) -- [Getting Started](#getting-started) -- [Using Ble in App Background](#using-ble-in-app-background) -- [Reference](#reference) -- [Debugging](#debugging) -- [Mocking](#mocking) -- [Common Problems](#common-problems) - -## Introduction - -FlutterBluePlus is a Bluetooth Low Energy plugin for [Flutter](https://flutter.dev). - -It supports BLE Central Role only (most common). - -If you need BLE Peripheral Role, you should check out [FlutterBlePeripheral](https://pub.dev/packages/flutter_ble_peripheral). - -## Tutorial - -If you are new to Bluetooth, you should start by reading BLE tutorials. -* [Novel Bits BLE Tutorial](https://novelbits.io/bluetooth-low-energy-ble-complete-guide/) -* [All About Circuits BLE Tutorial](https://www.allaboutcircuits.com/technical-articles/exploring-the-basics-of-bluetooth-low-energy-a-beginners-guide-to-ble/) -* [Embetronicx BLE Tutorial](https://embetronicx.com/tutorials/tech_devices/bluetooth-low-energy-ble-introduction-part-1/) - -## ❗ Bluetooth Classic is not supported ❗ - - i.e. **Arduino HC-05 & HC-06,** speakers, headphones, mice, keyboards, gamepads, and more are **not** supported. These all use Bluetooth Classic. - - Also, iBeacons are **_not_** supported on iOS. Apple requires you to use CoreLocation. - -## Cross-Platform Bluetooth Low Energy - -FlutterBluePlus supports nearly every feature on all supported platforms: iOS, macOS, Android. - -FlutterBluePlus was written to be simple, robust, and easy to understand. - -## No Dependencies - -FlutterBluePlus has zero dependencies besides Flutter, Android, iOS, and macOS themselves. - -This makes FlutterBluePlus very stable, and easy to maintain. - -## Other BLE Libraries - -These other libraries are worth considering. They support all platforms, but fewer features. - -- [bluetooth_low_energy](https://pub.dev/packages/bluetooth_low_energy) -- [universal_ble](https://pub.dev/packages/universal_ble) -- [quick_blue](https://pub.dev/packages/quick_blue) - -## ⭐ Stars ⭐ - -Please star this repo & on [pub.dev](https://pub.dev/packages/flutter_blue_plus). We all benefit from having a larger community. - -## Discord 💬 - -[![Chat](https://img.shields.io/discord/634853295160033301.svg?style=flat-square&colorB=758ED3)](https://discord.gg/Yk5Efra) There is a community Discord server. ([Link](https://discord.gg/Yk5Efra)) - -## Example - -FlutterBluePlus has a beautiful example app, useful to debug issues. - -``` -cd ./example -flutter run -``` - -

-FlutterBlue -

- -## Usage - -### 🔥 Error Handling 🔥 - -Flutter Blue Plus takes error handling seriously. - -Every error returned by the native platform is checked and thrown as an exception where appropriate. See [Reference](#reference) for a list of throwable functions. - -**Streams:** Streams returned by FlutterBluePlus never emit any errors and never close. There's no need to handle `onError` or `onDone` for `stream.listen(...)`. The one exception is `FlutterBluePlus.scanResults`, which you should handle `onError`. - ---- - -### Set Log Level - -```dart -// if your terminal doesn't support color you'll see annoying logs like `\x1B[1;35m` -FlutterBluePlus.setLogLevel(LogLevel.verbose, color:false) -``` - -Setting `LogLevel.verbose` shows *all* data in and out. - -⚫ = function name - -🟣 = args to platform - -🟡 = data from platform - -Screenshot 2023-07-27 at 4 53 08 AM - - -### Bluetooth On & Off - -**Note:** On iOS, a "*This app would like to use Bluetooth*" system dialogue appears on first call to any FlutterBluePlus method. - -```dart -// first, check if bluetooth is supported by your hardware -// Note: The platform is initialized on the first call to any FlutterBluePlus method. -if (await FlutterBluePlus.isSupported == false) { - print("Bluetooth not supported by this device"); - return; -} - -// handle bluetooth on & off -// note: for iOS the initial state is typically BluetoothAdapterState.unknown -// note: if you have permissions issues you will get stuck at BluetoothAdapterState.unauthorized -var subscription = FlutterBluePlus.adapterState.listen((BluetoothAdapterState state) { - print(state); - if (state == BluetoothAdapterState.on) { - // usually start scanning, connecting, etc - } else { - // show an error to the user, etc - } -}); - -// turn on bluetooth ourself if we can -// for iOS, the user controls bluetooth enable/disable -if (Platform.isAndroid) { - await FlutterBluePlus.turnOn(); -} - -// cancel to prevent duplicate listeners -subscription.cancel(); -``` - -### Scan for devices - -If your device is not found, see [Common Problems](#common-problems). - -**Note:** It is recommended to set scan filters to reduce main thread & platform channel usage. - -```dart -// listen to scan results -// Note: `onScanResults` only returns live scan results, i.e. during scanning. Use -// `scanResults` if you want live scan results *or* the results from a previous scan. -var subscription = FlutterBluePlus.onScanResults.listen((results) { - if (results.isNotEmpty) { - ScanResult r = results.last; // the most recently found device - print('${r.device.remoteId}: "${r.advertisementData.advName}" found!'); - } - }, - onError: (e) => print(e), -); - -// cleanup: cancel subscription when scanning stops -FlutterBluePlus.cancelWhenScanComplete(subscription); - -// Wait for Bluetooth enabled & permission granted -// In your real app you should use `FlutterBluePlus.adapterState.listen` to handle all states -await FlutterBluePlus.adapterState.where((val) => val == BluetoothAdapterState.on).first; - -// Start scanning w/ timeout -// Optional: use `stopScan()` as an alternative to timeout -await FlutterBluePlus.startScan( - withServices:[Guid("180D")], // match any of the specified services - withNames:["Bluno"], // *or* any of the specified names - timeout: Duration(seconds:15)); - -// wait for scanning to stop -await FlutterBluePlus.isScanning.where((val) => val == false).first; -``` - -### Connect to a device - -```dart -// listen for disconnection -var subscription = device.connectionState.listen((BluetoothConnectionState state) async { - if (state == BluetoothConnectionState.disconnected) { - // 1. typically, start a periodic timer that tries to - // reconnect, or just call connect() again right now - // 2. you must always re-discover services after disconnection! - print("${device.disconnectReason?.code} ${device.disconnectReason?.description}"); - } -}); - -// cleanup: cancel subscription when disconnected -// - [delayed] This option is only meant for `connectionState` subscriptions. -// When `true`, we cancel after a small delay. This ensures the `connectionState` -// listener receives the `disconnected` event. -// - [next] if true, the the stream will be canceled only on the *next* disconnection, -// not the current disconnection. This is useful if you setup your subscriptions -// before you connect. -device.cancelWhenDisconnected(subscription, delayed:true, next:true); - -// Connect to the device -await device.connect(); - -// Disconnect from device -await device.disconnect(); - -// cancel to prevent duplicate listeners -subscription.cancel(); -``` - -### Auto Connect - -Connects whenever your device is found. - -```dart -// enable auto connect -// - note: autoConnect is incompatible with mtu argument, so you must call requestMtu yourself -await device.connect(autoConnect:true, mtu:null) - -// wait until connection -// - when using autoConnect, connect() always returns immediately, so we must -// explicity listen to `device.connectionState` to know when connection occurs -await device.connectionState.where((val) => val == BluetoothConnectionState.connected).first; - -// disable auto connect -await device.disconnect() -``` - -### Save Device - -To save a device between app restarts, just write the `remoteId` to a file. - -Now you can connect without needing to scan again, like so: - -```dart -final String remoteId = await File('/remoteId.txt').readAsString(); -var device = BluetoothDevice.fromId(remoteId); -// AutoConnect is convenient because it does not "time out" -// even if the device is not available / turned off. -await device.connect(autoConnect: true); - -``` - - -### MTU - -On Android, we request an mtu of 512 by default during connection (see: `connect` function arguments). - -On iOS & macOS, the mtu is negotiated automatically, typically 135 to 255. - -```dart -final subscription = device.mtu.listen((int mtu) { - // iOS: initial value is always 23, but iOS will quickly negotiate a higher value - print("mtu $mtu"); -}); - -// cleanup: cancel subscription when disconnected -device.cancelWhenDisconnected(subscription); - -// You can also manually change the mtu yourself. -if (Platform.isAndroid) { - await device.requestMtu(512); -} -``` - -### Discover services - -```dart -// Note: You must call discoverServices after every re-connection! -List services = await device.discoverServices(); -services.forEach((service) { - // do something with service -}); -``` - -### Read Characteristics - -```dart -// Reads all characteristics -var characteristics = service.characteristics; -for(BluetoothCharacteristic c in characteristics) { - if (c.properties.read) { - List value = await c.read(); - print(value); - } -} -``` - -### Write Characteristic - -```dart -// Writes to a characteristic -await c.write([0x12, 0x34]); -``` - -**allowLongWrite**: To write large characteristics (up to 512 bytes) regardless of mtu, use `allowLongWrite`: - -```dart -/// allowLongWrite should be used with caution. -/// 1. it can only be used *with* response to avoid data loss -/// 2. the peripheral device must support the 'long write' ble protocol. -/// 3. Interrupted transfers can leave the characteristic in a partially written state -/// 4. If the mtu is small, it is very very slow. -await c.write(data, allowLongWrite:true); -``` - -**splitWrite**: To write lots of data (unlimited), you can define the `splitWrite` function. - -```dart -import 'dart:math'; -// split write should be used with caution. -// 1. due to splitting, `characteristic.read()` will return partial data. -// 2. it can only be used *with* response to avoid data loss -// 3. The characteristic must be designed to support split data -extension splitWrite on BluetoothCharacteristic { - Future splitWrite(List value, {int timeout = 15}) async { - int chunk = device.mtuNow - 3; // 3 bytes ble overhead - for (int i = 0; i < value.length; i += chunk) { - List subvalue = value.sublist(i, min(i + chunk, value.length)); - await write(subvalue, withoutResponse:false, timeout: timeout); - } - } -} -``` - -### Subscribe to a characteristic - -If `onValueReceived` is never called, see [Common Problems](#common-problems) in the README. - -```dart -final subscription = characteristic.onValueReceived.listen((value) { - // onValueReceived is updated: - // - anytime read() is called - // - anytime a notification arrives (if subscribed) -}); - -// cleanup: cancel subscription when disconnected -device.cancelWhenDisconnected(subscription); - -// subscribe -// Note: If a characteristic supports both **notifications** and **indications**, -// it will default to **notifications**. This matches how CoreBluetooth works on iOS. -await characteristic.setNotifyValue(true); -``` - -### Last Value Stream - -`lastValueStream` is an alternative to `onValueReceived`. It emits a value any time the characteristic changes, **including writes.** - -It is very convenient for simple characteristics that support both WRITE and READ (and/or NOTIFY). **e.g.** a "light switch toggle" characteristic. - -```dart -final subscription = characteristic.lastValueStream.listen((value) { - // lastValueStream` is updated: - // - anytime read() is called - // - anytime write() is called - // - anytime a notification arrives (if subscribed) - // - also when first listened to, it re-emits the last value for convenience. -}); - -// cleanup: cancel subscription when disconnected -device.cancelWhenDisconnected(subscription); - -// enable notifications -await characteristic.setNotifyValue(true); -``` - -### Read and write descriptors - -```dart -// Reads all descriptors -var descriptors = characteristic.descriptors; -for(BluetoothDescriptor d in descriptors) { - List value = await d.read(); - print(value); -} - -// Writes to a descriptor -await d.write([0x12, 0x34]) -``` - -### Services Changed Characteristic - -FlutterBluePlus automatically listens to the Services Changed Characteristic (0x2A05) - -In FlutterBluePlus, we call it `onServicesReset` because you must re-discover services. - -```dart -// - uses the GAP Services Changed characteristic (0x2A05) -// - you must call discoverServices() again -device.onServicesReset.listen(() async { - print("Services Reset"); - await device.discoverServices(); -}); -``` - -### Get Connected Devices - -Get devices currently connected to your app. - -```dart -List devs = FlutterBluePlus.connectedDevices; -for (var d in devs) { - print(d); -} -``` - -### Get System Devices - -Get devices connected to the system by *any* app. - -**Note:** you must connect *your app* to them before you can communicate with them. - -```dart -List devs = await FlutterBluePlus.systemDevices; -for (var d in devs) { - await d.connect(); // Must connect *our* app to the device - await d.discoverServices(); -} -``` - -### Create Bond (Android Only) - -**Note:** calling this is usually not necessary!! The platform will do it automatically. - -However, you can force the popup to show sooner. - -```dart -final bsSubscription = device.bondState.listen((value) { - print("$value prev:{$device.prevBondState}"); -}); - -// cleanup: cancel subscription when disconnected -device.cancelWhenDisconnected(bsSubscription); - -// Force the bonding popup to show now (Android Only) -await device.createBond(); - -// remove bond -await device.removeBond(); -``` - -### Events API - -Access streams from all devices simultaneously. - -There are streams for: -* events.onConnectionStateChanged -* events.onMtuChanged -* events.onReadRssi -* events.onServicesReset -* events.onDiscoveredServices -* events.onCharacteristicReceived -* events.onCharacteristicWritten -* events.onDescriptorRead -* events.onDescriptorWritten -* events.onNameChanged (iOS Only) -* events.onBondStateChanged (Android Only) - -```dart -// listen to *any device* connection state changes -FlutterBluePlus.events.onConnectionStateChanged.listen((event)) { - print('${event.device} ${event.connectionState}'); -} -``` - -## Mocking - -To mock `FlutterBluePlus` for development, refer to the [Mocking Guide](MOCKING.md). - -## Getting Started - -### Change the minSdkVersion for Android - -flutter_blue_plus is compatible only from version 21 of Android SDK so you should change this in **android/app/build.gradle**: - -```dart -android { - defaultConfig { - minSdkVersion: 21 -``` - -### Add permissions for Android (No Location) - -In the **android/app/src/main/AndroidManifest.xml** add: - -```xml - - - - - - - - - - - - - - -``` - -### Add permissions for Android (With Fine Location) - -If you want to use Bluetooth to determine location, or support iBeacons. - -In the **android/app/src/main/AndroidManifest.xml** add: - -```xml - - - - - - - - - - - - - - -``` - -And set **androidUsesFineLocation** when scanning: -```dart -// Start scanning -flutterBlue.startScan(timeout: Duration(seconds: 4), androidUsesFineLocation: true); -``` - -### Android Proguard - -Add the following line in your `project/android/app/proguard-rules.pro` file: - -``` --keep class com.lib.flutter_blue_plus.* { *; } -``` - -to avoid seeing the following kind errors in your `release` builds: - -``` -PlatformException(startScan, Field androidScanMode_ for m0.e0 not found. Known fields are - [private int m0.e0.q, private b3.b0$i m0.e0.r, private boolean m0.e0.s, private static final m0.e0 m0.e0.t, - private static volatile b3.a1 m0.e0.u], java.lang.RuntimeException: Field androidScanMode_ for m0.e0 not found -``` - -### Add permissions for iOS - -In the **ios/Runner/Info.plist** let’s add: - -```dart - - NSBluetoothAlwaysUsageDescription - This app needs Bluetooth to function -``` - -For location permissions on iOS see more at: [https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services](https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services) - -### Add permissions for macOS - -Make sure you have granted access to the Bluetooth hardware: - -`Xcode -> Runners -> Targets -> Runner-> Signing & Capabilities -> App Sandbox -> Hardware -> Enable Bluetooth` - -Screenshot 2023-12-11 at 10 32 04 AM - -## Using Ble in App Background - -**This is an advanced use case**. FlutterBluePlus does not support everything. You may have to fork it. PRs are welcome. - -### iOS - -Documentation: https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html - -Add the following to your `Info.plist` - -``` -UIBackgroundModes - - bluetooth-central - -``` - -When this key-value pair is included in the app’s Info.plist file, the system wakes up your app to process ble `read`, `write`, and `subscription` events. - -You may also have to use https://pub.dev/packages/workmanager - -**Note**: Upon being woken up, an app has around 10 seconds to complete a task. Apps that spend too much time executing in the background can be throttled back by the system or killed. - -### Android - -You can try using https://pub.dev/packages/flutter_foreground_task or possibly https://pub.dev/packages/workmanager - -## Reference - -🌀 = Stream -⚡ = synchronous - -### FlutterBluePlus API - -| | Android | iOS | Throws | Description | -| :--------------------- | :----------------: | :----------------: | :----: | :----------------------------------------------------------| -| setLogLevel | :white_check_mark: | :white_check_mark: | | Configure plugin log level | -| setOptions | :white_check_mark: | :white_check_mark: | | Set configurable bluetooth options | -| isSupported | :white_check_mark: | :white_check_mark: | | Checks whether the device supports Bluetooth | -| turnOn | :white_check_mark: | | :fire: | Turns on the bluetooth adapter | -| adapterStateNow ⚡ | :white_check_mark: | :white_check_mark: | | Current state of the bluetooth adapter | -| adapterState 🌀 | :white_check_mark: | :white_check_mark: | | Stream of on & off states of the bluetooth adapter | -| startScan | :white_check_mark: | :white_check_mark: | :fire: | Starts a scan for Ble devices | -| stopScan | :white_check_mark: | :white_check_mark: | :fire: | Stop an existing scan for Ble devices | -| onScanResults 🌀 | :white_check_mark: | :white_check_mark: | | Stream of live scan results | -| scanResults 🌀 | :white_check_mark: | :white_check_mark: | | Stream of live scan results or previous results | -| lastScanResults ⚡ | :white_check_mark: | :white_check_mark: | | The most recent scan results | -| isScanning 🌀 | :white_check_mark: | :white_check_mark: | | Stream of current scanning state | -| isScanningNow ⚡ | :white_check_mark: | :white_check_mark: | | Is a scan currently running? | -| connectedDevices ⚡ | :white_check_mark: | :white_check_mark: | | List of devices connected to *your app* | -| systemDevices | :white_check_mark: | :white_check_mark: | :fire: | List of devices connected to the system, even by other apps| -| getPhySupport | :white_check_mark: | | :fire: | Get supported bluetooth phy codings | - -### FlutterBluePlus Events API - -| | Android | iOS | Throws | Description | -| :--------------------------------- | :----------------: | :----------------: | :----: | :-----------------------------------------------------| -| events.onConnectionStateChanged 🌀 | :white_check_mark: | :white_check_mark: | | Stream of connection changes of *all devices* | -| events.onMtuChanged 🌀 | :white_check_mark: | :white_check_mark: | | Stream of mtu changes of *all devices* | -| events.onReadRssi 🌀 | :white_check_mark: | :white_check_mark: | | Stream of rssi reads of *all devices* | -| events.onServicesReset 🌀 | :white_check_mark: | :white_check_mark: | | Stream of services resets of *all devices* | -| events.onDiscoveredServices 🌀 | :white_check_mark: | :white_check_mark: | | Stream of services discovered of *all devices* | -| events.onCharacteristicReceived 🌀 | :white_check_mark: | :white_check_mark: | | Stream of characteristic value reads of *all devices* | -| events.onCharacteristicWritten 🌀 | :white_check_mark: | :white_check_mark: | | Stream of characteristic value writes of *all devices*| -| events.onDescriptorRead 🌀 | :white_check_mark: | :white_check_mark: | | Stream of descriptor value reads of *all devices* | -| events.onDescriptorWritten 🌀 | :white_check_mark: | :white_check_mark: | | Stream of descriptor value writes of *all devices* | -| events.onBondStateChanged 🌀 | :white_check_mark: | | | Stream of android bond state changes of *all devices* | -| events.onNameChanged 🌀 | | :white_check_mark: | | Stream of iOS name changes of *all devices* | - - -### BluetoothDevice API - -| | Android | iOS | Throws | Description | -| :------------------------ | :----------------: | :----------------: | :----: | :----------------------------------------------------------| -| platformName ⚡ | :white_check_mark: | :white_check_mark: | | The platform preferred name of the device | -| advName ⚡ | :white_check_mark: | :white_check_mark: | | The advertised name of the device found during scanning | -| connect | :white_check_mark: | :white_check_mark: | :fire: | Establishes a connection to the device | -| disconnect | :white_check_mark: | :white_check_mark: | :fire: | Cancels an active or pending connection to the device | -| isConnected ⚡ | :white_check_mark: | :white_check_mark: | | Is this device currently connected to *your app*? | -| isDisonnected ⚡ | :white_check_mark: | :white_check_mark: | | Is this device currently disconnected from *your app*? | -| connectionState 🌀 | :white_check_mark: | :white_check_mark: | | Stream of connection changes for the Bluetooth Device | -| discoverServices | :white_check_mark: | :white_check_mark: | :fire: | Discover services | -| servicesList ⚡ | :white_check_mark: | :white_check_mark: | | The current list of available services | -| onServicesReset 🌀 | :white_check_mark: | :white_check_mark: | | The services changed & must be rediscovered | -| mtu 🌀 | :white_check_mark: | :white_check_mark: | | Stream of current mtu value + changes | -| mtuNow ⚡ | :white_check_mark: | :white_check_mark: | | The current mtu value | -| readRssi | :white_check_mark: | :white_check_mark: | :fire: | Read RSSI from a connected device | -| requestMtu | :white_check_mark: | | :fire: | Request to change the MTU for the device | -| requestConnectionPriority | :white_check_mark: | | :fire: | Request to update a high priority, low latency connection | -| bondState 🌀 | :white_check_mark: | | | Stream of device bond state. Can be useful on Android | -| createBond | :white_check_mark: | | :fire: | Force a system pairing dialogue to show, if needed | -| removeBond | :white_check_mark: | | :fire: | Remove Bluetooth Bond of device | -| setPreferredPhy | :white_check_mark: | | :fire: | Set preferred RX and TX phy for connection and phy options | -| clearGattCache | :white_check_mark: | | :fire: | Clear android cache of service discovery results | - -### BluetoothCharacteristic API - -| | Android | iOS | Throws | Description | -| :----------------- | :----------------: | :----------------: | :----: | :--------------------------------------------------------------| -| uuid ⚡ | :white_check_mark: | :white_check_mark: | | The uuid of characteristic | -| read | :white_check_mark: | :white_check_mark: | :fire: | Retrieves the value of the characteristic | -| write | :white_check_mark: | :white_check_mark: | :fire: | Writes the value of the characteristic | -| setNotifyValue | :white_check_mark: | :white_check_mark: | :fire: | Sets notifications or indications on the characteristic | -| isNotifying ⚡ | :white_check_mark: | :white_check_mark: | | Are notifications or indications currently enabled | -| onValueReceived 🌀 | :white_check_mark: | :white_check_mark: | | Stream of characteristic value updates received from the device| -| lastValue ⚡ | :white_check_mark: | :white_check_mark: | | The most recent value of the characteristic | -| lastValueStream 🌀 | :white_check_mark: | :white_check_mark: | | Stream of onValueReceived + writes | - -### BluetoothDescriptor API - -| | Android | iOS | Throws | Description | -| :---- | :----------------: | :----------------: | :----: | :----------------------------------------------| -| uuid ⚡ | :white_check_mark: | :white_check_mark: | | The uuid of descriptor | -| read | :white_check_mark: | :white_check_mark: | :fire: | Retrieves the value of the descriptor | -| write | :white_check_mark: | :white_check_mark: | :fire: | Writes the value of the descriptor | -| onValueReceived 🌀 | :white_check_mark: | :white_check_mark: | | Stream of descriptor value reads & writes | -| lastValue ⚡ | :white_check_mark: | :white_check_mark: | | The most recent value of the descriptor | -| lastValueStream 🌀 | :white_check_mark: | :white_check_mark: | | Stream of onValueReceived + writes | - -## Debugging - -The easiest way to debug issues in FlutterBluePlus is to make your own local copy. - -``` -cd /user/downloads -git clone https://github.com/boskokg/flutter_blue_plus.git -``` - -then in `pubspec.yaml` add the repo by path: - -``` - flutter_blue_plus: - path: /user/downloads/flutter_blue_plus -``` - -Now you can edit the FlutterBluePlus code yourself. - -## Common Problems - -Many common problems are easily solved. - -Adapter: -- [bluetooth must be turned on](#bluetooth-must-be-turned-on) -- [adapterState is not 'on' but my Bluetooth is on](#adapterstate-is-not-on-but-my-bluetooth-is-on) -- [adapterState is called multiple times](#adapterstate-is-called-multiple-times) - -Scanning: -- [Scanning does not find my device](#scanning-does-not-find-my-device) -- [Scanned device never goes away](#scanned-device-never-goes-away) -- [iBeacons not showing](#ibeacons-not-showing) - -Connecting: -- [Connection fails](#connection-fails) -- [connectionState is called multiple times](#connectionstate-is-called-multiple-times) -- [remoteId is different on Android vs iOS](#the-remoteid-is-different-on-android-versus-ios--macos) -- [iOS: "[Error] The connection has timed out unexpectedly."](#ios-error-the-connection-has-timed-out-unexpectedly) - -Reading & Writing: -- [List of Bluetooth GATT Errors](#list-of-bluetooth-gatt-errors) -- [Characteristic write fails](#characteristic-write-fails) -- [Characteristic read fails](#characteristic-read-fails) - -Subscriptions: -- [onValueReceived is never called (or lastValueStream)](#onvaluereceived-is-never-called-or-lastvaluestream) -- [onValueReceived data is split up (or lastValueStream)](#onvaluereceived-data-is-split-up-or-lastvaluestream) -- [onValueReceived is called with duplicate data (or lastValueStream)](#onvaluereceived-is-called-with-duplicate-data-or-lastvaluestream) - -Android Errors: -- [ANDROID_SPECIFIC_ERROR](#android_specific_error) -- [android pairing popup appears twice](#android-pairing-popup-appears-twice) - -Flutter Errors: -- [MissingPluginException(No implementation found for method XXXX ...)](#missingpluginexceptionno-implementation-found-for-method-xxxx-) - ---- - -### "bluetooth must be turned on" - -You need to wait for the bluetooth adapter to fully turn on. - -`await FlutterBluePlus.adapterState.where((state) => state == BluetoothAdapterState.on).first;` - -You can also use `FlutterBluePlus.adapterState.listen(...)`. See [Usage](#usage). - ---- - -### adapterState is not 'on' but my Bluetooth is on - -**For iOS:** - -`adapterState` always starts as `unknown`. You need to wait longer for the service to initialize. Use this code: - -``` -// wait for actual adapter state, up to 3 seconds -Set inProgress = {BluetoothAdapterState.unknown, BluetoothAdapterState.turningOn}; -var adapterState = FlutterBluePlus.adapterState.where((v) => !inProgress.contains(v)).first; -await adapterState.timeout(const Duration(seconds: 3)).onError((error, stackTrace) { - throw Exception("Could not determine Bluetooth state. ${FlutterBluePlus.adapterStateNow}"); -}); - -// check adapter state -if (FlutterBluePlus.adapterStateNow != BluetoothAdapterState.on) { - throw Exception("Bluetooth Is Not On. ${FlutterBluePlus.adapterStateNow}"); -} -``` - -If `adapterState` is `unavailable`, you must add access to Bluetooth Hardware in the app's Xcode settings. See [Getting Started](#getting-started). - -**For Android:** - -Check that your device supports Bluetooth & has permissions. - ---- - -### adapterState is called multiple times - -You are forgetting to cancel the original `FlutterBluePlus.adapterState.listen` resulting in multiple listeners. - -```dart -// tip: using ??= makes it easy to only make new listener when currently null -final subscription ??= FlutterBluePlus.adapterState.listen((value) { - // ... -}); - -// also, make sure you cancel the subscription when done! -subscription.cancel() -``` - ---- - -### Scanning does not find my device - -**1. you're using an emulator** - -Use a physical device. - -**2. try using another ble scanner app** - -* **iOS**: [nRF Connect](https://apps.apple.com/us/app/nrf-connect-for-mobile/id1054362403) -* **Android**: [BLE Scanner](https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner) - -Install a BLE scanner app on your phone. Can it find your device? - -**3. your device uses bluetooth classic, not BLE.** - -Headphones, speakers, keyboards, mice, gamepads, & printers all use Bluetooth Classic. - -These devices may be found in System Settings, but they cannot be connected to by FlutterBluePlus. FlutterBluePlus only supports Bluetooth Low Energy. - -**4. your device stopped advertising.** - -- you might need to reboot your device -- you might need to put your device in "discovery mode" -- your phone may have already connected automatically -- another app may have already connected to your device -- another phone may have already connected to your device - -Try looking through system devices: - -```dart -// search system devices. i.e. any device connected to by *any* app -List system = await FlutterBluePlus.systemDevices; -for (var d in system) { - print('${r.device.platformName} already connected to! ${r.device.remoteId}'); - if (d.platformName == "myBleDevice") { - await r.connect(); // must connect our app - } -} -``` - -**5. your scan filters are wrong.** - -- try removing all scan filters -- for `withServices` to work, your device must actively advertise the serviceUUIDs it supports - -**6. Android: you're calling startScan too often** - -On Adroid you can only call `startScan` 5 times per 30 second period. This is a platform restriction. - ---- - -### Scanned device never goes away - -This is expected. - -You must set the `removeIfGone` scan option if you want the device to go away when no longer available. - ---- - -### iBeacons Not Showing - -**iOS:** - -iOS does not support iBeacons using CoreBluetooth. You must find a plugin meant for CoreLocation. - -**Android:** - -1. you need to enable location permissions, see [Getting Started](#getting-started) -2. you must pass `androidUsesFineLocation:true` to the `startScan` method. - ---- - -### Connection fails - -**1. Your ble device may be low battery** - -Bluetooth can become erratic when your peripheral device is low on battery. - -**2. Your ble device may have refused the connection or have a bug** - -Connection is a two-way process. Your ble device may be misconfigured. - -**3. You may be on the edge of the Bluetooth range.** - -The signal is too weak, or there are a lot of devices causing radio interference. - -**4. Some phones have an issue connecting while scanning.** - -The Huawei P8 Lite is one of the reported phones to have this issue. Try stopping your scanner before connecting. - -**5. Try restarting your phone** - -Bluetooth is a complicated system service, and can enter a bad state. - ---- - -### connectionState is called multiple times - -You are forgetting to cancel the original `device.connectionState.listen` resulting in multiple listeners. - -```dart -// tip: using ??= makes it easy to only make new listener when currently null -final subscription ??= FlutterBluePlus.device.connectionState.listen((value) { - // ... -}); - -// also, make sure you cancel the subscription when done! -subscription.cancel() -``` - ---- - -### The remoteId is different on Android versus iOS & macOS - -This is expected. There is no way to avoid it. - -For privacy, iOS & macOS use a randomly generated uuid. This uuid will periodically change. - -e.g. `6920a902-ba0e-4a13-a35f-6bc91161c517` - -Android uses the mac address of the bluetooth device. It never changes. - -e.g. `05:A4:22:31:F7:ED` - ---- - -### iOS: "[Error] The connection has timed out unexpectedly." - -You can google this error. It is a common iOS ble error code. - -It means your device stopped working. FlutterBluePlus cannot fix it. - ---- - -### List of Bluetooth GATT Errors - -These GATT error codes are part of the BLE Specification. - -**These are *responses* from your ble device because you are sending an invalid request.** - -FlutterBluePlus cannot fix these errors. You are doing something wrong & your device is responding with an error. - -**GATT errors as they appear on iOS**: -``` -apple-code: 1 | The handle is invalid. -apple-code: 2 | Reading is not permitted. -apple-code: 3 | Writing is not permitted. -apple-code: 4 | The command is invalid. -apple-code: 6 | The request is not supported. -apple-code: 7 | The offset is invalid. -apple-code: 8 | Authorization is insufficient. -apple-code: 9 | The prepare queue is full. -apple-code: 10 | The attribute could not be found. -apple-code: 11 | The attribute is not long. -apple-code: 12 | The encryption key size is insufficient. -apple-code: 13 | The value's length is invalid. -apple-code: 14 | Unlikely error. -apple-code: 15 | Encryption is insufficient. -apple-code: 16 | The group type is unsupported. -apple-code: 17 | Resources are insufficient. -apple-code: 18 | Unknown ATT error. -``` - -**GATT errors as they appear on Android**: -``` -android-code: 1 | GATT_INVALID_HANDLE -android-code: 2 | GATT_READ_NOT_PERMITTED -android-code: 3 | GATT_WRITE_NOT_PERMITTED -android-code: 4 | GATT_INVALID_PDU -android-code: 5 | GATT_INSUFFICIENT_AUTHENTICATION -android-code: 6 | GATT_REQUEST_NOT_SUPPORTED -android-code: 7 | GATT_INVALID_OFFSET -android-code: 8 | GATT_INSUFFICIENT_AUTHORIZATION -android-code: 9 | GATT_PREPARE_QUEUE_FULL -android-code: 10 | GATT_ATTR_NOT_FOUND -android-code: 11 | GATT_ATTR_NOT_LONG -android-code: 12 | GATT_INSUFFICIENT_KEY_SIZE -android-code: 13 | GATT_INVALID_ATTRIBUTE_LENGTH -android-code: 14 | GATT_UNLIKELY -android-code: 15 | GATT_INSUFFICIENT_ENCRYPTION -android-code: 16 | GATT_UNSUPPORTED_GROUP -android-code: 17 | GATT_INSUFFICIENT_RESOURCES -``` - -**Descriptions**: -``` -1 | Invalid Handle | The attribute handle given was not valid on this server. -2 | Read Not Permitted | The attribute cannot be read. -3 | Write Not Permitted | The attribute cannot be written. -4 | Invalid PDU | The attribute PDU was invalid. -5 | Insufficient Authentication | The attribute requires authentication before it can be read or written. -6 | Request Not Supported | Attribute server does not support the request received from the client. -7 | Invalid Offset | Offset specified was past the end of the attribute. -8 | Insufficient Authorization | The attribute requires an authorization before it can be read or written. -9 | Prepare Queue Full | Too many prepare writes have been queued. -10 | Attribute Not Found | No attribute found within the given attribute handle range. -11 | Attribute Not Long | The attribute cannot be read or written using the Read Blob or Write Blob requests. -12 | Insufficient Key Size | The Encryption Key Size used for encrypting this link is insufficient. -13 | Invalid Attribute Value Length | The attribute value length is invalid for the operation. -14 | Unlikely Error | The request has encountered an unlikely error and cannot be completed. -15 | Insufficient Encryption | The attribute requires encryption before it can be read or written. -16 | Unsupported Group Type | The attribute type is not a supported grouping as defined by a higher layer. -17 | Insufficient Resources | Insufficient Resources to complete the request. -``` - ---- - -### characteristic write fails - -First, check the [List of Bluetooth GATT Errors](#list-of-bluetooth-gatt-errors) for your error. - -**1. your bluetooth device turned off, or is out of range** - -If your device turns off or crashes during a write, it will cause a failure. - -**2. Your Bluetooth device has bugs** - -Maybe your device crashed, or is not sending a response due to software bugs. - -**3. there is radio interference** - -Bluetooth is wireless and will not always work. - ---- - -### Characteristic read fails - -First, check the [List of Bluetooth GATT Errors](#list-of-bluetooth-gatt-errors) for your error. - -**1. your bluetooth device turned off, or is out of range** - -If your device turns off or crashes during a read, it will cause a failure. - -**2. Your Bluetooth device has bugs** - -Maybe your device crashed, or is not sending a response due to software bugs. - -**3. there is radio interference** - -Bluetooth is wireless and will not always work. - ---- - -### onValueReceived is never called (or lastValueStream) - -**1. you are not calling the right function** - -`lastValueStream` is called for `await chr.read()` & `await chr.write()` & `await chr.setNotifyValue(true)` - -`onValueReceived` is only called for `await chr.read()` & `await chr.setNotifyValue(true)` - -**2. your device has nothing to send** - -If you are using `await chr.setNotifyValue(true)`, your _device_ chooses when to send data. - -Try interacting with your device to get it to send new data. - -**3. your device has bugs** - -Try rebooting your ble device. - -Some ble devices have buggy software and stop sending data - ---- - -### onValueReceived data is split up (or lastValueStream) - -Verify that the mtu is large enough to hold your message. - -```dart -device.mtu -``` - -If it still happens, it is a problem with your peripheral device. - ---- - -### onValueReceived is called with duplicate data (or lastValueStream) - -You are probably forgetting to cancel the original `chr.onValueReceived.listen` resulting in multiple listens. - -The easiest solution is to use `device.cancelWhenDisconnected(subscription)` to cancel device subscriptions. - -```dart -final subscription = chr.onValueReceived.listen((value) { - // ... -}); - -// make sure you have this line! -device.cancelWhenDisconnected(subscription); - -await characteristic.setNotifyValue(true); -``` - ---- - -### ANDROID_SPECIFIC_ERROR - -There is no 100% solution. - -FBP already has mitigations for this error, but Android will still fail with this code randomly. - -The recommended solution is to `catch` the error, and retry. - ---- - -### android pairing popup appears twice - -This is a bug in android itself. - -You can call `createBond()` yourself just after connecting and this will resolve the issue. - ---- - -### MissingPluginException(No implementation found for method XXXX ...) - -If you just added flutter_blue_plus to your pubspec.yaml, a hot reload / hot restart is not enough. - -You need to fully stop your app and run again so that the native plugins are loaded. - -Also try `flutter clean`. - - - - - - - - - - diff --git a/packages/flutter_blue_plus/analysis_options.yaml b/packages/flutter_blue_plus/analysis_options.yaml deleted file mode 100644 index f9b30346..00000000 --- a/packages/flutter_blue_plus/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus/example/pubspec.lock b/packages/flutter_blue_plus/example/pubspec.lock deleted file mode 100644 index fb57eafd..00000000 --- a/packages/flutter_blue_plus/example/pubspec.lock +++ /dev/null @@ -1,107 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - characters: - dependency: transitive - description: - name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - collection: - dependency: transitive - description: - name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" - convert: - dependency: transitive - description: - name: convert - sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" - url: "https://pub.dev" - source: hosted - version: "3.1.1" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_blue_plus: - dependency: "direct main" - description: - path: ".." - relative: true - source: path - version: "1.33.0" - flutter_blue_plus_android: - dependency: "direct overridden" - description: - path: "../../flutter_blue_plus_android" - relative: true - source: path - version: "1.33.0" - flutter_blue_plus_darwin: - dependency: "direct overridden" - description: - path: "../../flutter_blue_plus_darwin" - relative: true - source: path - version: "1.33.0" - flutter_blue_plus_platform_interface: - dependency: "direct overridden" - description: - path: "../../flutter_blue_plus_platform_interface" - relative: true - source: path - version: "1.0.0" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec - url: "https://pub.dev" - source: hosted - version: "0.11.1" - meta: - dependency: transitive - description: - name: meta - sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 - url: "https://pub.dev" - source: hosted - version: "1.15.0" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" - url: "https://pub.dev" - source: hosted - version: "2.1.8" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - typed_data: - dependency: transitive - description: - name: typed_data - sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c - url: "https://pub.dev" - source: hosted - version: "1.3.2" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" -sdks: - dart: ">=3.3.0-0 <4.0.0" diff --git a/packages/flutter_blue_plus/example/pubspec.yaml b/packages/flutter_blue_plus/example/pubspec.yaml deleted file mode 100644 index c599d728..00000000 --- a/packages/flutter_blue_plus/example/pubspec.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: flutter_blue_plus_example -description: Demonstrates how to use the flutter_blue_plus plugin. - -# The following line prevents the package from being accidentally published to -# pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' - -environment: - sdk: ">=2.15.1 <3.0.0" - -dependencies: - flutter: - sdk: flutter - flutter_blue_plus: ^1.33.0 - -# Note: We use path dependency overrides because the example app & plugin are bundled together. -# In *your* app you should omit this dependency overrides section. -dependency_overrides: - flutter_blue_plus: - path: ../ - flutter_blue_plus_android: - path: ../../flutter_blue_plus_android - flutter_blue_plus_darwin: - path: ../../flutter_blue_plus_darwin - flutter_blue_plus_platform_interface: - path: ../../flutter_blue_plus_platform_interface - -flutter: - uses-material-design: true diff --git a/packages/flutter_blue_plus/pubspec.yaml b/packages/flutter_blue_plus/pubspec.yaml deleted file mode 100644 index 4758aa4c..00000000 --- a/packages/flutter_blue_plus/pubspec.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: flutter_blue_plus -description: Flutter plugin for connecting and communicating with Bluetooth Low Energy devices. -version: 1.33.0 -homepage: https://github.com/boskokg/flutter_blue_plus - -environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=2.0.0" - -dependencies: - flutter: - sdk: flutter - flutter_blue_plus_android: ^1.33.0 - flutter_blue_plus_darwin: ^1.33.0 - flutter_blue_plus_platform_interface: ^1.0.0 - -dev_dependencies: - flutter_lints: ^4.0.0 - flutter_test: - sdk: flutter - -dependency_overrides: - flutter_blue_plus_android: - path: ../flutter_blue_plus_android - flutter_blue_plus_darwin: - path: ../flutter_blue_plus_darwin - flutter_blue_plus_platform_interface: - path: ../flutter_blue_plus_platform_interface - -flutter: - plugin: - platforms: - android: - default_package: flutter_blue_plus_android - ios: - default_package: flutter_blue_plus_darwin - macos: - default_package: flutter_blue_plus_darwin diff --git a/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java b/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java index 5020882a..f417f2cc 100644 --- a/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java +++ b/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java @@ -280,7 +280,7 @@ public void onDetachedFromActivity() // ██████ ██ ██ ███████ ███████ @Override - @SuppressWarnings({"deprecation", "unchecked"}) // needed for compatibility, type safety uses flutter_blue_plus_platform_interface + @SuppressWarnings({"deprecation", "unchecked"}) // needed for compatibility, type safety uses bluetooth_msgs.dart public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { @@ -2021,7 +2021,7 @@ private ScanCallback getScanCallback() scanCallback = new ScanCallback() { @Override - @SuppressWarnings("unchecked") // type safety uses flutter_blue_plus_platform_interface + @SuppressWarnings("unchecked") // type safety uses bluetooth_msgs.dart public void onScanResult(int callbackType, ScanResult result) { log(LogLevel.VERBOSE, "onScanResult"); From 961325c2330b5792b4ca13b026156bad4fc58432 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:45 +0100 Subject: [PATCH 61/90] Revert "test: update method channel implementation" This reverts commit 044fa0f81cf9e7ba6a6baccbea8be71c6f62e4ad. --- .../src/method_channel_flutter_blue_plus.dart | 191 ++-- .../lib/src/scan/models/bm_scan_response.dart | 4 +- ...method_channel_flutter_blue_plus_test.dart | 887 +----------------- 3 files changed, 129 insertions(+), 953 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index 42c1dc71..0949c4af 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -40,140 +40,146 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { final _calls = StreamController.broadcast(); MethodChannelFlutterBluePlus() { - channel.setMethodCallHandler(handleMethodCall); + channel.setMethodCallHandler( + (call) async { + _calls.add(call); + }, + ); } @override - Stream get onAdapterStateChanged { - return _calls.stream.where((call) { - return call.method == 'OnAdapterStateChanged'; - }).map((call) { - return BmBluetoothAdapterState.fromMap(call.arguments); - }); + Stream get onAdapterStateChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnAdapterStateChanged') { + yield BmBluetoothAdapterState.fromMap(call.arguments); + } + } } @override - Stream get onBondStateChanged { - return _calls.stream.where((call) { - return call.method == 'OnBondStateChanged'; - }).map((call) { - return BmBondStateResponse.fromMap(call.arguments); - }); + Stream get onBondStateChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnBondStateChanged') { + yield BmBondStateResponse.fromMap(call.arguments); + } + } } @override - Stream get onCharacteristicReceived { - return _calls.stream.where((call) { - return call.method == 'OnCharacteristicReceived'; - }).map((call) { - return BmCharacteristicData.fromMap(call.arguments); - }); + Stream get onCharacteristicReceived async* { + await for (final call in _calls.stream) { + if (call.method == 'OnCharacteristicReceived') { + yield BmCharacteristicData.fromMap(call.arguments); + } + } } @override - Stream get onCharacteristicWritten { - return _calls.stream.where((call) { - return call.method == 'OnCharacteristicWritten'; - }).map((call) { - return BmCharacteristicData.fromMap(call.arguments); - }); + Stream get onCharacteristicWritten async* { + await for (final call in _calls.stream) { + if (call.method == 'OnCharacteristicWritten') { + yield BmCharacteristicData.fromMap(call.arguments); + } + } } @override - Stream get onConnectionStateChanged { - return _calls.stream.where((call) { - return call.method == 'OnConnectionStateChanged'; - }).map((call) { - return BmConnectionStateResponse.fromMap(call.arguments); - }); + Stream get onConnectionStateChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnConnectionStateChanged') { + yield BmConnectionStateResponse.fromMap(call.arguments); + } + } } @override - Stream get onDescriptorRead { - return _calls.stream.where((call) { - return call.method == 'OnDescriptorRead'; - }).map((call) { - return BmDescriptorData.fromMap(call.arguments); - }); + Stream get onDescriptorRead async* { + await for (final call in _calls.stream) { + if (call.method == 'OnDescriptorRead') { + yield BmDescriptorData.fromMap(call.arguments); + } + } } @override - Stream get onDescriptorWritten { - return _calls.stream.where((call) { - return call.method == 'OnDescriptorWritten'; - }).map((call) { - return BmDescriptorData.fromMap(call.arguments); - }); + Stream get onDescriptorWritten async* { + await for (final call in _calls.stream) { + if (call.method == 'OnDescriptorWritten') { + yield BmDescriptorData.fromMap(call.arguments); + } + } } @override - Stream get onDetachedFromEngine { - return _calls.stream.where((call) { - return call.method == 'OnDetachedFromEngine'; - }); + Stream get onDetachedFromEngine async* { + await for (final call in _calls.stream) { + if (call.method == 'OnDetachedFromEngine') { + yield null; + } + } } @override - Stream get onDiscoveredServices { - return _calls.stream.where((call) { - return call.method == 'OnDiscoveredServices'; - }).map((call) { - return BmDiscoverServicesResult.fromMap(call.arguments); - }); + Stream get onDiscoveredServices async* { + await for (final call in _calls.stream) { + if (call.method == 'OnDiscoveredServices') { + yield BmDiscoverServicesResult.fromMap(call.arguments); + } + } } @override - Stream get onMtuChanged { - return _calls.stream.where((call) { - return call.method == 'OnMtuChanged'; - }).map((call) { - return BmMtuChangedResponse.fromMap(call.arguments); - }); + Stream get onMtuChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnMtuChanged') { + yield BmMtuChangedResponse.fromMap(call.arguments); + } + } } @override - Stream get onNameChanged { - return _calls.stream.where((call) { - return call.method == 'OnNameChanged'; - }).map((call) { - return BmNameChanged.fromMap(call.arguments); - }); + Stream get onNameChanged async* { + await for (final call in _calls.stream) { + if (call.method == 'OnNameChanged') { + yield BmNameChanged.fromMap(call.arguments); + } + } } @override - Stream get onReadRssi { - return _calls.stream.where((call) { - return call.method == 'OnReadRssi'; - }).map((call) { - return BmReadRssiResult.fromMap(call.arguments); - }); + Stream get onReadRssi async* { + await for (final call in _calls.stream) { + if (call.method == 'OnReadRssi') { + yield BmReadRssiResult.fromMap(call.arguments); + } + } } @override - Stream get onScanResponse { - return _calls.stream.where((call) { - return call.method == 'OnScanResponse'; - }).map((call) { - return BmScanResponse.fromMap(call.arguments); - }); + Stream get onScanResponse async* { + await for (final call in _calls.stream) { + if (call.method == 'OnScanResponse') { + yield BmScanResponse.fromMap(call.arguments); + } + } } @override - Stream get onServicesReset { - return _calls.stream.where((call) { - return call.method == 'OnServicesReset'; - }).map((call) { - return BmBluetoothDevice.fromMap(call.arguments); - }); + Stream get onServicesReset async* { + await for (final call in _calls.stream) { + if (call.method == 'OnServicesReset') { + yield BmBluetoothDevice.fromMap(call.arguments); + } + } } @override - Stream get onTurnOnResponse { - return _calls.stream.where((call) { - return call.method == 'OnTurnOnResponse'; - }).map((call) { - return BmTurnOnResponse.fromMap(call.arguments); - }); + Stream get onTurnOnResponse async* { + await for (final call in _calls.stream) { + if (call.method == 'OnTurnOnResponse') { + yield BmTurnOnResponse.fromMap(call.arguments); + } + } } @override @@ -307,13 +313,6 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { return BmDevicesList.fromMap(result!); } - @visibleForTesting - Future handleMethodCall( - MethodCall call, - ) async { - _calls.add(call); - } - @override Future isSupported() async { final result = await channel.invokeMethod( diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart index c6053b1a..90ba85aa 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart @@ -33,8 +33,8 @@ class BmScanResponse { Map toMap() { return { 'advertisements': - advertisements.map((advertisement) => advertisement.toMap()).toList(), - 'success': success ? 1 : 0, + advertisements.map((advertisement) => advertisement.toMap()), + 'success': success, 'error_code': errorCode, 'error_string': errorString, }; diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart index 39b821b2..e236e873 100644 --- a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart @@ -12,830 +12,7 @@ void main() { final flutterBluePlus = MethodChannelFlutterBluePlus(); final log = []; - Future? Function(MethodCall call)? methodCallHandler; - - group( - 'onAdapterStateChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ).toMap(); - - expectLater( - flutterBluePlus.onAdapterStateChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnAdapterStateChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ).toMap(); - - expectLater( - flutterBluePlus.onAdapterStateChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnAdapterStateChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onBondStateChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmBondStateResponse( - remoteId: DeviceIdentifier(''), - bondState: BmBondStateEnum.none, - ).toMap(); - - expectLater( - flutterBluePlus.onBondStateChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnBondStateChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmBondStateResponse( - remoteId: DeviceIdentifier(''), - bondState: BmBondStateEnum.none, - ).toMap(); - - expectLater( - flutterBluePlus.onBondStateChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnBondStateChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onCharacteristicReceived', - () { - test( - 'deserializes the event', - () async { - final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onCharacteristicReceived.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnCharacteristicReceived', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onCharacteristicReceived, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnCharacteristicReceived', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onCharacteristicWritten', - () { - test( - 'deserializes the event', - () async { - final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onCharacteristicWritten.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnCharacteristicWritten', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmCharacteristicData( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onCharacteristicWritten, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnCharacteristicWritten', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onConnectionStateChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmConnectionStateResponse( - remoteId: DeviceIdentifier(''), - connectionState: BmConnectionStateEnum.disconnected, - ).toMap(); - - expectLater( - flutterBluePlus.onConnectionStateChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnConnectionStateChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmConnectionStateResponse( - remoteId: DeviceIdentifier(''), - connectionState: BmConnectionStateEnum.disconnected, - ).toMap(); - - expectLater( - flutterBluePlus.onConnectionStateChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnConnectionStateChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onDescriptorRead', - () { - test( - 'deserializes the event', - () async { - final arguments = BmDescriptorData( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDescriptorRead.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDescriptorRead', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmDescriptorData( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDescriptorRead, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDescriptorRead', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onDescriptorWritten', - () { - test( - 'deserializes the event', - () async { - final arguments = BmDescriptorData( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDescriptorWritten.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDescriptorWritten', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmDescriptorData( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDescriptorWritten, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDescriptorWritten', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onDetachedFromEngine', - () { - test( - 'handles the method call', - () async { - expectLater( - flutterBluePlus.onDetachedFromEngine, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDetachedFromEngine', - ), - ); - }, - ); - }, - ); - - group( - 'onDiscoveredServices', - () { - test( - 'deserializes the event', - () async { - final arguments = BmDiscoverServicesResult( - remoteId: DeviceIdentifier(''), - services: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDiscoveredServices.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDiscoveredServices', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmDiscoverServicesResult( - remoteId: DeviceIdentifier(''), - services: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onDiscoveredServices, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnDiscoveredServices', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onMtuChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmMtuChangedResponse( - remoteId: DeviceIdentifier(''), - mtu: 0, - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onMtuChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnMtuChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmMtuChangedResponse( - remoteId: DeviceIdentifier(''), - mtu: 0, - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onMtuChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnMtuChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onNameChanged', - () { - test( - 'deserializes the event', - () async { - final arguments = BmNameChanged( - remoteId: DeviceIdentifier(''), - name: '', - ).toMap(); - - expectLater( - flutterBluePlus.onNameChanged.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnNameChanged', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmNameChanged( - remoteId: DeviceIdentifier(''), - name: '', - ).toMap(); - - expectLater( - flutterBluePlus.onNameChanged, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnNameChanged', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onReadRssi', - () { - test( - 'deserializes the event', - () async { - final arguments = BmReadRssiResult( - remoteId: DeviceIdentifier(''), - rssi: 0, - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onReadRssi.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnReadRssi', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmReadRssiResult( - remoteId: DeviceIdentifier(''), - rssi: 0, - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onReadRssi, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnReadRssi', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onScanResponse', - () { - test( - 'deserializes the event', - () async { - final arguments = BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onScanResponse.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnScanResponse', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmScanResponse( - advertisements: [], - success: true, - errorCode: 0, - errorString: '', - ).toMap(); - - expectLater( - flutterBluePlus.onScanResponse, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnScanResponse', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onServicesReset', - () { - test( - 'deserializes the event', - () async { - final arguments = BmBluetoothDevice( - remoteId: DeviceIdentifier(''), - ).toMap(); - - expectLater( - flutterBluePlus.onServicesReset.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnServicesReset', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmBluetoothDevice( - remoteId: DeviceIdentifier(''), - ).toMap(); - - expectLater( - flutterBluePlus.onServicesReset, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnServicesReset', - arguments, - ), - ); - }, - ); - }, - ); - - group( - 'onServicesReset', - () { - test( - 'deserializes the event', - () async { - final arguments = BmTurnOnResponse( - userAccepted: true, - ).toMap(); - - expectLater( - flutterBluePlus.onTurnOnResponse.map( - (event) { - return event.toMap(); - }, - ), - emits(equals(arguments)), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnTurnOnResponse', - arguments, - ), - ); - }, - ); - - test( - 'handles the method call', - () async { - final arguments = BmTurnOnResponse( - userAccepted: true, - ).toMap(); - - expectLater( - flutterBluePlus.onTurnOnResponse, - emits(anything), - ); - - await flutterBluePlus.handleMethodCall( - MethodCall( - 'OnTurnOnResponse', - arguments, - ), - ); - }, - ); - }, - ); + Future? Function(MethodCall methodCall)? handler; group( 'clearGattCache', @@ -868,7 +45,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -876,7 +53,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -926,7 +103,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -934,7 +111,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -974,7 +151,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -982,7 +159,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1026,7 +203,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -1034,7 +211,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1102,7 +279,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -1110,7 +287,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1150,7 +327,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -1158,7 +335,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1200,7 +377,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -1208,7 +385,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1251,7 +428,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -1259,7 +436,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1305,7 +482,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -1313,7 +490,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1356,7 +533,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -1364,7 +541,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1406,7 +583,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result.toMap()); }; }, @@ -1414,7 +591,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1454,7 +631,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -1462,7 +639,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1583,7 +760,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -1591,7 +768,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1713,7 +890,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -1721,7 +898,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -1912,7 +1089,7 @@ void main() { setUp( () { - methodCallHandler = (call) { + handler = (call) { return Future.value(result); }; }, @@ -1920,7 +1097,7 @@ void main() { tearDown( () { - methodCallHandler = null; + handler = null; }, ); @@ -2022,7 +1199,7 @@ void main() { (call) { log.add(call); - return methodCallHandler?.call(call); + return handler?.call(call); }, ); }, From 6b103b09073148ae129ac65e475cf50afa62b73c Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:46 +0100 Subject: [PATCH 62/90] Revert "chore: remove pubspec from root" This reverts commit 22e8b12cc2f89de804e5598e1f572854fb37b03e. --- pubspec.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 pubspec.yaml diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 00000000..3cd93451 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,23 @@ +name: flutter_blue_plus +description: Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, and MacOS. +version: 1.32.12 +homepage: https://github.com/boskokg/flutter_blue_plus + +environment: + sdk: ">=2.15.1 <4.0.0" + flutter: ">=2.5.0" + +dependencies: + flutter: + sdk: flutter + +flutter: + plugin: + platforms: + android: + package: com.lib.flutter_blue_plus + pluginClass: FlutterBluePlusPlugin + ios: + pluginClass: FlutterBluePlusPlugin + macos: + pluginClass: FlutterBluePlusPlugin From 57c5e67a4f2140f9d00ee4358bfdb899c0da2c83 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:46 +0100 Subject: [PATCH 63/90] Revert "refactor: add events to platform interface" This reverts commit 38c5453dfe89bf972b0477b2c7272df21bbbc505. --- .../lib/src/flutter_blue_plus_platform.dart | 130 ++-------- .../src/method_channel_flutter_blue_plus.dart | 223 +++--------------- ...method_channel_flutter_blue_plus_test.dart | 38 +-- 3 files changed, 72 insertions(+), 319 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index 31deb750..ce5ccab2 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -1,8 +1,6 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'adapter/models/bm_bluetooth_adapter_state.dart'; -import 'adapter/models/bm_turn_on_response.dart'; -import 'characteristic/models/bm_characteristic_data.dart'; import 'characteristic/models/bm_read_characteristic_request.dart'; import 'characteristic/models/bm_set_notify_value_request.dart'; import 'characteristic/models/bm_write_characteristic_request.dart'; @@ -10,124 +8,38 @@ import 'common/enums/log_level.dart'; import 'common/models/device_identifier.dart'; import 'common/models/options.dart'; import 'common/models/phy_support.dart'; -import 'descriptor/models/bm_descriptor_data.dart'; import 'descriptor/models/bm_read_descriptor_request.dart'; import 'descriptor/models/bm_write_descriptor_request.dart'; -import 'device/models/bm_bluetooth_device.dart'; import 'device/models/bm_bond_state_response.dart'; import 'device/models/bm_connect_request.dart'; import 'device/models/bm_connection_priority_request.dart'; -import 'device/models/bm_connection_state_response.dart'; import 'device/models/bm_devices_list.dart'; import 'device/models/bm_mtu_change_request.dart'; -import 'device/models/bm_mtu_changed_response.dart'; -import 'device/models/bm_name_changed.dart'; import 'device/models/bm_preferred_phy.dart'; -import 'device/models/bm_read_rssi_result.dart'; import 'method_channel_flutter_blue_plus.dart'; -import 'scan/models/bm_scan_response.dart'; import 'scan/models/bm_scan_settings.dart'; -import 'service/models/bm_discover_services_result.dart'; /// The interface that implementations of flutter_blue_plus must implement. abstract class FlutterBluePlusPlatform extends PlatformInterface { + FlutterBluePlusPlatform() : super(token: _token); + static final _token = Object(); static FlutterBluePlusPlatform _instance = MethodChannelFlutterBluePlus(); - FlutterBluePlusPlatform() : super(token: _token); - /// The default instance of [FlutterBluePlusPlatform] to use. /// /// Defaults to [MethodChannelFlutterBluePlus]. - static FlutterBluePlusPlatform get instance { - return _instance; - } + static FlutterBluePlusPlatform get instance => _instance; - /// Platform-specific plugins should set this with their own platform-specific class that extends [FlutterBluePlusPlatform] when they register themselves. - static set instance( - FlutterBluePlusPlatform instance, - ) { + /// Platform-specific plugins should set this with their own platform-specific + /// class that extends [FlutterBluePlusPlatform] when they register themselves. + static set instance(FlutterBluePlusPlatform instance) { PlatformInterface.verify(instance, _token); _instance = instance; } - /// Returns a stream of adapter state changed events. - Stream get onAdapterStateChanged { - throw UnimplementedError(); - } - - /// Returns a stream of bond state changed events. - Stream get onBondStateChanged { - throw UnimplementedError(); - } - - /// Returns a stream of characteristic received (notified or read) events. - Stream get onCharacteristicReceived { - throw UnimplementedError(); - } - - /// Returns a stream of characteristic written events. - Stream get onCharacteristicWritten { - throw UnimplementedError(); - } - - /// Returns a stream of connection state changed events. - Stream get onConnectionStateChanged { - throw UnimplementedError(); - } - - /// Returns a stream of descriptor read events. - Stream get onDescriptorRead { - throw UnimplementedError(); - } - - /// Returns a stream of descriptor written events. - Stream get onDescriptorWritten { - throw UnimplementedError(); - } - - /// Returns a stream of detached from engine events. - Stream get onDetachedFromEngine { - throw UnimplementedError(); - } - - /// Returns a stream of discovered services events. - Stream get onDiscoveredServices { - throw UnimplementedError(); - } - - /// Returns a stream of Maximum Transmission Unit (MTU) changed events. - Stream get onMtuChanged { - throw UnimplementedError(); - } - - /// Returns a stream of name changed events. - Stream get onNameChanged { - throw UnimplementedError(); - } - - /// Returns a stream of Received Signal Strength Indicator (RSSI) read events. - Stream get onReadRssi { - throw UnimplementedError(); - } - - /// Returns a stream of scan response events. - Stream get onScanResponse { - throw UnimplementedError(); - } - - /// Returns a stream of services reset events. - Stream get onServicesReset { - throw UnimplementedError(); - } - - /// Returns a stream of turn on response events. - Stream get onTurnOnResponse { - throw UnimplementedError(); - } - - /// Clears the Generic Attribute Profile (GATT) cache for a [remoteId]. + /// Clears the GATT cache for a [remoteId]. Future clearGattCache( DeviceIdentifier remoteId, ) { @@ -138,7 +50,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the connection state is changed. /// - /// Implementations should add an event to the [onConnectionStateChanged] stream with the changed connection state. + /// Implementations should call [OnConnectionStateChanged] with the changed connection state. Future connect( BmConnectRequest request, ) { @@ -154,7 +66,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the bond state is changed. /// - /// Implementations should add an event to the [onBondStateChanged] stream with the changed bond state. + /// Implementations should call [OnBondStateChanged] with the changed bond state. Future createBond( DeviceIdentifier remoteId, ) { @@ -165,7 +77,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the connection state is changed. /// - /// Implementations should add an event to the [onConnectionStateChanged] stream with the changed connection state. + /// Implementations should call [OnConnectionStateChanged] with the changed connection state. Future disconnect( DeviceIdentifier remoteId, ) { @@ -174,7 +86,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Discovers the services for a [remoteId]. /// - /// Implementations should add an event to the [onDiscoveredServices] stream with the discovered services. + /// Implementations should call [OnDiscoveredServices] with the discovered services. Future discoverServices( DeviceIdentifier remoteId, ) { @@ -225,7 +137,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Reads the characteristic for a [request]. /// - /// Implementations should add an event to the [onCharacteristicReceived] stream with the read characteristic. + /// Implementations should call [OnCharacteristicReceived] with the read characteristic. Future readCharacteristic( BmReadCharacteristicRequest request, ) { @@ -234,7 +146,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Reads the descriptor for a [request]. /// - /// Implementations should add an event to the [onDescriptorRead] stream with the read descriptor. + /// Implementations should call [OnDescriptorRead] with the read descriptor. Future readDescriptor( BmReadDescriptorRequest request, ) { @@ -243,7 +155,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. /// - /// Implementations should add an event to the [onReadRssi] stream with the read RSSI. + /// Implementations should call [OnReadRssi] with the read RSSI. Future readRssi( DeviceIdentifier remoteId, ) { @@ -254,7 +166,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the bond state is changed. /// - /// Implementations should add an event to the [onBondStateChanged] stream with the changed bond state. + /// Implementations should call [OnBondStateChanged] with the changed bond state. Future removeBond( DeviceIdentifier remoteId, ) { @@ -270,7 +182,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Requests a change to the Maximum Transmission Unit (MTU) for a [request]. /// - /// Implementations should add an event to the [onMtuChanged] stream with the changed MTU. + /// Implementations should call [OnMtuChanged] with the changed MTU. Future requestMtu( BmMtuChangeRequest request, ) { @@ -288,7 +200,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the characteristic has a Client Characteristic Configuration Descriptor (CCCD). /// - /// Implementations should add an event to the [onDescriptorWritten] stream with the written CCCD. + /// Implementations should call [OnDescriptorWritten] with the written CCCD. Future setNotifyValue( BmSetNotifyValueRequest request, ) { @@ -311,7 +223,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Starts scanning for devices. /// - /// Implementations should add an event to the [onScanResponse] stream for each scanned device. + /// Implementations should call [OnScanResponse] for each scanned device. Future startScan( BmScanSettings settings, ) { @@ -332,14 +244,14 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// /// Returns [true] if the power state is changed. /// - /// Implementations should add an event to the [onTurnOnResponse] stream with the power state. + /// Implementations should call [OnTurnOnResponse] with the power state. Future turnOn() { throw UnimplementedError(); } /// Writes the characteristic for a [request]. /// - /// Implementations should add an event to the [onCharacteristicWritten] stream with the written characteristic. + /// Implementations should call [OnCharacteristicWritten] with the written characteristic. Future writeCharacteristic( BmWriteCharacteristicRequest request, ) { @@ -348,7 +260,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Writes the descriptor for a [request]. /// - /// Implementations should add an event to the [onDescriptorWritten] stream with the written descriptor. + /// Implementations should call [OnDescriptorWritten] with the written descriptor. Future writeDescriptor( BmWriteDescriptorRequest request, ) { diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index 0949c4af..e678d758 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -1,11 +1,6 @@ -import 'dart:async'; - -import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'adapter/models/bm_bluetooth_adapter_state.dart'; -import 'adapter/models/bm_turn_on_response.dart'; -import 'characteristic/models/bm_characteristic_data.dart'; import 'characteristic/models/bm_read_characteristic_request.dart'; import 'characteristic/models/bm_set_notify_value_request.dart'; import 'characteristic/models/bm_write_characteristic_request.dart'; @@ -13,180 +8,26 @@ import 'common/enums/log_level.dart'; import 'common/models/device_identifier.dart'; import 'common/models/options.dart'; import 'common/models/phy_support.dart'; -import 'descriptor/models/bm_descriptor_data.dart'; import 'descriptor/models/bm_read_descriptor_request.dart'; import 'descriptor/models/bm_write_descriptor_request.dart'; -import 'device/models/bm_bluetooth_device.dart'; import 'device/models/bm_bond_state_response.dart'; import 'device/models/bm_connect_request.dart'; import 'device/models/bm_connection_priority_request.dart'; -import 'device/models/bm_connection_state_response.dart'; import 'device/models/bm_devices_list.dart'; import 'device/models/bm_mtu_change_request.dart'; -import 'device/models/bm_mtu_changed_response.dart'; -import 'device/models/bm_name_changed.dart'; import 'device/models/bm_preferred_phy.dart'; -import 'device/models/bm_read_rssi_result.dart'; import 'flutter_blue_plus_platform.dart'; -import 'scan/models/bm_scan_response.dart'; import 'scan/models/bm_scan_settings.dart'; -import 'service/models/bm_discover_services_result.dart'; + +const _channel = MethodChannel('flutter_blue_plus/methods'); /// An implementation of [FlutterBluePlusPlatform] that uses method channels. class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { - @visibleForTesting - final channel = const MethodChannel('flutter_blue_plus/methods'); - - final _calls = StreamController.broadcast(); - - MethodChannelFlutterBluePlus() { - channel.setMethodCallHandler( - (call) async { - _calls.add(call); - }, - ); - } - - @override - Stream get onAdapterStateChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnAdapterStateChanged') { - yield BmBluetoothAdapterState.fromMap(call.arguments); - } - } - } - - @override - Stream get onBondStateChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnBondStateChanged') { - yield BmBondStateResponse.fromMap(call.arguments); - } - } - } - - @override - Stream get onCharacteristicReceived async* { - await for (final call in _calls.stream) { - if (call.method == 'OnCharacteristicReceived') { - yield BmCharacteristicData.fromMap(call.arguments); - } - } - } - - @override - Stream get onCharacteristicWritten async* { - await for (final call in _calls.stream) { - if (call.method == 'OnCharacteristicWritten') { - yield BmCharacteristicData.fromMap(call.arguments); - } - } - } - - @override - Stream get onConnectionStateChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnConnectionStateChanged') { - yield BmConnectionStateResponse.fromMap(call.arguments); - } - } - } - - @override - Stream get onDescriptorRead async* { - await for (final call in _calls.stream) { - if (call.method == 'OnDescriptorRead') { - yield BmDescriptorData.fromMap(call.arguments); - } - } - } - - @override - Stream get onDescriptorWritten async* { - await for (final call in _calls.stream) { - if (call.method == 'OnDescriptorWritten') { - yield BmDescriptorData.fromMap(call.arguments); - } - } - } - - @override - Stream get onDetachedFromEngine async* { - await for (final call in _calls.stream) { - if (call.method == 'OnDetachedFromEngine') { - yield null; - } - } - } - - @override - Stream get onDiscoveredServices async* { - await for (final call in _calls.stream) { - if (call.method == 'OnDiscoveredServices') { - yield BmDiscoverServicesResult.fromMap(call.arguments); - } - } - } - - @override - Stream get onMtuChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnMtuChanged') { - yield BmMtuChangedResponse.fromMap(call.arguments); - } - } - } - - @override - Stream get onNameChanged async* { - await for (final call in _calls.stream) { - if (call.method == 'OnNameChanged') { - yield BmNameChanged.fromMap(call.arguments); - } - } - } - - @override - Stream get onReadRssi async* { - await for (final call in _calls.stream) { - if (call.method == 'OnReadRssi') { - yield BmReadRssiResult.fromMap(call.arguments); - } - } - } - - @override - Stream get onScanResponse async* { - await for (final call in _calls.stream) { - if (call.method == 'OnScanResponse') { - yield BmScanResponse.fromMap(call.arguments); - } - } - } - - @override - Stream get onServicesReset async* { - await for (final call in _calls.stream) { - if (call.method == 'OnServicesReset') { - yield BmBluetoothDevice.fromMap(call.arguments); - } - } - } - - @override - Stream get onTurnOnResponse async* { - await for (final call in _calls.stream) { - if (call.method == 'OnTurnOnResponse') { - yield BmTurnOnResponse.fromMap(call.arguments); - } - } - } - @override Future clearGattCache( DeviceIdentifier remoteId, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'clearGattCache', remoteId.str, ); @@ -196,7 +37,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future connect( BmConnectRequest request, ) async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'connect', request.toMap(), ); @@ -206,7 +47,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future connectedCount() async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'connectedCount', ); @@ -217,7 +58,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future createBond( DeviceIdentifier remoteId, ) async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'createBond', remoteId.str, ); @@ -229,7 +70,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future disconnect( DeviceIdentifier remoteId, ) async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'disconnect', remoteId.str, ); @@ -241,7 +82,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future discoverServices( DeviceIdentifier remoteId, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'discoverServices', remoteId.str, ); @@ -249,7 +90,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future flutterRestart() async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'flutterRestart', ); @@ -258,7 +99,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getAdapterName() async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'getAdapterName', ); @@ -267,7 +108,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getAdapterState() async { - final result = await channel.invokeMethod>( + final result = await _channel.invokeMethod>( 'getAdapterState', ); @@ -278,7 +119,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future getBondState( DeviceIdentifier remoteId, ) async { - final result = await channel.invokeMethod>( + final result = await _channel.invokeMethod>( 'getBondState', remoteId.str, ); @@ -288,7 +129,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getBondedDevices() async { - final result = await channel.invokeMethod>( + final result = await _channel.invokeMethod>( 'getBondedDevices', ); @@ -297,7 +138,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getPhySupport() async { - final result = await channel.invokeMethod>( + final result = await _channel.invokeMethod>( 'getPhySupport', ); @@ -306,7 +147,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getSystemDevices() async { - final result = await channel.invokeMethod>( + final result = await _channel.invokeMethod>( 'getSystemDevices', ); @@ -315,7 +156,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future isSupported() async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'isSupported', ); @@ -326,7 +167,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future readCharacteristic( BmReadCharacteristicRequest request, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'readCharacteristic', request.toMap(), ); @@ -336,7 +177,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future readDescriptor( BmReadDescriptorRequest request, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'readDescriptor', request.toMap(), ); @@ -346,7 +187,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future readRssi( DeviceIdentifier remoteId, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'readRssi', remoteId.str, ); @@ -356,7 +197,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future removeBond( DeviceIdentifier remoteId, ) async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'removeBond', remoteId.str, ); @@ -368,7 +209,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future requestConnectionPriority( BmConnectionPriorityRequest request, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'requestConnectionPriority', request.toMap(), ); @@ -378,7 +219,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future requestMtu( BmMtuChangeRequest request, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'requestMtu', request.toMap(), ); @@ -388,7 +229,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future setLogLevel( LogLevel level, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'setLogLevel', level.index, ); @@ -398,7 +239,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future setNotifyValue( BmSetNotifyValueRequest request, ) async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'setNotifyValue', request.toMap(), ); @@ -410,7 +251,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future setOptions( Options options, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'setOptions', options.toMap(), ); @@ -420,7 +261,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future setPreferredPhy( BmPreferredPhy preferredPhy, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'setPreferredPhy', preferredPhy.toMap(), ); @@ -430,7 +271,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future startScan( BmScanSettings settings, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'startScan', settings.toMap(), ); @@ -438,21 +279,21 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future stopScan() async { - await channel.invokeMethod( + await _channel.invokeMethod( 'stopScan', ); } @override Future turnOff() async { - await channel.invokeMethod( + await _channel.invokeMethod( 'turnOff', ); } @override Future turnOn() async { - final result = await channel.invokeMethod( + final result = await _channel.invokeMethod( 'turnOn', ); @@ -463,7 +304,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future writeCharacteristic( BmWriteCharacteristicRequest request, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'writeCharacteristic', request.toMap(), ); @@ -473,7 +314,7 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { Future writeDescriptor( BmWriteDescriptorRequest request, ) async { - await channel.invokeMethod( + await _channel.invokeMethod( 'writeDescriptor', request.toMap(), ); diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart index e236e873..93794eda 100644 --- a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart @@ -45,7 +45,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -103,7 +103,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -151,7 +151,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -203,7 +203,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -279,7 +279,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -327,7 +327,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -377,7 +377,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result.toMap()); }; }, @@ -428,7 +428,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result.toMap()); }; }, @@ -482,7 +482,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result.toMap()); }; }, @@ -533,7 +533,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result.toMap()); }; }, @@ -583,7 +583,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result.toMap()); }; }, @@ -631,7 +631,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -760,7 +760,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -890,7 +890,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -1089,7 +1089,7 @@ void main() { setUp( () { - handler = (call) { + handler = (methodCall) { return Future.value(result); }; }, @@ -1195,11 +1195,11 @@ void main() { () { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - flutterBluePlus.channel, - (call) { - log.add(call); + MethodChannel('flutter_blue_plus/methods'), + (methodCall) { + log.add(methodCall); - return handler?.call(call); + return handler?.call(methodCall); }, ); }, From ba4519cf4c12ef335ec8f62a88607ec33f6bf56b Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:46 +0100 Subject: [PATCH 64/90] Revert "refactor: rename device parameter to remote id" This reverts commit 7913c48564a3db27539ba7f45b36b46e68890520. --- .../lib/src/flutter_blue_plus_platform.dart | 28 +++++++++---------- .../src/method_channel_flutter_blue_plus.dart | 28 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index ce5ccab2..8947143c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -39,9 +39,9 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { _instance = instance; } - /// Clears the GATT cache for a [remoteId]. + /// Clears the GATT cache for a [device]. Future clearGattCache( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } @@ -62,33 +62,33 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Creates a bond to a [remoteId]. + /// Creates a bond to a [device]. /// /// Returns [true] if the bond state is changed. /// /// Implementations should call [OnBondStateChanged] with the changed bond state. Future createBond( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } - /// Disconnects from a [remoteId]. + /// Disconnects from a [device]. /// /// Returns [true] if the connection state is changed. /// /// Implementations should call [OnConnectionStateChanged] with the changed connection state. Future disconnect( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } - /// Discovers the services for a [remoteId]. + /// Discovers the services for a [device]. /// /// Implementations should call [OnDiscoveredServices] with the discovered services. Future discoverServices( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } @@ -108,9 +108,9 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Returns the bond state for a [remoteId]. + /// Returns the bond state for a [device]. Future getBondState( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } @@ -153,22 +153,22 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. + /// Reads the Received Signal Strength Indicator (RSSI) for a [device]. /// /// Implementations should call [OnReadRssi] with the read RSSI. Future readRssi( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } - /// Removes the bond to a [remoteId]. + /// Removes the bond to a [device]. /// /// Returns [true] if the bond state is changed. /// /// Implementations should call [OnBondStateChanged] with the changed bond state. Future removeBond( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) { throw UnimplementedError(); } diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index e678d758..c734edfd 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -25,11 +25,11 @@ const _channel = MethodChannel('flutter_blue_plus/methods'); class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future clearGattCache( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) async { await _channel.invokeMethod( 'clearGattCache', - remoteId.str, + device.str, ); } @@ -56,11 +56,11 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future createBond( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) async { final result = await _channel.invokeMethod( 'createBond', - remoteId.str, + device.str, ); return result!; @@ -68,11 +68,11 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future disconnect( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) async { final result = await _channel.invokeMethod( 'disconnect', - remoteId.str, + device.str, ); return result!; @@ -80,11 +80,11 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future discoverServices( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) async { await _channel.invokeMethod( 'discoverServices', - remoteId.str, + device.str, ); } @@ -117,11 +117,11 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future getBondState( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) async { final result = await _channel.invokeMethod>( 'getBondState', - remoteId.str, + device.str, ); return BmBondStateResponse.fromMap(result!); @@ -185,21 +185,21 @@ class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { @override Future readRssi( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) async { await _channel.invokeMethod( 'readRssi', - remoteId.str, + device.str, ); } @override Future removeBond( - DeviceIdentifier remoteId, + DeviceIdentifier device, ) async { final result = await _channel.invokeMethod( 'removeBond', - remoteId.str, + device.str, ); return result!; From 69b7da941ef3bb2b67279cd1170421cdc6f40be5 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:47 +0100 Subject: [PATCH 65/90] Revert "refactor: add bm user canceled error code" This reverts commit 0fff3fc6a5b8d4931b1ecf8ea90d44fc7ff23828. --- .../lib/flutter_blue_plus_platform_interface.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index e5a9820c..b011abec 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -39,6 +39,3 @@ export 'src/scan/models/bm_scan_settings.dart'; export 'src/scan/models/bm_service_data_filter.dart'; export 'src/service/models/bm_bluetooth_service.dart'; export 'src/service/models/bm_discover_services_result.dart'; - -// random number defined by flutter blue plus -int bmUserCanceledErrorCode = 23789258; From b41cf10f972ef3ff46f48c2a075b415dbcae4477 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:47 +0100 Subject: [PATCH 66/90] Revert "refactor: migrate ios and macos implementation" This reverts commit 022a1a8c6a3bb5538dee6066aebce2501ff07151. --- .../darwin => ios}/.gitignore | 2 +- ios/Assets/.gitkeep | 0 .../Classes/FlutterBluePlusPlugin.h | 0 .../Classes/FlutterBluePlusPlugin.m | 0 ios/flutter_blue_plus.podspec | 20 +++++++++++ macos/Classes/FlutterBluePlusPlugin.h | 1 + macos/Classes/FlutterBluePlusPlugin.m | 1 + macos/flutter_blue_plus.podspec | 22 +++++++++++++ packages/flutter_blue_plus_darwin/.gitignore | 29 ---------------- packages/flutter_blue_plus_darwin/.metadata | 30 ----------------- .../flutter_blue_plus_darwin/CHANGELOG.md | 3 -- packages/flutter_blue_plus_darwin/LICENSE | 28 ---------------- packages/flutter_blue_plus_darwin/README.md | 15 --------- .../analysis_options.yaml | 1 - .../darwin/flutter_blue_plus_darwin.podspec | 22 ------------- .../flutter_blue_plus_darwin/pubspec.yaml | 33 ------------------- 16 files changed, 45 insertions(+), 162 deletions(-) rename {packages/flutter_blue_plus_darwin/darwin => ios}/.gitignore (90%) create mode 100644 ios/Assets/.gitkeep rename {packages/flutter_blue_plus_darwin/darwin => ios}/Classes/FlutterBluePlusPlugin.h (100%) rename {packages/flutter_blue_plus_darwin/darwin => ios}/Classes/FlutterBluePlusPlugin.m (100%) create mode 100644 ios/flutter_blue_plus.podspec create mode 120000 macos/Classes/FlutterBluePlusPlugin.h create mode 120000 macos/Classes/FlutterBluePlusPlugin.m create mode 100644 macos/flutter_blue_plus.podspec delete mode 100644 packages/flutter_blue_plus_darwin/.gitignore delete mode 100644 packages/flutter_blue_plus_darwin/.metadata delete mode 100644 packages/flutter_blue_plus_darwin/CHANGELOG.md delete mode 100644 packages/flutter_blue_plus_darwin/LICENSE delete mode 100644 packages/flutter_blue_plus_darwin/README.md delete mode 100644 packages/flutter_blue_plus_darwin/analysis_options.yaml delete mode 100644 packages/flutter_blue_plus_darwin/darwin/flutter_blue_plus_darwin.podspec delete mode 100644 packages/flutter_blue_plus_darwin/pubspec.yaml diff --git a/packages/flutter_blue_plus_darwin/darwin/.gitignore b/ios/.gitignore similarity index 90% rename from packages/flutter_blue_plus_darwin/darwin/.gitignore rename to ios/.gitignore index 034771fc..0c885071 100644 --- a/packages/flutter_blue_plus_darwin/darwin/.gitignore +++ b/ios/.gitignore @@ -35,4 +35,4 @@ Icon? /Flutter/Generated.xcconfig /Flutter/ephemeral/ -/Flutter/flutter_export_environment.sh +/Flutter/flutter_export_environment.sh \ No newline at end of file diff --git a/ios/Assets/.gitkeep b/ios/Assets/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/flutter_blue_plus_darwin/darwin/Classes/FlutterBluePlusPlugin.h b/ios/Classes/FlutterBluePlusPlugin.h similarity index 100% rename from packages/flutter_blue_plus_darwin/darwin/Classes/FlutterBluePlusPlugin.h rename to ios/Classes/FlutterBluePlusPlugin.h diff --git a/packages/flutter_blue_plus_darwin/darwin/Classes/FlutterBluePlusPlugin.m b/ios/Classes/FlutterBluePlusPlugin.m similarity index 100% rename from packages/flutter_blue_plus_darwin/darwin/Classes/FlutterBluePlusPlugin.m rename to ios/Classes/FlutterBluePlusPlugin.m diff --git a/ios/flutter_blue_plus.podspec b/ios/flutter_blue_plus.podspec new file mode 100644 index 00000000..d4c7245c --- /dev/null +++ b/ios/flutter_blue_plus.podspec @@ -0,0 +1,20 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint flutter_blue_plus.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'flutter_blue_plus' + s.version = '0.0.1' + s.summary = 'Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS' + s.description = 'Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS' + s.homepage = 'https://github.com/boskokg/flutter_blue_plus' + s.license = { :file => '../LICENSE' } + s.author = { 'Chip Weinberger' => 'weinberger.c@gmail.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.dependency 'Flutter' + s.platform = :ios, '9.0' + s.framework = 'CoreBluetooth' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', } +end diff --git a/macos/Classes/FlutterBluePlusPlugin.h b/macos/Classes/FlutterBluePlusPlugin.h new file mode 120000 index 00000000..2f315101 --- /dev/null +++ b/macos/Classes/FlutterBluePlusPlugin.h @@ -0,0 +1 @@ +../../ios/Classes/FlutterBluePlusPlugin.h \ No newline at end of file diff --git a/macos/Classes/FlutterBluePlusPlugin.m b/macos/Classes/FlutterBluePlusPlugin.m new file mode 120000 index 00000000..0c610151 --- /dev/null +++ b/macos/Classes/FlutterBluePlusPlugin.m @@ -0,0 +1 @@ +../../ios/Classes/FlutterBluePlusPlugin.m \ No newline at end of file diff --git a/macos/flutter_blue_plus.podspec b/macos/flutter_blue_plus.podspec new file mode 100644 index 00000000..6944e77d --- /dev/null +++ b/macos/flutter_blue_plus.podspec @@ -0,0 +1,22 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint flutter_blue_plus.podspec' to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'flutter_blue_plus' + s.version = '0.0.1' + s.summary = 'Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS' + s.description = 'Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS' + s.homepage = 'https://github.com/boskokg/flutter_blue_plus' + s.license = { :file => '../LICENSE' } + s.author = { 'Chip Weinberger' => 'weinberger.c@gmail.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.dependency 'FlutterMacOS' + s.platform = :osx, '10.11' + s.framework = 'CoreBluetooth' + s.pod_target_xcconfig = { + 'DEFINES_MODULE' => 'YES', + } +end diff --git a/packages/flutter_blue_plus_darwin/.gitignore b/packages/flutter_blue_plus_darwin/.gitignore deleted file mode 100644 index ac5aa989..00000000 --- a/packages/flutter_blue_plus_darwin/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ -migrate_working_dir/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. -/pubspec.lock -**/doc/api/ -.dart_tool/ -build/ diff --git a/packages/flutter_blue_plus_darwin/.metadata b/packages/flutter_blue_plus_darwin/.metadata deleted file mode 100644 index 9b743e45..00000000 --- a/packages/flutter_blue_plus_darwin/.metadata +++ /dev/null @@ -1,30 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" - channel: "beta" - -project_type: plugin - -# Tracks metadata for the flutter migrate command -migration: - platforms: - - platform: root - create_revision: b864805a681ae6bb7d7f6cafb7a5a21489819bcf - base_revision: b864805a681ae6bb7d7f6cafb7a5a21489819bcf - - platform: ios - create_revision: b864805a681ae6bb7d7f6cafb7a5a21489819bcf - base_revision: b864805a681ae6bb7d7f6cafb7a5a21489819bcf - - # User provided section - - # List of Local paths (relative to this file) that should be - # ignored by the migrate tool. - # - # Files that are not part of the templates will be ignored by default. - unmanaged_files: - - 'lib/main.dart' - - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/flutter_blue_plus_darwin/CHANGELOG.md b/packages/flutter_blue_plus_darwin/CHANGELOG.md deleted file mode 100644 index 1e7cb110..00000000 --- a/packages/flutter_blue_plus_darwin/CHANGELOG.md +++ /dev/null @@ -1,3 +0,0 @@ -## 1.33.0 - -* Split from `flutter_blue_plus` as a federated implementation. diff --git a/packages/flutter_blue_plus_darwin/LICENSE b/packages/flutter_blue_plus_darwin/LICENSE deleted file mode 100644 index 0df3b4a3..00000000 --- a/packages/flutter_blue_plus_darwin/LICENSE +++ /dev/null @@ -1,28 +0,0 @@ -Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Buffalo PC Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_darwin/README.md b/packages/flutter_blue_plus_darwin/README.md deleted file mode 100644 index 6e6d5ecd..00000000 --- a/packages/flutter_blue_plus_darwin/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# flutter_blue_plus_darwin - -The iOS and macOS implementation of [`flutter_blue_plus`][1]. - -## Usage - -This package is [endorsed][2], which means you can simply use `flutter_blue_plus` -normally. This package will be automatically included in your app when you do, -so you do not need to add it to your `pubspec.yaml`. - -However, if you `import` this package to use any of its APIs directly, you -should add it to your `pubspec.yaml` as usual. - -[1]: https://pub.dev/packages/flutter_blue_plus -[2]: https://flutter.dev/to/endorsed-federated-plugin diff --git a/packages/flutter_blue_plus_darwin/analysis_options.yaml b/packages/flutter_blue_plus_darwin/analysis_options.yaml deleted file mode 100644 index f9b30346..00000000 --- a/packages/flutter_blue_plus_darwin/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_darwin/darwin/flutter_blue_plus_darwin.podspec b/packages/flutter_blue_plus_darwin/darwin/flutter_blue_plus_darwin.podspec deleted file mode 100644 index a8e159b1..00000000 --- a/packages/flutter_blue_plus_darwin/darwin/flutter_blue_plus_darwin.podspec +++ /dev/null @@ -1,22 +0,0 @@ -# -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. -# Run `pod lib lint flutter_blue_plus.podspec` to validate before publishing. -# -Pod::Spec.new do |s| - s.name = 'flutter_blue_plus' - s.version = '0.0.1' - s.summary = 'Flutter plugin for connecting and communicating with Bluetooth Low Energy devices, on Android and iOS' - s.description = 'Flutter plugin for connecting and communicating with Bluetooth Low Energy devices, on Android and iOS' - s.homepage = 'https://github.com/boskokg/flutter_blue_plus' - s.license = { :file => '../LICENSE' } - s.author = { 'Chip Weinberger' => 'weinberger.c@gmail.com' } - s.source = { :path => '.' } - s.source_files = 'Classes/**/*' - s.public_header_files = 'Classes/**/*.h' - s.ios.dependency 'Flutter' - s.osx.dependency 'FlutterMacOS' - s.ios.deployment_target = '9.0' - s.osx.deployment_target = '10.11' - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', } - s.framework = 'CoreBluetooth' -end diff --git a/packages/flutter_blue_plus_darwin/pubspec.yaml b/packages/flutter_blue_plus_darwin/pubspec.yaml deleted file mode 100644 index 3392cb0f..00000000 --- a/packages/flutter_blue_plus_darwin/pubspec.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: flutter_blue_plus_darwin -description: iOS and macOS implementation of the flutter_blue_plus plugin. -version: 1.33.0 -homepage: https://github.com/boskokg/flutter_blue_plus - -environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=3.7.0" - -dependencies: - flutter: - sdk: flutter - flutter_blue_plus_platform_interface: ^1.0.0 - -dev_dependencies: - flutter_lints: ^4.0.0 - flutter_test: - sdk: flutter - -dependency_overrides: - flutter_blue_plus_platform_interface: - path: ../flutter_blue_plus_platform_interface - -flutter: - plugin: - implements: flutter_blue_plus - platforms: - ios: - pluginClass: FlutterBluePlusPlugin - sharedDarwinSource: true - macos: - pluginClass: FlutterBluePlusPlugin - sharedDarwinSource: true From 8ac562ce4b1daadbdbb94d4655787cf83d817769 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:47 +0100 Subject: [PATCH 67/90] Revert "refactor: migrate android implementation" This reverts commit 9d14ed00d3e44369f194c0c19ffd83206e701edf. --- .../.metadata => .metadata | 6 ++-- .../android => android}/.gitignore | 1 - .../android => android}/build.gradle | 2 -- android/settings.gradle | 1 + .../src/main/AndroidManifest.xml | 0 .../FlutterBluePlusPlugin.java | 0 packages/flutter_blue_plus_android/.gitignore | 29 ------------------ .../flutter_blue_plus_android/CHANGELOG.md | 3 -- packages/flutter_blue_plus_android/LICENSE | 28 ----------------- packages/flutter_blue_plus_android/README.md | 15 ---------- .../analysis_options.yaml | 1 - .../android/settings.gradle | 3 -- .../flutter_blue_plus_android/pubspec.yaml | 30 ------------------- 13 files changed, 4 insertions(+), 115 deletions(-) rename packages/flutter_blue_plus_android/.metadata => .metadata (73%) rename {packages/flutter_blue_plus_android/android => android}/.gitignore (95%) rename {packages/flutter_blue_plus_android/android => android}/build.gradle (93%) create mode 100644 android/settings.gradle rename {packages/flutter_blue_plus_android/android => android}/src/main/AndroidManifest.xml (100%) rename {packages/flutter_blue_plus_android/android => android}/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java (100%) delete mode 100644 packages/flutter_blue_plus_android/.gitignore delete mode 100644 packages/flutter_blue_plus_android/CHANGELOG.md delete mode 100644 packages/flutter_blue_plus_android/LICENSE delete mode 100644 packages/flutter_blue_plus_android/README.md delete mode 100644 packages/flutter_blue_plus_android/analysis_options.yaml delete mode 100644 packages/flutter_blue_plus_android/android/settings.gradle delete mode 100644 packages/flutter_blue_plus_android/pubspec.yaml diff --git a/packages/flutter_blue_plus_android/.metadata b/.metadata similarity index 73% rename from packages/flutter_blue_plus_android/.metadata rename to .metadata index 8123a41b..7516097a 100644 --- a/packages/flutter_blue_plus_android/.metadata +++ b/.metadata @@ -1,10 +1,10 @@ # This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. +# Used by Flutter tool to assess capabilities and perform upgrades, etc. # # This file should be version controlled and should not be manually edited. version: - revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" - channel: "beta" + revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b + channel: stable project_type: plugin diff --git a/packages/flutter_blue_plus_android/android/.gitignore b/android/.gitignore similarity index 95% rename from packages/flutter_blue_plus_android/android/.gitignore rename to android/.gitignore index 161bdcda..c6cbe562 100644 --- a/packages/flutter_blue_plus_android/android/.gitignore +++ b/android/.gitignore @@ -6,4 +6,3 @@ .DS_Store /build /captures -.cxx diff --git a/packages/flutter_blue_plus_android/android/build.gradle b/android/build.gradle similarity index 93% rename from packages/flutter_blue_plus_android/android/build.gradle rename to android/build.gradle index 04f31190..2c6f5f39 100644 --- a/packages/flutter_blue_plus_android/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,3 @@ -package packages.flutter_blue_plus_android.android - group 'com.lib.flutter_blue_plus' version '1.0' diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 00000000..943eabda --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'flutter_blue_plus' diff --git a/packages/flutter_blue_plus_android/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml similarity index 100% rename from packages/flutter_blue_plus_android/android/src/main/AndroidManifest.xml rename to android/src/main/AndroidManifest.xml diff --git a/packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java b/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java similarity index 100% rename from packages/flutter_blue_plus_android/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java rename to android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java diff --git a/packages/flutter_blue_plus_android/.gitignore b/packages/flutter_blue_plus_android/.gitignore deleted file mode 100644 index ac5aa989..00000000 --- a/packages/flutter_blue_plus_android/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ -migrate_working_dir/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. -/pubspec.lock -**/doc/api/ -.dart_tool/ -build/ diff --git a/packages/flutter_blue_plus_android/CHANGELOG.md b/packages/flutter_blue_plus_android/CHANGELOG.md deleted file mode 100644 index 1e7cb110..00000000 --- a/packages/flutter_blue_plus_android/CHANGELOG.md +++ /dev/null @@ -1,3 +0,0 @@ -## 1.33.0 - -* Split from `flutter_blue_plus` as a federated implementation. diff --git a/packages/flutter_blue_plus_android/LICENSE b/packages/flutter_blue_plus_android/LICENSE deleted file mode 100644 index 0df3b4a3..00000000 --- a/packages/flutter_blue_plus_android/LICENSE +++ /dev/null @@ -1,28 +0,0 @@ -Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Buffalo PC Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_android/README.md b/packages/flutter_blue_plus_android/README.md deleted file mode 100644 index dc692c17..00000000 --- a/packages/flutter_blue_plus_android/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# flutter_blue_plus_android - -The Android implementation of [`flutter_blue_plus`][1]. - -## Usage - -This package is [endorsed][2], which means you can simply use `flutter_blue_plus` -normally. This package will be automatically included in your app when you do, -so you do not need to add it to your `pubspec.yaml`. - -However, if you `import` this package to use any of its APIs directly, you -should add it to your `pubspec.yaml` as usual. - -[1]: https://pub.dev/packages/flutter_blue_plus -[2]: https://flutter.dev/to/endorsed-federated-plugin diff --git a/packages/flutter_blue_plus_android/analysis_options.yaml b/packages/flutter_blue_plus_android/analysis_options.yaml deleted file mode 100644 index f9b30346..00000000 --- a/packages/flutter_blue_plus_android/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_android/android/settings.gradle b/packages/flutter_blue_plus_android/android/settings.gradle deleted file mode 100644 index 902780c0..00000000 --- a/packages/flutter_blue_plus_android/android/settings.gradle +++ /dev/null @@ -1,3 +0,0 @@ -package packages.flutter_blue_plus_android.android - -rootProject.name = 'flutter_blue_plus' diff --git a/packages/flutter_blue_plus_android/pubspec.yaml b/packages/flutter_blue_plus_android/pubspec.yaml deleted file mode 100644 index 761ec1a0..00000000 --- a/packages/flutter_blue_plus_android/pubspec.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: flutter_blue_plus_android -description: Android implementation of the flutter_blue_plus plugin. -version: 1.33.0 -homepage: https://github.com/boskokg/flutter_blue_plus - -environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=2.0.0" - -dependencies: - flutter: - sdk: flutter - flutter_blue_plus_platform_interface: ^1.0.0 - -dev_dependencies: - flutter_lints: ^4.0.0 - flutter_test: - sdk: flutter - -dependency_overrides: - flutter_blue_plus_platform_interface: - path: ../flutter_blue_plus_platform_interface - -flutter: - plugin: - implements: flutter_blue_plus - platforms: - android: - package: com.lib.flutter_blue_plus - pluginClass: FlutterBluePlusPlugin From 0c3e196e9bf34eb5fd544aa0d997709b472e381f Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:48 +0100 Subject: [PATCH 68/90] Revert "build: update platform interface pubspec" This reverts commit 09022fb40b1edbb8bdd24cfd6830c2da39e19201. --- packages/flutter_blue_plus_platform_interface/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index b524581a..1804d08c 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -1,11 +1,11 @@ name: flutter_blue_plus_platform_interface description: A common platform interface for the flutter_blue_plus plugin. -version: 1.0.0 +version: 0.0.0 homepage: https://github.com/boskokg/flutter_blue_plus environment: sdk: ">=2.12.0 <4.0.0" - flutter: ">=2.0.0" + flutter: ">=1.17.0" dependencies: convert: ^3.0.0 From 0ac7c32dbdce8e6354fa5b1d4624e0edcc7a1473 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:48 +0100 Subject: [PATCH 69/90] Revert "chore: add changelog to platform interface" This reverts commit 7af78abb75975ef0185b106eb88f1e6d79100b5f. --- packages/flutter_blue_plus_platform_interface/CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/CHANGELOG.md diff --git a/packages/flutter_blue_plus_platform_interface/CHANGELOG.md b/packages/flutter_blue_plus_platform_interface/CHANGELOG.md deleted file mode 100644 index 0d8803f9..00000000 --- a/packages/flutter_blue_plus_platform_interface/CHANGELOG.md +++ /dev/null @@ -1,3 +0,0 @@ -## 1.0.0 - -* Initial release. From 06a8a1db25ea33a2af9d16ac5b7fd8cd1e4d8983 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:48 +0100 Subject: [PATCH 70/90] Revert "test: add method channel implementation" This reverts commit 2e684c573b845ac0b00f9c43ab300a08ef16d00b. --- ...method_channel_flutter_blue_plus_test.dart | 1215 ----------------- 1 file changed, 1215 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart b/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart deleted file mode 100644 index 93794eda..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/method_channel_flutter_blue_plus_test.dart +++ /dev/null @@ -1,1215 +0,0 @@ -import 'package:flutter/services.dart'; -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_blue_plus_platform_interface/src/method_channel_flutter_blue_plus.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group( - 'MethodChannelFlutterBluePlus', - () { - final flutterBluePlus = MethodChannelFlutterBluePlus(); - final log = []; - - Future? Function(MethodCall methodCall)? handler; - - group( - 'clearGattCache', - () { - test( - 'invokes the method', - () async { - final device = DeviceIdentifier(''); - - await flutterBluePlus.clearGattCache(device); - - expect( - log, - orderedEquals([ - isMethodCall( - 'clearGattCache', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'connect', - () { - final result = true; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final request = BmConnectRequest( - remoteId: DeviceIdentifier(''), - autoConnect: false, - ); - - expect( - await flutterBluePlus.connect(request), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final request = BmConnectRequest( - remoteId: DeviceIdentifier(''), - autoConnect: false, - ); - - await flutterBluePlus.connect(request); - - expect( - log, - orderedEquals([ - isMethodCall( - 'connect', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'connectedCount', - () { - final result = 0; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.connectedCount(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.connectedCount(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'connectedCount', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'createBond', - () { - final result = true; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final device = DeviceIdentifier(''); - - expect( - await flutterBluePlus.createBond(device), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final device = DeviceIdentifier(''); - - await flutterBluePlus.createBond(device); - - expect( - log, - orderedEquals([ - isMethodCall( - 'createBond', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'disconnect', - () { - final result = true; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final device = DeviceIdentifier(''); - - expect( - await flutterBluePlus.disconnect(device), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final device = DeviceIdentifier(''); - - await flutterBluePlus.disconnect(device); - - expect( - log, - orderedEquals([ - isMethodCall( - 'disconnect', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'discoverServices', - () { - test( - 'invokes the method', - () async { - final device = DeviceIdentifier(''); - - await flutterBluePlus.discoverServices(device); - - expect( - log, - orderedEquals([ - isMethodCall( - 'discoverServices', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'flutterRestart', - () { - final result = 0; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.flutterRestart(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.flutterRestart(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'flutterRestart', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getAdapterName', - () { - final result = ''; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.getAdapterName(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getAdapterName(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'getAdapterName', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getAdapterState', - () { - final result = BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ); - - setUp( - () { - handler = (methodCall) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - (await flutterBluePlus.getAdapterState()).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getAdapterState(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'getAdapterState', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getBondState', - () { - final result = BmBondStateResponse( - remoteId: DeviceIdentifier(''), - bondState: BmBondStateEnum.none, - ); - - setUp( - () { - handler = (methodCall) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final device = DeviceIdentifier(''); - - expect( - (await flutterBluePlus.getBondState(device)).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - final device = DeviceIdentifier(''); - - await flutterBluePlus.getBondState(device); - - expect( - log, - orderedEquals([ - isMethodCall( - 'getBondState', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getBondedDevices', - () { - final result = BmDevicesList( - devices: [], - ); - - setUp( - () { - handler = (methodCall) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - (await flutterBluePlus.getBondedDevices()).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getBondedDevices(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'getBondedDevices', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getPhySupport', - () { - final result = PhySupport( - le2M: false, - leCoded: false, - ); - - setUp( - () { - handler = (methodCall) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - (await flutterBluePlus.getPhySupport()).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getPhySupport(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'getPhySupport', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'getSystemDevices', - () { - final result = BmDevicesList( - devices: [], - ); - - setUp( - () { - handler = (methodCall) { - return Future.value(result.toMap()); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - (await flutterBluePlus.getSystemDevices()).toMap(), - equals(result.toMap()), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.getSystemDevices(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'getSystemDevices', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'isSupported', - () { - final result = true; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.isSupported(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.isSupported(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'isSupported', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'readCharacteristic', - () { - test( - 'invokes the method', - () async { - final request = BmReadCharacteristicRequest( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - ); - - await flutterBluePlus.readCharacteristic(request); - - expect( - log, - orderedEquals([ - isMethodCall( - 'readCharacteristic', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'readDescriptor', - () { - test( - 'invokes the method', - () async { - final request = BmReadDescriptorRequest( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - ); - - await flutterBluePlus.readDescriptor(request); - - expect( - log, - orderedEquals([ - isMethodCall( - 'readDescriptor', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'readRssi', - () { - test( - 'invokes the method', - () async { - final device = DeviceIdentifier(''); - - await flutterBluePlus.readRssi(device); - - expect( - log, - orderedEquals([ - isMethodCall( - 'readRssi', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'removeBond', - () { - final result = true; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final device = DeviceIdentifier(''); - - expect( - await flutterBluePlus.removeBond(device), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final device = DeviceIdentifier(''); - - await flutterBluePlus.removeBond(device); - - expect( - log, - orderedEquals([ - isMethodCall( - 'removeBond', - arguments: device.str, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'requestConnectionPriority', - () { - test( - 'invokes the method', - () async { - final request = BmConnectionPriorityRequest( - remoteId: DeviceIdentifier(''), - connectionPriority: BmConnectionPriorityEnum.balanced, - ); - - await flutterBluePlus.requestConnectionPriority(request); - - expect( - log, - orderedEquals([ - isMethodCall( - 'requestConnectionPriority', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'requestMtu', - () { - test( - 'invokes the method', - () async { - final request = BmMtuChangeRequest( - remoteId: DeviceIdentifier(''), - mtu: 0, - ); - - await flutterBluePlus.requestMtu(request); - - expect( - log, - orderedEquals([ - isMethodCall( - 'requestMtu', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'setLogLevel', - () { - test( - 'invokes the method', - () async { - final level = LogLevel.none; - - await flutterBluePlus.setLogLevel(level); - - expect( - log, - orderedEquals([ - isMethodCall( - 'setLogLevel', - arguments: level.index, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'setNotifyValue', - () { - final result = true; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - final request = BmSetNotifyValueRequest( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ); - - expect( - await flutterBluePlus.setNotifyValue(request), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - final request = BmSetNotifyValueRequest( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - forceIndications: false, - enable: false, - ); - - await flutterBluePlus.setNotifyValue(request); - - expect( - log, - orderedEquals([ - isMethodCall( - 'setNotifyValue', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'setOptions', - () { - test( - 'invokes the method', - () async { - final options = Options( - showPowerAlert: false, - ); - - await flutterBluePlus.setOptions(options); - - expect( - log, - orderedEquals([ - isMethodCall( - 'setOptions', - arguments: options.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'setPreferredPhy', - () { - test( - 'invokes the method', - () async { - final preferredPhy = BmPreferredPhy( - remoteId: DeviceIdentifier(''), - txPhy: 0, - rxPhy: 0, - phyOptions: 0, - ); - - await flutterBluePlus.setPreferredPhy(preferredPhy); - - expect( - log, - orderedEquals([ - isMethodCall( - 'setPreferredPhy', - arguments: preferredPhy.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'startScan', - () { - test( - 'invokes the method', - () async { - final settings = BmScanSettings( - withServices: [], - withRemoteIds: [], - withNames: [], - withKeywords: [], - withMsd: [], - withServiceData: [], - continuousUpdates: false, - continuousDivisor: 1, - androidLegacy: false, - androidScanMode: 0, - androidUsesFineLocation: false, - ); - - await flutterBluePlus.startScan(settings); - - expect( - log, - orderedEquals([ - isMethodCall( - 'startScan', - arguments: settings.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'stopScan', - () { - test( - 'invokes the method', - () async { - await flutterBluePlus.stopScan(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'stopScan', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'turnOff', - () { - test( - 'invokes the method', - () async { - await flutterBluePlus.turnOff(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'turnOff', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'turnOn', - () { - final result = true; - - setUp( - () { - handler = (methodCall) { - return Future.value(result); - }; - }, - ); - - tearDown( - () { - handler = null; - }, - ); - - test( - 'deserializes the result', - () async { - expect( - await flutterBluePlus.turnOn(), - equals(result), - ); - }, - ); - - test( - 'invokes the method', - () async { - await flutterBluePlus.turnOn(); - - expect( - log, - orderedEquals([ - isMethodCall( - 'turnOn', - arguments: null, - ), - ]), - ); - }, - ); - }, - ); - - group( - 'writeCharacteristic', - () { - test( - 'invokes the method', - () async { - final request = BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ); - - await flutterBluePlus.writeCharacteristic(request); - - expect( - log, - orderedEquals([ - isMethodCall( - 'writeCharacteristic', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - group( - 'writeDescriptor', - () { - test( - 'invokes the method', - () async { - final request = BmWriteDescriptorRequest( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - descriptorUuid: Guid('0102'), - value: [], - ); - - await flutterBluePlus.writeDescriptor(request); - - expect( - log, - orderedEquals([ - isMethodCall( - 'writeDescriptor', - arguments: request.toMap(), - ), - ]), - ); - }, - ); - }, - ); - - setUp( - () { - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler( - MethodChannel('flutter_blue_plus/methods'), - (methodCall) { - log.add(methodCall); - - return handler?.call(methodCall); - }, - ); - }, - ); - - tearDown( - () { - log.clear(); - }, - ); - }, - ); -} From cc2f03e05c7440af81185159170eccdef453796e Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:48 +0100 Subject: [PATCH 71/90] Revert "refactor: update method channel implementation" This reverts commit ee9585a66ff31c85b398d45e0bd105a945d58891. --- .../flutter_blue_plus_platform_interface.dart | 2 - .../lib/src/common/enums/log_level.dart | 8 - .../lib/src/common/models/options.dart | 22 -- .../lib/src/flutter_blue_plus_platform.dart | 35 +- .../src/method_channel_flutter_blue_plus.dart | 320 +----------------- 5 files changed, 17 insertions(+), 370 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index b011abec..34e51c9a 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -8,10 +8,8 @@ export 'src/characteristic/models/bm_characteristic_properties.dart'; export 'src/characteristic/models/bm_read_characteristic_request.dart'; export 'src/characteristic/models/bm_set_notify_value_request.dart'; export 'src/characteristic/models/bm_write_characteristic_request.dart'; -export 'src/common/enums/log_level.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; -export 'src/common/models/options.dart'; export 'src/common/models/phy_support.dart'; export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; export 'src/descriptor/models/bm_descriptor_data.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart deleted file mode 100644 index ae462139..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/enums/log_level.dart +++ /dev/null @@ -1,8 +0,0 @@ -enum LogLevel { - none, // 0 - error, // 1 - warning, // 2 - info, // 3 - debug, // 4 - verbose, // 5 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart deleted file mode 100644 index fec83483..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/options.dart +++ /dev/null @@ -1,22 +0,0 @@ -class Options { - /// Whether to show the power alert (iOS & macOS only). i.e. CBCentralManagerOptionShowPowerAlertKey - final bool showPowerAlert; - - Options({ - required this.showPowerAlert, - }); - - factory Options.fromMap( - Map json, - ) { - return Options( - showPowerAlert: json['show_power_alert'], - ); - } - - Map toMap() { - return { - 'show_power_alert': showPowerAlert, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index 8947143c..e95d8317 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -4,9 +4,6 @@ import 'adapter/models/bm_bluetooth_adapter_state.dart'; import 'characteristic/models/bm_read_characteristic_request.dart'; import 'characteristic/models/bm_set_notify_value_request.dart'; import 'characteristic/models/bm_write_characteristic_request.dart'; -import 'common/enums/log_level.dart'; -import 'common/models/device_identifier.dart'; -import 'common/models/options.dart'; import 'common/models/phy_support.dart'; import 'descriptor/models/bm_read_descriptor_request.dart'; import 'descriptor/models/bm_write_descriptor_request.dart'; @@ -39,9 +36,9 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { _instance = instance; } - /// Clears the GATT cache for a [device]. + /// Clears the GATT cache for a [remoteId]. Future clearGattCache( - DeviceIdentifier device, + String remoteId, ) { throw UnimplementedError(); } @@ -62,33 +59,33 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Creates a bond to a [device]. + /// Creates a bond to a [remoteId]. /// /// Returns [true] if the bond state is changed. /// /// Implementations should call [OnBondStateChanged] with the changed bond state. Future createBond( - DeviceIdentifier device, + String remoteId, ) { throw UnimplementedError(); } - /// Disconnects from a [device]. + /// Disconnects from a [remoteId]. /// /// Returns [true] if the connection state is changed. /// /// Implementations should call [OnConnectionStateChanged] with the changed connection state. Future disconnect( - DeviceIdentifier device, + String remoteId, ) { throw UnimplementedError(); } - /// Discovers the services for a [device]. + /// Discovers the services for a [remoteId]. /// /// Implementations should call [OnDiscoveredServices] with the discovered services. Future discoverServices( - DeviceIdentifier device, + String remoteId, ) { throw UnimplementedError(); } @@ -108,9 +105,9 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Returns the bond state for a [device]. + /// Returns the bond state for a [remoteId]. Future getBondState( - DeviceIdentifier device, + String remoteId, ) { throw UnimplementedError(); } @@ -153,22 +150,22 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { throw UnimplementedError(); } - /// Reads the Received Signal Strength Indicator (RSSI) for a [device]. + /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. /// /// Implementations should call [OnReadRssi] with the read RSSI. Future readRssi( - DeviceIdentifier device, + String remoteId, ) { throw UnimplementedError(); } - /// Removes the bond to a [device]. + /// Removes the bond to a [remoteId]. /// /// Returns [true] if the bond state is changed. /// /// Implementations should call [OnBondStateChanged] with the changed bond state. Future removeBond( - DeviceIdentifier device, + String remoteId, ) { throw UnimplementedError(); } @@ -191,7 +188,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Sets the log level. Future setLogLevel( - LogLevel level, + int level, ) { throw UnimplementedError(); } @@ -209,7 +206,7 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { /// Sets the options. Future setOptions( - Options options, + Map options, ) { throw UnimplementedError(); } diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart index c734edfd..a2b8fc02 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart @@ -1,322 +1,4 @@ -import 'package:flutter/services.dart'; - -import 'adapter/models/bm_bluetooth_adapter_state.dart'; -import 'characteristic/models/bm_read_characteristic_request.dart'; -import 'characteristic/models/bm_set_notify_value_request.dart'; -import 'characteristic/models/bm_write_characteristic_request.dart'; -import 'common/enums/log_level.dart'; -import 'common/models/device_identifier.dart'; -import 'common/models/options.dart'; -import 'common/models/phy_support.dart'; -import 'descriptor/models/bm_read_descriptor_request.dart'; -import 'descriptor/models/bm_write_descriptor_request.dart'; -import 'device/models/bm_bond_state_response.dart'; -import 'device/models/bm_connect_request.dart'; -import 'device/models/bm_connection_priority_request.dart'; -import 'device/models/bm_devices_list.dart'; -import 'device/models/bm_mtu_change_request.dart'; -import 'device/models/bm_preferred_phy.dart'; import 'flutter_blue_plus_platform.dart'; -import 'scan/models/bm_scan_settings.dart'; - -const _channel = MethodChannel('flutter_blue_plus/methods'); /// An implementation of [FlutterBluePlusPlatform] that uses method channels. -class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform { - @override - Future clearGattCache( - DeviceIdentifier device, - ) async { - await _channel.invokeMethod( - 'clearGattCache', - device.str, - ); - } - - @override - Future connect( - BmConnectRequest request, - ) async { - final result = await _channel.invokeMethod( - 'connect', - request.toMap(), - ); - - return result!; - } - - @override - Future connectedCount() async { - final result = await _channel.invokeMethod( - 'connectedCount', - ); - - return result!; - } - - @override - Future createBond( - DeviceIdentifier device, - ) async { - final result = await _channel.invokeMethod( - 'createBond', - device.str, - ); - - return result!; - } - - @override - Future disconnect( - DeviceIdentifier device, - ) async { - final result = await _channel.invokeMethod( - 'disconnect', - device.str, - ); - - return result!; - } - - @override - Future discoverServices( - DeviceIdentifier device, - ) async { - await _channel.invokeMethod( - 'discoverServices', - device.str, - ); - } - - @override - Future flutterRestart() async { - final result = await _channel.invokeMethod( - 'flutterRestart', - ); - - return result!; - } - - @override - Future getAdapterName() async { - final result = await _channel.invokeMethod( - 'getAdapterName', - ); - - return result!; - } - - @override - Future getAdapterState() async { - final result = await _channel.invokeMethod>( - 'getAdapterState', - ); - - return BmBluetoothAdapterState.fromMap(result!); - } - - @override - Future getBondState( - DeviceIdentifier device, - ) async { - final result = await _channel.invokeMethod>( - 'getBondState', - device.str, - ); - - return BmBondStateResponse.fromMap(result!); - } - - @override - Future getBondedDevices() async { - final result = await _channel.invokeMethod>( - 'getBondedDevices', - ); - - return BmDevicesList.fromMap(result!); - } - - @override - Future getPhySupport() async { - final result = await _channel.invokeMethod>( - 'getPhySupport', - ); - - return PhySupport.fromMap(result!); - } - - @override - Future getSystemDevices() async { - final result = await _channel.invokeMethod>( - 'getSystemDevices', - ); - - return BmDevicesList.fromMap(result!); - } - - @override - Future isSupported() async { - final result = await _channel.invokeMethod( - 'isSupported', - ); - - return result!; - } - - @override - Future readCharacteristic( - BmReadCharacteristicRequest request, - ) async { - await _channel.invokeMethod( - 'readCharacteristic', - request.toMap(), - ); - } - - @override - Future readDescriptor( - BmReadDescriptorRequest request, - ) async { - await _channel.invokeMethod( - 'readDescriptor', - request.toMap(), - ); - } - - @override - Future readRssi( - DeviceIdentifier device, - ) async { - await _channel.invokeMethod( - 'readRssi', - device.str, - ); - } - - @override - Future removeBond( - DeviceIdentifier device, - ) async { - final result = await _channel.invokeMethod( - 'removeBond', - device.str, - ); - - return result!; - } - - @override - Future requestConnectionPriority( - BmConnectionPriorityRequest request, - ) async { - await _channel.invokeMethod( - 'requestConnectionPriority', - request.toMap(), - ); - } - - @override - Future requestMtu( - BmMtuChangeRequest request, - ) async { - await _channel.invokeMethod( - 'requestMtu', - request.toMap(), - ); - } - - @override - Future setLogLevel( - LogLevel level, - ) async { - await _channel.invokeMethod( - 'setLogLevel', - level.index, - ); - } - - @override - Future setNotifyValue( - BmSetNotifyValueRequest request, - ) async { - final result = await _channel.invokeMethod( - 'setNotifyValue', - request.toMap(), - ); - - return result!; - } - - @override - Future setOptions( - Options options, - ) async { - await _channel.invokeMethod( - 'setOptions', - options.toMap(), - ); - } - - @override - Future setPreferredPhy( - BmPreferredPhy preferredPhy, - ) async { - await _channel.invokeMethod( - 'setPreferredPhy', - preferredPhy.toMap(), - ); - } - - @override - Future startScan( - BmScanSettings settings, - ) async { - await _channel.invokeMethod( - 'startScan', - settings.toMap(), - ); - } - - @override - Future stopScan() async { - await _channel.invokeMethod( - 'stopScan', - ); - } - - @override - Future turnOff() async { - await _channel.invokeMethod( - 'turnOff', - ); - } - - @override - Future turnOn() async { - final result = await _channel.invokeMethod( - 'turnOn', - ); - - return result!; - } - - @override - Future writeCharacteristic( - BmWriteCharacteristicRequest request, - ) async { - await _channel.invokeMethod( - 'writeCharacteristic', - request.toMap(), - ); - } - - @override - Future writeDescriptor( - BmWriteDescriptorRequest request, - ) async { - await _channel.invokeMethod( - 'writeDescriptor', - request.toMap(), - ); - } -} +class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform {} From 3e580803a4ea03355507838777751f8ab9424e6e Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:49 +0100 Subject: [PATCH 72/90] Revert "refactor: add method channel methods" This reverts commit 8fddb267cc8ba8936c96d108f5ffee6407ad671d. --- .../flutter_blue_plus_platform_interface.dart | 1 - .../lib/src/common/models/phy_support.dart | 28 -- .../lib/src/flutter_blue_plus_platform.dart | 242 ------------------ .../test/bm_scan_settings_test.dart | 12 +- 4 files changed, 6 insertions(+), 277 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 34e51c9a..0c92b73d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -10,7 +10,6 @@ export 'src/characteristic/models/bm_set_notify_value_request.dart'; export 'src/characteristic/models/bm_write_characteristic_request.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; -export 'src/common/models/phy_support.dart'; export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; export 'src/descriptor/models/bm_descriptor_data.dart'; export 'src/descriptor/models/bm_read_descriptor_request.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart deleted file mode 100644 index dc779840..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/phy_support.dart +++ /dev/null @@ -1,28 +0,0 @@ -class PhySupport { - /// High speed (PHY 2M) - final bool le2M; - - /// Long range (PHY codec) - final bool leCoded; - - PhySupport({ - required this.le2M, - required this.leCoded, - }); - - factory PhySupport.fromMap( - Map json, - ) { - return PhySupport( - le2M: json['le_2M'], - leCoded: json['le_coded'], - ); - } - - Map toMap() { - return { - 'le_2M': le2M, - 'le_coded': leCoded, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart index e95d8317..73e2b21c 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart @@ -1,20 +1,6 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'adapter/models/bm_bluetooth_adapter_state.dart'; -import 'characteristic/models/bm_read_characteristic_request.dart'; -import 'characteristic/models/bm_set_notify_value_request.dart'; -import 'characteristic/models/bm_write_characteristic_request.dart'; -import 'common/models/phy_support.dart'; -import 'descriptor/models/bm_read_descriptor_request.dart'; -import 'descriptor/models/bm_write_descriptor_request.dart'; -import 'device/models/bm_bond_state_response.dart'; -import 'device/models/bm_connect_request.dart'; -import 'device/models/bm_connection_priority_request.dart'; -import 'device/models/bm_devices_list.dart'; -import 'device/models/bm_mtu_change_request.dart'; -import 'device/models/bm_preferred_phy.dart'; import 'method_channel_flutter_blue_plus.dart'; -import 'scan/models/bm_scan_settings.dart'; /// The interface that implementations of flutter_blue_plus must implement. abstract class FlutterBluePlusPlatform extends PlatformInterface { @@ -35,232 +21,4 @@ abstract class FlutterBluePlusPlatform extends PlatformInterface { PlatformInterface.verify(instance, _token); _instance = instance; } - - /// Clears the GATT cache for a [remoteId]. - Future clearGattCache( - String remoteId, - ) { - throw UnimplementedError(); - } - - /// Connects to the device for a [request]. - /// - /// Returns [true] if the connection state is changed. - /// - /// Implementations should call [OnConnectionStateChanged] with the changed connection state. - Future connect( - BmConnectRequest request, - ) { - throw UnimplementedError(); - } - - /// Returns the number of connected devices. - Future connectedCount() { - throw UnimplementedError(); - } - - /// Creates a bond to a [remoteId]. - /// - /// Returns [true] if the bond state is changed. - /// - /// Implementations should call [OnBondStateChanged] with the changed bond state. - Future createBond( - String remoteId, - ) { - throw UnimplementedError(); - } - - /// Disconnects from a [remoteId]. - /// - /// Returns [true] if the connection state is changed. - /// - /// Implementations should call [OnConnectionStateChanged] with the changed connection state. - Future disconnect( - String remoteId, - ) { - throw UnimplementedError(); - } - - /// Discovers the services for a [remoteId]. - /// - /// Implementations should call [OnDiscoveredServices] with the discovered services. - Future discoverServices( - String remoteId, - ) { - throw UnimplementedError(); - } - - /// Returns the number of remaining connected devices after restarting Flutter. - Future flutterRestart() { - throw UnimplementedError(); - } - - /// Returns the adapter name. - Future getAdapterName() { - throw UnimplementedError(); - } - - /// Returns the adapter state. - Future getAdapterState() { - throw UnimplementedError(); - } - - /// Returns the bond state for a [remoteId]. - Future getBondState( - String remoteId, - ) { - throw UnimplementedError(); - } - - /// Returns the bonded devices. - Future getBondedDevices() { - throw UnimplementedError(); - } - - /// Returns the Physical Layer (PHY) support. - Future getPhySupport() { - throw UnimplementedError(); - } - - /// Returns the system devices. - Future getSystemDevices() { - throw UnimplementedError(); - } - - /// Returns [true] if Bluetooth is supported on the hardware. - Future isSupported() { - throw UnimplementedError(); - } - - /// Reads the characteristic for a [request]. - /// - /// Implementations should call [OnCharacteristicReceived] with the read characteristic. - Future readCharacteristic( - BmReadCharacteristicRequest request, - ) { - throw UnimplementedError(); - } - - /// Reads the descriptor for a [request]. - /// - /// Implementations should call [OnDescriptorRead] with the read descriptor. - Future readDescriptor( - BmReadDescriptorRequest request, - ) { - throw UnimplementedError(); - } - - /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. - /// - /// Implementations should call [OnReadRssi] with the read RSSI. - Future readRssi( - String remoteId, - ) { - throw UnimplementedError(); - } - - /// Removes the bond to a [remoteId]. - /// - /// Returns [true] if the bond state is changed. - /// - /// Implementations should call [OnBondStateChanged] with the changed bond state. - Future removeBond( - String remoteId, - ) { - throw UnimplementedError(); - } - - /// Requests a change to the connection priority for a [request]. - Future requestConnectionPriority( - BmConnectionPriorityRequest request, - ) { - throw UnimplementedError(); - } - - /// Requests a change to the Maximum Transmission Unit (MTU) for a [request]. - /// - /// Implementations should call [OnMtuChanged] with the changed MTU. - Future requestMtu( - BmMtuChangeRequest request, - ) { - throw UnimplementedError(); - } - - /// Sets the log level. - Future setLogLevel( - int level, - ) { - throw UnimplementedError(); - } - - /// Sets the notify value for a [request]. - /// - /// Returns [true] if the characteristic has a Client Characteristic Configuration Descriptor (CCCD). - /// - /// Implementations should call [OnDescriptorWritten] with the written CCCD. - Future setNotifyValue( - BmSetNotifyValueRequest request, - ) { - throw UnimplementedError(); - } - - /// Sets the options. - Future setOptions( - Map options, - ) { - throw UnimplementedError(); - } - - /// Sets the preferred Physical Layer (PHY). - Future setPreferredPhy( - BmPreferredPhy preferredPhy, - ) { - throw UnimplementedError(); - } - - /// Starts scanning for devices. - /// - /// Implementations should call [OnScanResponse] for each scanned device. - Future startScan( - BmScanSettings settings, - ) { - throw UnimplementedError(); - } - - /// Stops scanning for devices. - Future stopScan() { - throw UnimplementedError(); - } - - /// Turns off the adapter. - Future turnOff() { - throw UnimplementedError(); - } - - /// Turns on the adapter. - /// - /// Returns [true] if the power state is changed. - /// - /// Implementations should call [OnTurnOnResponse] with the power state. - Future turnOn() { - throw UnimplementedError(); - } - - /// Writes the characteristic for a [request]. - /// - /// Implementations should call [OnCharacteristicWritten] with the written characteristic. - Future writeCharacteristic( - BmWriteCharacteristicRequest request, - ) { - throw UnimplementedError(); - } - - /// Writes the descriptor for a [request]. - /// - /// Implementations should call [OnDescriptorWritten] with the written descriptor. - Future writeDescriptor( - BmWriteDescriptorRequest request, - ) { - throw UnimplementedError(); - } } diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart index fbbd6085..c89ab2fe 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart @@ -20,7 +20,7 @@ void main() { 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 1, + 'continuous_divisor': 0, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -42,7 +42,7 @@ void main() { 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 1, + 'continuous_divisor': 0, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -64,7 +64,7 @@ void main() { 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 1, + 'continuous_divisor': 0, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -86,7 +86,7 @@ void main() { 'with_msd': [], 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 1, + 'continuous_divisor': 0, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -108,7 +108,7 @@ void main() { 'with_msd': null, 'with_service_data': [], 'continuous_updates': false, - 'continuous_divisor': 1, + 'continuous_divisor': 0, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, @@ -130,7 +130,7 @@ void main() { 'with_msd': [], 'with_service_data': null, 'continuous_updates': false, - 'continuous_divisor': 1, + 'continuous_divisor': 0, 'android_legacy': false, 'android_scan_mode': 0, 'android_uses_fine_location': false, From 357a10eb70adae66350f886286a5de4a6035cc5f Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:49 +0100 Subject: [PATCH 73/90] Revert "test: add device models" This reverts commit 1f2dd10d8e097e0b309dc303fe431a1e6fadc0c5. --- .../flutter_blue_plus_platform_interface.dart | 14 --- .../device/models/bm_bluetooth_device.dart | 2 +- .../test/bm_bond_state_response_test.dart | 104 ------------------ .../bm_connection_priority_request_test.dart | 60 ---------- .../bm_connection_state_response_test.dart | 60 ---------- .../test/bm_devices_list_test.dart | 26 ----- .../test/bm_mtu_changed_response_test.dart | 62 ----------- .../test/bm_read_rssi_result_test.dart | 62 ----------- 8 files changed, 1 insertion(+), 389 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 0c92b73d..9c51b49d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -14,20 +14,6 @@ export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; export 'src/descriptor/models/bm_descriptor_data.dart'; export 'src/descriptor/models/bm_read_descriptor_request.dart'; export 'src/descriptor/models/bm_write_descriptor_request.dart'; -export 'src/device/enums/bm_bond_state_enum.dart'; -export 'src/device/enums/bm_connection_priority_enum.dart'; -export 'src/device/enums/bm_connection_state_enum.dart'; -export 'src/device/models/bm_bluetooth_device.dart'; -export 'src/device/models/bm_bond_state_response.dart'; -export 'src/device/models/bm_connect_request.dart'; -export 'src/device/models/bm_connection_priority_request.dart'; -export 'src/device/models/bm_connection_state_response.dart'; -export 'src/device/models/bm_devices_list.dart'; -export 'src/device/models/bm_mtu_change_request.dart'; -export 'src/device/models/bm_mtu_changed_response.dart'; -export 'src/device/models/bm_name_changed.dart'; -export 'src/device/models/bm_preferred_phy.dart'; -export 'src/device/models/bm_read_rssi_result.dart'; export 'src/flutter_blue_plus_platform.dart'; export 'src/scan/models/bm_msd_filter.dart'; export 'src/scan/models/bm_scan_advertisement.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart index 73ccb88b..dd2bb684 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart @@ -6,7 +6,7 @@ class BmBluetoothDevice { BmBluetoothDevice({ required this.remoteId, - this.platformName, + required this.platformName, }); factory BmBluetoothDevice.fromMap( diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart deleted file mode 100644 index e03e9c5a..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bond_state_response_test.dart +++ /dev/null @@ -1,104 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBondStateResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the bond state property', - () { - expect( - BmBondStateResponse.fromMap({ - 'remote_id': '', - 'bond_state': 0, - }).bondState, - equals(BmBondStateEnum.none), - ); - }, - ); - - test( - 'deserializes the prev state property', - () { - expect( - BmBondStateResponse.fromMap({ - 'remote_id': '', - 'bond_state': 0, - 'prev_state': 0, - }).prevState, - equals(BmBondStateEnum.none), - ); - }, - ); - - test( - 'throws a range error if the bond state property index is out of range', - () { - expect( - () { - BmBondStateResponse.fromMap({ - 'remote_id': '', - 'bond_state': 3, - }); - }, - throwsRangeError, - ); - }, - ); - - test( - 'throws a range error if the prev state property index is out of range', - () { - expect( - () { - BmBondStateResponse.fromMap({ - 'remote_id': '', - 'bond_state': 0, - 'prev_state': 3, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the bond state property', - () { - expect( - BmBondStateResponse( - remoteId: DeviceIdentifier(''), - bondState: BmBondStateEnum.none, - ).toMap(), - containsPair('bond_state', 0), - ); - }, - ); - - test( - 'serializes the prev state property', - () { - expect( - BmBondStateResponse( - remoteId: DeviceIdentifier(''), - bondState: BmBondStateEnum.none, - prevState: BmBondStateEnum.none, - ).toMap(), - containsPair('prev_state', 0), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart deleted file mode 100644 index 03ed371f..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_connection_priority_request_test.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmConnectionPriorityRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the connection priority property', - () { - expect( - BmConnectionPriorityRequest.fromMap({ - 'remote_id': '', - 'connection_priority': 0, - }).connectionPriority, - equals(BmConnectionPriorityEnum.balanced), - ); - }, - ); - - test( - 'throws a range error if the connection priority property index is out of range', - () { - expect( - () { - BmConnectionPriorityRequest.fromMap({ - 'remote_id': '', - 'connection_priority': 3, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the connection priority property', - () { - expect( - BmConnectionPriorityRequest( - remoteId: DeviceIdentifier(''), - connectionPriority: BmConnectionPriorityEnum.balanced, - ).toMap(), - containsPair('connection_priority', 0), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart deleted file mode 100644 index c9425121..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_connection_state_response_test.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmConnectionStateResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the connection state property', - () { - expect( - BmConnectionStateResponse.fromMap({ - 'remote_id': '', - 'connection_state': 0, - }).connectionState, - equals(BmConnectionStateEnum.disconnected), - ); - }, - ); - - test( - 'throws a range error if the connection state property index is out of range', - () { - expect( - () { - BmConnectionStateResponse.fromMap({ - 'remote_id': '', - 'connection_state': 2, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the connection state property', - () { - expect( - BmConnectionStateResponse( - remoteId: DeviceIdentifier(''), - connectionState: BmConnectionStateEnum.disconnected, - ).toMap(), - containsPair('connection_state', 0), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart deleted file mode 100644 index e1edfa34..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_devices_list_test.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmDevicesList', - () { - group( - 'fromMap', - () { - test( - 'deserializes the devices property as [] if it is null', - () { - expect( - BmDevicesList.fromMap({ - 'devices': null, - }).devices, - isEmpty, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart deleted file mode 100644 index 4b92659e..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_mtu_changed_response_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmMtuChangedResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmMtuChangedResponse.fromMap({ - 'remote_id': '', - 'mtu': 0, - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmMtuChangedResponse.fromMap({ - 'remote_id': '', - 'mtu': 0, - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmMtuChangedResponse.fromMap({ - 'remote_id': '', - 'mtu': 0, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart deleted file mode 100644 index 851a4c10..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_read_rssi_result_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmReadRssiResult', - () { - group( - 'fromMap', - () { - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmReadRssiResult.fromMap({ - 'remote_id': '', - 'rssi': 0, - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmReadRssiResult.fromMap({ - 'remote_id': '', - 'rssi': 0, - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmReadRssiResult.fromMap({ - 'remote_id': '', - 'rssi': 0, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - }, - ); - }, - ); -} From 9bc94d0d384ad18a527dd0dee505d0814a9a97f8 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:49 +0100 Subject: [PATCH 74/90] Revert "test: add service models" This reverts commit d8b40d25fcbd9d6aa8c94fa924b2ddc4b066a85d. --- .../flutter_blue_plus_platform_interface.dart | 2 - .../service/models/bm_bluetooth_service.dart | 2 +- .../test/bm_bluetooth_service_test.dart | 46 ----------- .../test/bm_characteristic_data_test.dart | 2 +- .../test/bm_descriptor_data_test.dart | 2 +- .../bm_discover_services_result_test.dart | 78 ------------------- .../test/bm_msd_filter_test.dart | 4 +- .../test/bm_service_data_filter_test.dart | 4 +- .../bm_write_characteristic_request_test.dart | 2 +- .../bm_write_descriptor_request_test.dart | 2 +- 10 files changed, 9 insertions(+), 135 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 9c51b49d..3ba94ab5 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -20,5 +20,3 @@ export 'src/scan/models/bm_scan_advertisement.dart'; export 'src/scan/models/bm_scan_response.dart'; export 'src/scan/models/bm_scan_settings.dart'; export 'src/scan/models/bm_service_data_filter.dart'; -export 'src/service/models/bm_bluetooth_service.dart'; -export 'src/service/models/bm_discover_services_result.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart index 29aa7214..bffa8440 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart @@ -21,8 +21,8 @@ class BmBluetoothService { Map json, ) { return BmBluetoothService( - remoteId: DeviceIdentifier(json['remote_id']), serviceUuid: Guid(json['service_uuid']), + remoteId: DeviceIdentifier(json['remote_id']), isPrimary: json['is_primary'] == 1, characteristics: (json['characteristics'] as List?) ?.map((characteristic) => diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart deleted file mode 100644 index 6f1da7da..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_service_test.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBluetoothService', - () { - group( - 'fromMap', - () { - test( - 'deserializes the characteristics property as [] if it is null', - () { - expect( - BmBluetoothService.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': null, - 'included_services': [], - }).characteristics, - isEmpty, - ); - }, - ); - - test( - 'deserializes the included services property as [] if it is null', - () { - expect( - BmBluetoothService.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'is_primary': 1, - 'characteristics': [], - 'included_services': null, - }).includedServices, - isEmpty, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart index eadc64fe..97da4cf2 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -107,7 +107,7 @@ void main() { ); test( - 'deserializes the value property', + 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', () { expect( BmCharacteristicData.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart index 183f5a2f..e069df29 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart @@ -112,7 +112,7 @@ void main() { ); test( - 'deserializes the value property', + 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', () { expect( BmDescriptorData.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart deleted file mode 100644 index 7cf5894f..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_discover_services_result_test.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmDiscoverServicesResult', - () { - group( - 'fromMap', - () { - test( - 'deserializes the services property as [] if it is null', - () { - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': '', - 'services': null, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).services, - isEmpty, - ); - }, - ); - - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': '', - 'services': [], - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': '', - 'services': [], - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmDiscoverServicesResult.fromMap({ - 'remote_id': '', - 'services': [], - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart index de385abc..66fbd1f9 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart @@ -23,7 +23,7 @@ void main() { ); test( - 'deserializes the data property', + 'deserializes the data property as [0x01,0x02,0x03] if it is 010203', () { expect( BmMsdFilter.fromMap({ @@ -55,7 +55,7 @@ void main() { ); test( - 'deserializes the mask property', + 'deserializes the mask property as [0x01,0x02,0x03] if it is 010203', () { expect( BmMsdFilter.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart index 1eac1ef9..d64f6261 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart @@ -23,7 +23,7 @@ void main() { ); test( - 'deserializes the data property', + 'deserializes the data property as [0x01,0x02,0x03] if it is 010203', () { expect( BmServiceDataFilter.fromMap({ @@ -55,7 +55,7 @@ void main() { ); test( - 'deserializes the mask property', + 'deserializes the mask property as [0x01,0x02,0x03] if it is 010203', () { expect( BmServiceDataFilter.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart index 417274e2..522dece4 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart @@ -46,7 +46,7 @@ void main() { ); test( - 'deserializes the value property', + 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', () { expect( BmWriteCharacteristicRequest.fromMap({ diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart index d398ab6d..2b8726fc 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart @@ -46,7 +46,7 @@ void main() { ); test( - 'deserializes the value property', + 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', () { expect( BmWriteDescriptorRequest.fromMap({ From 6b1416ed388b9fe2dafa2b15eb2f351e8915c5f8 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:50 +0100 Subject: [PATCH 75/90] Revert "test: add scan models" This reverts commit 2085e10c3cdafd84c8cca301f877c1e861547d50. --- .../flutter_blue_plus_platform_interface.dart | 5 - .../scan/models/bm_scan_advertisement.dart | 8 +- .../lib/src/scan/models/bm_scan_settings.dart | 8 +- .../models/bm_discover_services_result.dart | 4 +- .../test/bm_characteristic_data_test.dart | 7 +- .../test/bm_descriptor_data_test.dart | 7 +- .../test/bm_msd_filter_test.dart | 78 ---------- .../test/bm_scan_advertisement_test.dart | 132 ---------------- .../test/bm_scan_response_test.dart | 74 --------- .../test/bm_scan_settings_test.dart | 146 ------------------ .../test/bm_service_data_filter_test.dart | 78 ---------- .../bm_write_characteristic_request_test.dart | 7 +- .../bm_write_descriptor_request_test.dart | 7 +- 13 files changed, 21 insertions(+), 540 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 3ba94ab5..2d98f842 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -15,8 +15,3 @@ export 'src/descriptor/models/bm_descriptor_data.dart'; export 'src/descriptor/models/bm_read_descriptor_request.dart'; export 'src/descriptor/models/bm_write_descriptor_request.dart'; export 'src/flutter_blue_plus_platform.dart'; -export 'src/scan/models/bm_msd_filter.dart'; -export 'src/scan/models/bm_scan_advertisement.dart'; -export 'src/scan/models/bm_scan_response.dart'; -export 'src/scan/models/bm_scan_settings.dart'; -export 'src/scan/models/bm_service_data_filter.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart index 5d0e3d89..21a2af2d 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart @@ -17,11 +17,11 @@ class BmScanAdvertisement { BmScanAdvertisement({ required this.remoteId, - this.platformName, - this.advName, + required this.platformName, + required this.advName, required this.connectable, - this.txPowerLevel, - this.appearance, + required this.txPowerLevel, + required this.appearance, required this.manufacturerData, required this.serviceData, required this.serviceUuids, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart index 0f18f305..a8d2cc4b 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart @@ -37,11 +37,9 @@ class BmScanSettings { ?.map((str) => Guid(str)) .toList() ?? [], - withRemoteIds: - (json['with_remote_ids'] as List?)?.cast() ?? [], - withNames: (json['with_names'] as List?)?.cast() ?? [], - withKeywords: - (json['with_keywords'] as List?)?.cast() ?? [], + withRemoteIds: json['with_remote_ids'], + withNames: json['with_names'], + withKeywords: json['with_keywords'], withMsd: (json['with_msd'] as List?) ?.map((manufacturerData) => BmMsdFilter.fromMap(manufacturerData)) .toList() ?? diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart index 5979e00c..f4bf85be 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart @@ -24,8 +24,8 @@ class BmDiscoverServicesResult { return BmDiscoverServicesResult( remoteId: DeviceIdentifier(json['remote_id']), services: (json['services'] as List?) - ?.map((service) => - BmBluetoothService.fromMap(service as Map)) + ?.map( + (e) => BmBluetoothService.fromMap(e as Map)) .toList() ?? [], success: success, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart index 97da4cf2..818c056e 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -107,7 +107,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the value property as [0x01,0x02] if it is 0102', () { expect( BmCharacteristicData.fromMap({ @@ -115,7 +115,7 @@ void main() { 'service_uuid': '0102', 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', - 'value': '010203', + 'value': '0102', 'success': 1, 'error_code': 0, 'error_string': '', @@ -123,7 +123,6 @@ void main() { orderedEquals([ 0x01, 0x02, - 0x03, ]), ); }, @@ -143,7 +142,7 @@ void main() { 'error_code': 0, 'error_string': '', }).value, - isEmpty, + orderedEquals([]), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart index e069df29..fffab80d 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart @@ -112,7 +112,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the value property as [0x01,0x02] if it is 0102', () { expect( BmDescriptorData.fromMap({ @@ -121,7 +121,7 @@ void main() { 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - 'value': '010203', + 'value': '0102', 'success': 1, 'error_code': 0, 'error_string': '', @@ -129,7 +129,6 @@ void main() { orderedEquals([ 0x01, 0x02, - 0x03, ]), ); }, @@ -150,7 +149,7 @@ void main() { 'error_code': 0, 'error_string': '', }).value, - isEmpty, + orderedEquals([]), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart deleted file mode 100644 index 66fbd1f9..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_msd_filter_test.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmMsdFilter', - () { - group( - 'fromMap', - () { - test( - 'deserializes the data property as null if it is null', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': null, - 'mask': null, - }).data, - isNull, - ); - }, - ); - - test( - 'deserializes the data property as [0x01,0x02,0x03] if it is 010203', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': '010203', - 'mask': null, - }).data, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - - test( - 'deserializes the mask property as null if it is null', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': null, - 'mask': null, - }).mask, - isNull, - ); - }, - ); - - test( - 'deserializes the mask property as [0x01,0x02,0x03] if it is 010203', - () { - expect( - BmMsdFilter.fromMap({ - 'manufacturer_id': 0, - 'data': null, - 'mask': '010203', - }).mask, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart deleted file mode 100644 index 2a55567b..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_advertisement_test.dart +++ /dev/null @@ -1,132 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmScanAdvertisement', - () { - group( - 'fromMap', - () { - test( - 'deserializes the manufacturer data property', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': '', - 'connectable': 1, - 'manufacturer_data': { - 1: '010203', - }, - 'service_data': {}, - 'service_uuids': [], - }).manufacturerData, - containsPair( - 1, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), - ), - ); - }, - ); - - test( - 'deserializes the manufacturer data property as {} if it is null', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': '', - 'connectable': 1, - 'manufacturer_data': null, - 'service_data': {}, - 'service_uuids': [], - }).manufacturerData, - isEmpty, - ); - }, - ); - - test( - 'deserializes the service data property', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': '', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': { - '0102': '010203', - }, - 'service_uuids': [], - }).serviceData, - containsPair( - Guid('0102'), - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), - ), - ); - }, - ); - - test( - 'deserializes the service data property as {} if it is null', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': '', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': null, - 'service_uuids': [], - }).serviceData, - isEmpty, - ); - }, - ); - - test( - 'deserializes the service uuids property', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': '', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': [ - '0102', - ], - }).serviceUuids, - orderedEquals([ - Guid('0102'), - ]), - ); - }, - ); - - test( - 'deserializes the service uuids property as [] if it is null', - () { - expect( - BmScanAdvertisement.fromMap({ - 'remote_id': '', - 'connectable': 1, - 'manufacturer_data': {}, - 'service_data': {}, - 'service_uuids': null, - }).serviceUuids, - isEmpty, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart deleted file mode 100644 index 8636986b..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_response_test.dart +++ /dev/null @@ -1,74 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmScanResponse', - () { - group( - 'fromMap', - () { - test( - 'deserializes the advertisements property as [] if it is null', - () { - expect( - BmScanResponse.fromMap({ - 'advertisements': null, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).advertisements, - isEmpty, - ); - }, - ); - - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmScanResponse.fromMap({ - 'advertisements': [], - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmScanResponse.fromMap({ - 'advertisements': [], - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmScanResponse.fromMap({ - 'advertisements': [], - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart deleted file mode 100644 index c89ab2fe..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_scan_settings_test.dart +++ /dev/null @@ -1,146 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmScanSettings', - () { - group( - 'fromMap', - () { - test( - 'deserializes the with services property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': null, - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 0, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withServices, - isEmpty, - ); - }, - ); - - test( - 'deserializes the with remote ids property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': null, - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 0, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withRemoteIds, - isEmpty, - ); - }, - ); - - test( - 'deserializes the with names property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': null, - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 0, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withNames, - isEmpty, - ); - }, - ); - - test( - 'deserializes the with keywords property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': null, - 'with_msd': [], - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 0, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withKeywords, - isEmpty, - ); - }, - ); - - test( - 'deserializes the with msd property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': null, - 'with_service_data': [], - 'continuous_updates': false, - 'continuous_divisor': 0, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withMsd, - isEmpty, - ); - }, - ); - - test( - 'deserializes the with service data property as [] if it is null', - () { - expect( - BmScanSettings.fromMap({ - 'with_services': [], - 'with_remote_ids': [], - 'with_names': [], - 'with_keywords': [], - 'with_msd': [], - 'with_service_data': null, - 'continuous_updates': false, - 'continuous_divisor': 0, - 'android_legacy': false, - 'android_scan_mode': 0, - 'android_uses_fine_location': false, - }).withServiceData, - isEmpty, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart deleted file mode 100644 index d64f6261..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_service_data_filter_test.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmServiceDataFilter', - () { - group( - 'fromMap', - () { - test( - 'deserializes the data property as [] if it is null', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': null, - 'mask': null, - }).data, - isEmpty, - ); - }, - ); - - test( - 'deserializes the data property as [0x01,0x02,0x03] if it is 010203', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': '010203', - 'mask': null, - }).data, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - - test( - 'deserializes the mask property as [] if it is null', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': null, - 'mask': null, - }).mask, - isEmpty, - ); - }, - ); - - test( - 'deserializes the mask property as [0x01,0x02,0x03] if it is 010203', - () { - expect( - BmServiceDataFilter.fromMap({ - 'service': '0102', - 'data': null, - 'mask': '010203', - }).mask, - orderedEquals([ - 0x01, - 0x02, - 0x03, - ]), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart index 522dece4..eafa787d 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart @@ -46,7 +46,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the value property as [0x01,0x02] if it is 0102', () { expect( BmWriteCharacteristicRequest.fromMap({ @@ -55,12 +55,11 @@ void main() { 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'write_type': 0, - 'value': '010203', + 'value': '0102', }).value, orderedEquals([ 0x01, 0x02, - 0x03, ]), ); }, @@ -78,7 +77,7 @@ void main() { 'write_type': 0, 'value': null, }).value, - isEmpty, + orderedEquals([]), ); }, ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart index 2b8726fc..5b8fac03 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart @@ -46,7 +46,7 @@ void main() { ); test( - 'deserializes the value property as [0x01,0x02,0x03] if it is 010203', + 'deserializes the value property as [0x01,0x02] if it is 0102', () { expect( BmWriteDescriptorRequest.fromMap({ @@ -55,12 +55,11 @@ void main() { 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'descriptor_uuid': '0102', - 'value': '010203', + 'value': '0102', }).value, orderedEquals([ 0x01, 0x02, - 0x03, ]), ); }, @@ -78,7 +77,7 @@ void main() { 'descriptor_uuid': '0102', 'value': null, }).value, - isEmpty, + orderedEquals([]), ); }, ); From b5eca40e4fdbda706362e2a0c9a349808a975a80 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:50 +0100 Subject: [PATCH 76/90] Revert "test: add descriptor models" This reverts commit 2c4f92a3b2eb16293c6eab7fecdfc833e78a67b1. --- .../flutter_blue_plus_platform_interface.dart | 4 - .../test/bm_characteristic_data_test.dart | 6 - .../test/bm_descriptor_data_test.dart | 160 ------------------ .../test/bm_read_descriptor_request_test.dart | 49 ------ .../bm_write_descriptor_request_test.dart | 88 ---------- 5 files changed, 307 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 2d98f842..39302ccf 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -10,8 +10,4 @@ export 'src/characteristic/models/bm_set_notify_value_request.dart'; export 'src/characteristic/models/bm_write_characteristic_request.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; -export 'src/descriptor/models/bm_bluetooth_descriptor.dart'; -export 'src/descriptor/models/bm_descriptor_data.dart'; -export 'src/descriptor/models/bm_read_descriptor_request.dart'; -export 'src/descriptor/models/bm_write_descriptor_request.dart'; export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart index 818c056e..36c255e7 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart @@ -116,9 +116,6 @@ void main() { 'secondary_service_uuid': '0102', 'characteristic_uuid': '0102', 'value': '0102', - 'success': 1, - 'error_code': 0, - 'error_string': '', }).value, orderedEquals([ 0x01, @@ -138,9 +135,6 @@ void main() { 'secondary_service_uuid': null, 'characteristic_uuid': '0102', 'value': null, - 'success': 1, - 'error_code': 0, - 'error_string': '', }).value, orderedEquals([]), ); diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart deleted file mode 100644 index fffab80d..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_descriptor_data_test.dart +++ /dev/null @@ -1,160 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmCharacteristicData', - () { - group( - 'fromMap', - () { - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the value property as [0x01,0x02] if it is 0102', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '0102', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).value, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the value property as [] if it is null', - () { - expect( - BmDescriptorData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': null, - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).value, - orderedEquals([]), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart deleted file mode 100644 index 1d600b87..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_read_descriptor_request_test.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmReadDescriptorRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmReadDescriptorRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart deleted file mode 100644 index 5b8fac03..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_descriptor_request_test.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmWriteDescriptorRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the value property as [0x01,0x02] if it is 0102', - () { - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': '0102', - }).value, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the value property as [] if it is null', - () { - expect( - BmWriteDescriptorRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'descriptor_uuid': '0102', - 'value': null, - }).value, - orderedEquals([]), - ); - }, - ); - }, - ); - }, - ); -} From 8c6987f7a4b5a47e0f65fed590dbf3835bb94642 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:50 +0100 Subject: [PATCH 77/90] Revert "test: add characteristic models" This reverts commit 52ada10f2c164d715dc771c19d99fafc30d3b8e1. --- .../flutter_blue_plus_platform_interface.dart | 7 - .../models/bm_bluetooth_characteristic.dart | 2 +- .../models/bm_characteristic_data.dart | 8 +- .../bm_bluetooth_characteristic_test.dart | 72 ----- .../test/bm_characteristic_data_test.dart | 147 ---------- .../bm_characteristic_properties_test.dart | 255 ------------------ .../bm_read_characteristic_request_test.dart | 47 ---- .../bm_set_notify_value_request_test.dart | 51 ---- .../test/bm_turn_on_response_test.dart | 14 +- .../bm_write_characteristic_request_test.dart | 146 ---------- 10 files changed, 5 insertions(+), 744 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 39302ccf..12ae90d8 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -1,13 +1,6 @@ export 'src/adapter/enums/bm_adapter_state_enum.dart'; export 'src/adapter/models/bm_bluetooth_adapter_state.dart'; export 'src/adapter/models/bm_turn_on_response.dart'; -export 'src/characteristic/enums/bm_write_type.dart'; -export 'src/characteristic/models/bm_bluetooth_characteristic.dart'; -export 'src/characteristic/models/bm_characteristic_data.dart'; -export 'src/characteristic/models/bm_characteristic_properties.dart'; -export 'src/characteristic/models/bm_read_characteristic_request.dart'; -export 'src/characteristic/models/bm_set_notify_value_request.dart'; -export 'src/characteristic/models/bm_write_characteristic_request.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart index 1fec7092..a1cbb6e5 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart @@ -14,7 +14,7 @@ class BmBluetoothCharacteristic { BmBluetoothCharacteristic({ required this.remoteId, required this.serviceUuid, - this.secondaryServiceUuid, + required this.secondaryServiceUuid, required this.characteristicUuid, required this.descriptors, required this.properties, diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart index 3e2a97e4..2b887108 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart @@ -27,8 +27,6 @@ class BmCharacteristicData { factory BmCharacteristicData.fromMap( Map json, ) { - final success = json['success'] == null || json['success'] != 0; - return BmCharacteristicData( remoteId: DeviceIdentifier(json['remote_id']), serviceUuid: Guid(json['service_uuid']), @@ -37,9 +35,9 @@ class BmCharacteristicData { : null, characteristicUuid: Guid(json['characteristic_uuid']), value: json['value'] != null ? hex.decode(json['value']) : [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', + success: json['success'] != 0, + errorCode: json['error_code'], + errorString: json['error_string'], ); } diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart deleted file mode 100644 index 3092b3b8..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_characteristic_test.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBluetoothCharacteristic', - () { - group( - 'fromMap', - () { - test( - 'deserializes the properties property properties as false if it is null', - () { - final properties = BmBluetoothCharacteristic.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'characteristic_uuid': '0102', - 'properties': null, - }).properties; - - expect(properties.broadcast, isFalse); - expect(properties.read, isFalse); - expect(properties.writeWithoutResponse, isFalse); - expect(properties.write, isFalse); - expect(properties.notify, isFalse); - expect(properties.indicate, isFalse); - expect(properties.authenticatedSignedWrites, isFalse); - expect(properties.extendedProperties, isFalse); - expect(properties.notifyEncryptionRequired, isFalse); - expect(properties.indicateEncryptionRequired, isFalse); - }, - ); - - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'properties': {}, - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmBluetoothCharacteristic.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'properties': {}, - }).secondaryServiceUuid, - isNull, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart deleted file mode 100644 index 36c255e7..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_data_test.dart +++ /dev/null @@ -1,147 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmCharacteristicData', - () { - group( - 'fromMap', - () { - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the success property as false if it is 0', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'value': '', - 'success': 0, - 'error_code': 0, - 'error_string': '', - }).success, - isFalse, - ); - }, - ); - - test( - 'deserializes the success property as true if it is null', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'value': '', - 'success': null, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the success property as true if it is not 0', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'value': '', - 'success': 1, - 'error_code': 0, - 'error_string': '', - }).success, - isTrue, - ); - }, - ); - - test( - 'deserializes the value property as [0x01,0x02] if it is 0102', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'value': '0102', - }).value, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the value property as [] if it is null', - () { - expect( - BmCharacteristicData.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'value': null, - }).value, - orderedEquals([]), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart deleted file mode 100644 index 4ede2c27..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_characteristic_properties_test.dart +++ /dev/null @@ -1,255 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmCharacteristicProperties', - () { - group( - 'fromMap', - () { - test( - 'deserializes the properties as false if they are not 1', - () { - final properties = BmCharacteristicProperties.fromMap({ - 'broadcast': 0, - 'read': 0, - 'write_without_response': 0, - 'write': 0, - 'notify': 0, - 'indicate': 0, - 'authenticated_signed_writes': 0, - 'extended_properties': 0, - 'notify_encryption_required': 0, - 'indicate_encryption_required': 0, - }); - - expect( - properties.broadcast, - isFalse, - ); - expect( - properties.read, - isFalse, - ); - expect( - properties.writeWithoutResponse, - isFalse, - ); - expect( - properties.write, - isFalse, - ); - expect( - properties.notify, - isFalse, - ); - expect( - properties.indicate, - isFalse, - ); - expect( - properties.authenticatedSignedWrites, - isFalse, - ); - expect( - properties.extendedProperties, - isFalse, - ); - expect( - properties.notifyEncryptionRequired, - isFalse, - ); - expect( - properties.indicateEncryptionRequired, - isFalse, - ); - }, - ); - - test( - 'deserializes the properties as true if they are 1', - () { - final properties = BmCharacteristicProperties.fromMap({ - 'broadcast': 1, - 'read': 1, - 'write_without_response': 1, - 'write': 1, - 'notify': 1, - 'indicate': 1, - 'authenticated_signed_writes': 1, - 'extended_properties': 1, - 'notify_encryption_required': 1, - 'indicate_encryption_required': 1, - }); - - expect( - properties.broadcast, - isTrue, - ); - expect( - properties.read, - isTrue, - ); - expect( - properties.writeWithoutResponse, - isTrue, - ); - expect( - properties.write, - isTrue, - ); - expect( - properties.notify, - isTrue, - ); - expect( - properties.indicate, - isTrue, - ); - expect( - properties.authenticatedSignedWrites, - isTrue, - ); - expect( - properties.extendedProperties, - isTrue, - ); - expect( - properties.notifyEncryptionRequired, - isTrue, - ); - expect( - properties.indicateEncryptionRequired, - isTrue, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the properties as 0 if they are false', - () { - final map = BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ).toMap(); - - expect( - map, - containsPair('broadcast', equals(0)), - ); - expect( - map, - containsPair('read', equals(0)), - ); - expect( - map, - containsPair('write_without_response', equals(0)), - ); - expect( - map, - containsPair('write', equals(0)), - ); - expect( - map, - containsPair('notify', equals(0)), - ); - expect( - map, - containsPair('indicate', equals(0)), - ); - expect( - map, - containsPair('authenticated_signed_writes', equals(0)), - ); - expect( - map, - containsPair('extended_properties', equals(0)), - ); - expect( - map, - containsPair('notify_encryption_required', equals(0)), - ); - expect( - map, - containsPair('indicate_encryption_required', equals(0)), - ); - }, - ); - - test( - 'serializes the properties as 1 if they are true', - () { - final map = BmCharacteristicProperties( - broadcast: true, - read: true, - writeWithoutResponse: true, - write: true, - notify: true, - indicate: true, - authenticatedSignedWrites: true, - extendedProperties: true, - notifyEncryptionRequired: true, - indicateEncryptionRequired: true, - ).toMap(); - - expect( - map, - containsPair('broadcast', equals(1)), - ); - expect( - map, - containsPair('read', equals(1)), - ); - expect( - map, - containsPair('write_without_response', equals(1)), - ); - expect( - map, - containsPair('write', equals(1)), - ); - expect( - map, - containsPair('notify', equals(1)), - ); - expect( - map, - containsPair('indicate', equals(1)), - ); - expect( - map, - containsPair('authenticated_signed_writes', equals(1)), - ); - expect( - map, - containsPair('extended_properties', equals(1)), - ); - expect( - map, - containsPair('notify_encryption_required', equals(1)), - ); - expect( - map, - containsPair('indicate_encryption_required', equals(1)), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart deleted file mode 100644 index f3f06fb6..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_read_characteristic_request_test.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmReadCharacteristicRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmReadCharacteristicRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmReadCharacteristicRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart deleted file mode 100644 index 2dcb0ae7..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_set_notify_value_request_test.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmSetNotifyValueRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmSetNotifyValueRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'force_indications': false, - 'enable': false, - }).secondaryServiceUuid, - isNull, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart index 1a7065bb..718ed80f 100644 --- a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart @@ -9,7 +9,7 @@ void main() { 'fromMap', () { test( - 'deserializes the user accepted property as false if the user accepted property is null', + 'initializes the user accepted property as false if the user accepted property is null', () { expect( BmTurnOnResponse.fromMap({ @@ -19,18 +19,6 @@ void main() { ); }, ); - - test( - 'deserializes the user accepted property as true if the user accepted property is true', - () { - expect( - BmTurnOnResponse.fromMap({ - 'user_accepted': true, - }).userAccepted, - isTrue, - ); - }, - ); }, ); }, diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart deleted file mode 100644 index eafa787d..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_write_characteristic_request_test.dart +++ /dev/null @@ -1,146 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmWriteCharacteristicRequest', - () { - group( - 'fromMap', - () { - test( - 'deserializes the secondary service uuid property as [0x01,0x02] if it is 0102', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 0, - 'value': '', - }).secondaryServiceUuid?.bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the secondary service uuid property as null if it is null', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'write_type': 0, - 'value': '', - }).secondaryServiceUuid, - isNull, - ); - }, - ); - - test( - 'deserializes the value property as [0x01,0x02] if it is 0102', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': '0102', - 'characteristic_uuid': '0102', - 'write_type': 0, - 'value': '0102', - }).value, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'deserializes the value property as [] if it is null', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'write_type': 0, - 'value': null, - }).value, - orderedEquals([]), - ); - }, - ); - - test( - 'deserializes the write type property', - () { - expect( - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'write_type': 0, - 'value': null, - }).writeType, - equals(BmWriteType.withResponse), - ); - }, - ); - - test( - 'throws a range error if the write type property index is out of range', - () { - expect( - () { - BmWriteCharacteristicRequest.fromMap({ - 'remote_id': '', - 'service_uuid': '0102', - 'secondary_service_uuid': null, - 'characteristic_uuid': '0102', - 'write_type': 2, - 'value': null, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the write type property', - () { - expect( - BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier(''), - serviceUuid: Guid('0102'), - characteristicUuid: Guid('0102'), - writeType: BmWriteType.withResponse, - allowLongWrite: false, - value: [], - ).toMap(), - containsPair('write_type', 0), - ); - }, - ); - }, - ); - }, - ); -} From 7819c94b612b6ee121ac73bd767c005e5e2bc0b7 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:51 +0100 Subject: [PATCH 78/90] Revert "test: add adapter models" This reverts commit f11da6113eefdfa721f49ee8eb98e84987135976. --- .../flutter_blue_plus_platform_interface.dart | 3 - .../test/bm_bluetooth_adapter_state_test.dart | 57 ------------------- .../test/bm_turn_on_response_test.dart | 26 --------- .../test/guid_test.dart | 4 +- 4 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index 12ae90d8..b4e9dad8 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -1,6 +1,3 @@ -export 'src/adapter/enums/bm_adapter_state_enum.dart'; -export 'src/adapter/models/bm_bluetooth_adapter_state.dart'; -export 'src/adapter/models/bm_turn_on_response.dart'; export 'src/common/models/device_identifier.dart'; export 'src/common/models/guid.dart'; export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart deleted file mode 100644 index eeca9a52..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_bluetooth_adapter_state_test.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmBluetoothAdapterState', - () { - group( - 'fromMap', - () { - test( - 'deserializes the adapter state property', - () { - expect( - BmBluetoothAdapterState.fromMap({ - 'adapter_state': 0, - }).adapterState, - equals(BmAdapterStateEnum.unknown), - ); - }, - ); - - test( - 'throws a range error if the adapter state property index is out of range', - () { - expect( - () { - BmBluetoothAdapterState.fromMap({ - 'adapter_state': 7, - }); - }, - throwsRangeError, - ); - }, - ); - }, - ); - - group( - 'toMap', - () { - test( - 'serializes the adapter state property', - () { - expect( - BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.unknown, - ).toMap(), - containsPair('adapter_state', 0), - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart b/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart deleted file mode 100644 index 718ed80f..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/bm_turn_on_response_test.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'BmTurnOnResponse', - () { - group( - 'fromMap', - () { - test( - 'initializes the user accepted property as false if the user accepted property is null', - () { - expect( - BmTurnOnResponse.fromMap({ - 'user_accepted': null, - }).userAccepted, - isFalse, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart index 14af0716..7c2708fa 100644 --- a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart +++ b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart @@ -89,7 +89,7 @@ void main() { ); test( - 'throws a format exception if the list is not 2 nor 4 nor 16 bytes in length', + 'throws an exception if the list is not 2 nor 4 nor 16 bytes in length', () { expect( () { @@ -192,7 +192,7 @@ void main() { ); test( - 'throws a format exception if the string is not 2 nor 4 nor 16 bytes in length', + 'throws an exception if the string is not 2 nor 4 nor 16 bytes in length', () { expect( () { From 16d3a80be851b973f9fe700ad7afc4bf0e25982f Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:51 +0100 Subject: [PATCH 79/90] Revert "refactor: add characteristic enums nd models" This reverts commit 7c1d7fc153c9f090e11b19ec8114447e5bd98533. --- .../characteristic/enums/bm_write_type.dart | 4 -- .../models/bm_bluetooth_characteristic.dart | 65 ------------------- .../models/bm_characteristic_data.dart | 56 ---------------- .../models/bm_characteristic_properties.dart | 57 ---------------- .../bm_read_characteristic_request.dart | 38 ----------- .../models/bm_set_notify_value_request.dart | 46 ------------- .../bm_write_characteristic_request.dart | 53 --------------- 7 files changed, 319 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart deleted file mode 100644 index 2ffb5318..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/enums/bm_write_type.dart +++ /dev/null @@ -1,4 +0,0 @@ -enum BmWriteType { - withResponse, // 0 - withoutResponse, // 1 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart deleted file mode 100644 index a1cbb6e5..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_bluetooth_characteristic.dart +++ /dev/null @@ -1,65 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; -import '../../descriptor/models/bm_bluetooth_descriptor.dart'; -import 'bm_characteristic_properties.dart'; - -class BmBluetoothCharacteristic { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - List descriptors; - BmCharacteristicProperties properties; - - BmBluetoothCharacteristic({ - required this.remoteId, - required this.serviceUuid, - required this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptors, - required this.properties, - }); - - factory BmBluetoothCharacteristic.fromMap( - Map json, - ) { - return BmBluetoothCharacteristic( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptors: (json['descriptors'] as List?) - ?.map((descriptor) => BmBluetoothDescriptor.fromMap(descriptor)) - .toList() ?? - [], - properties: json['properties'] != null - ? BmCharacteristicProperties.fromMap(json['properties']) - : BmCharacteristicProperties( - broadcast: false, - read: false, - writeWithoutResponse: false, - write: false, - notify: false, - indicate: false, - authenticatedSignedWrites: false, - extendedProperties: false, - notifyEncryptionRequired: false, - indicateEncryptionRequired: false, - ), - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptors': - descriptors.map((descriptor) => descriptor.toMap()).toList(), - 'properties': properties.toMap(), - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart deleted file mode 100644 index 2b887108..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_data.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'package:convert/convert.dart'; - -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmCharacteristicData { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final List value; - final bool success; - final int errorCode; - final String errorString; - - BmCharacteristicData({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.value, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmCharacteristicData.fromMap( - Map json, - ) { - return BmCharacteristicData( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - success: json['success'] != 0, - errorCode: json['error_code'], - errorString: json['error_string'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'value': hex.encode(value), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart deleted file mode 100644 index 0204ab0f..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_characteristic_properties.dart +++ /dev/null @@ -1,57 +0,0 @@ -class BmCharacteristicProperties { - bool broadcast; - bool read; - bool writeWithoutResponse; - bool write; - bool notify; - bool indicate; - bool authenticatedSignedWrites; - bool extendedProperties; - bool notifyEncryptionRequired; - bool indicateEncryptionRequired; - - BmCharacteristicProperties({ - required this.broadcast, - required this.read, - required this.writeWithoutResponse, - required this.write, - required this.notify, - required this.indicate, - required this.authenticatedSignedWrites, - required this.extendedProperties, - required this.notifyEncryptionRequired, - required this.indicateEncryptionRequired, - }); - - factory BmCharacteristicProperties.fromMap( - Map json, - ) { - return BmCharacteristicProperties( - broadcast: json['broadcast'] == 1, - read: json['read'] == 1, - writeWithoutResponse: json['write_without_response'] == 1, - write: json['write'] == 1, - notify: json['notify'] == 1, - indicate: json['indicate'] == 1, - authenticatedSignedWrites: json['authenticated_signed_writes'] == 1, - extendedProperties: json['extended_properties'] == 1, - notifyEncryptionRequired: json['notify_encryption_required'] == 1, - indicateEncryptionRequired: json['indicate_encryption_required'] == 1, - ); - } - - Map toMap() { - return { - 'broadcast': broadcast ? 1 : 0, - 'read': read ? 1 : 0, - 'write_without_response': writeWithoutResponse ? 1 : 0, - 'write': write ? 1 : 0, - 'notify': notify ? 1 : 0, - 'indicate': indicate ? 1 : 0, - 'authenticated_signed_writes': authenticatedSignedWrites ? 1 : 0, - 'extended_properties': extendedProperties ? 1 : 0, - 'notify_encryption_required': notifyEncryptionRequired ? 1 : 0, - 'indicate_encryption_required': indicateEncryptionRequired ? 1 : 0, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart deleted file mode 100644 index 3638432a..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_read_characteristic_request.dart +++ /dev/null @@ -1,38 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmReadCharacteristicRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - - BmReadCharacteristicRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - }); - - factory BmReadCharacteristicRequest.fromMap( - Map json, - ) { - return BmReadCharacteristicRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart deleted file mode 100644 index 6bc2315e..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_set_notify_value_request.dart +++ /dev/null @@ -1,46 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmSetNotifyValueRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final bool forceIndications; - final bool enable; - - BmSetNotifyValueRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.forceIndications, - required this.enable, - }); - - factory BmSetNotifyValueRequest.fromMap( - Map json, - ) { - return BmSetNotifyValueRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - forceIndications: json['force_indications'], - enable: json['enable'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'force_indications': forceIndications, - 'enable': enable, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart deleted file mode 100644 index e516eb13..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/characteristic/models/bm_write_characteristic_request.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:convert/convert.dart'; - -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; -import '../enums/bm_write_type.dart'; - -class BmWriteCharacteristicRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final BmWriteType writeType; - final bool allowLongWrite; - final List value; - - BmWriteCharacteristicRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.writeType, - required this.allowLongWrite, - required this.value, - }); - - factory BmWriteCharacteristicRequest.fromMap( - Map json, - ) { - return BmWriteCharacteristicRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - writeType: BmWriteType.values[json['write_type'] as int], - allowLongWrite: json['allow_long_write'] != 0, - value: json['value'] != null ? hex.decode(json['value']) : [], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'write_type': writeType.index, - 'allow_long_write': allowLongWrite ? 1 : 0, - 'value': hex.encode(value), - }; - } -} From a6ebdf5c3ed091ca08b9537d39bc40bfbfefced1 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:51 +0100 Subject: [PATCH 80/90] Revert "refactor: add descriptor models" This reverts commit f99870647bcc5df7d6cf22cbb8a211699331e582. --- .../models/bm_bluetooth_descriptor.dart | 36 ----------- .../descriptor/models/bm_descriptor_data.dart | 62 ------------------- .../models/bm_read_descriptor_request.dart | 42 ------------- .../models/bm_write_descriptor_request.dart | 48 -------------- 4 files changed, 188 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart deleted file mode 100644 index 344124b5..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_bluetooth_descriptor.dart +++ /dev/null @@ -1,36 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmBluetoothDescriptor { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - - BmBluetoothDescriptor({ - required this.remoteId, - required this.serviceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - }); - - factory BmBluetoothDescriptor.fromMap( - Map json, - ) { - return BmBluetoothDescriptor( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart deleted file mode 100644 index 7eb0a236..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_descriptor_data.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:convert/convert.dart'; - -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmDescriptorData { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - final List value; - final bool success; - final int errorCode; - final String errorString; - - BmDescriptorData({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - required this.value, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmDescriptorData.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmDescriptorData( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - 'value': hex.encode(value), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart deleted file mode 100644 index b6ec526e..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_read_descriptor_request.dart +++ /dev/null @@ -1,42 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmReadDescriptorRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - - BmReadDescriptorRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - }); - - factory BmReadDescriptorRequest.fromMap( - Map json, - ) { - return BmReadDescriptorRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart deleted file mode 100644 index b5449818..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/descriptor/models/bm_write_descriptor_request.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'package:convert/convert.dart'; - -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmWriteDescriptorRequest { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - final Guid? secondaryServiceUuid; - final Guid characteristicUuid; - final Guid descriptorUuid; - final List value; - - BmWriteDescriptorRequest({ - required this.remoteId, - required this.serviceUuid, - this.secondaryServiceUuid, - required this.characteristicUuid, - required this.descriptorUuid, - required this.value, - }); - - factory BmWriteDescriptorRequest.fromMap( - Map json, - ) { - return BmWriteDescriptorRequest( - remoteId: DeviceIdentifier(json['remote_id']), - serviceUuid: Guid(json['service_uuid']), - secondaryServiceUuid: json['secondary_service_uuid'] != null - ? Guid(json['secondary_service_uuid']) - : null, - characteristicUuid: Guid(json['characteristic_uuid']), - descriptorUuid: Guid(json['descriptor_uuid']), - value: json['value'] != null ? hex.decode(json['value']) : [], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'secondary_service_uuid': secondaryServiceUuid?.str, - 'characteristic_uuid': characteristicUuid.str, - 'descriptor_uuid': descriptorUuid.str, - 'value': hex.encode(value), - }; - } -} From 829538bddde9fbda3bf8a1fdc6b2a8185b5ce20e Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:51 +0100 Subject: [PATCH 81/90] Revert "refactor: add device enums and models" This reverts commit d7f41b4eb881b4d0bbc12232f97c7986bd33659e. --- .../src/device/enums/bm_bond_state_enum.dart | 5 -- .../enums/bm_connection_priority_enum.dart | 5 -- .../enums/bm_connection_state_enum.dart | 4 -- .../device/models/bm_bluetooth_device.dart | 27 ----------- .../device/models/bm_bond_state_response.dart | 34 ------------- .../src/device/models/bm_connect_request.dart | 27 ----------- .../bm_connection_priority_request.dart | 29 ----------- .../models/bm_connection_state_response.dart | 37 -------------- .../src/device/models/bm_devices_list.dart | 48 ------------------- .../device/models/bm_mtu_change_request.dart | 27 ----------- .../models/bm_mtu_changed_response.dart | 41 ---------------- .../src/device/models/bm_name_changed.dart | 27 ----------- .../src/device/models/bm_preferred_phy.dart | 35 -------------- .../device/models/bm_read_rssi_result.dart | 41 ---------------- 14 files changed, 387 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart deleted file mode 100644 index 4e9756b1..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_bond_state_enum.dart +++ /dev/null @@ -1,5 +0,0 @@ -enum BmBondStateEnum { - none, // 0 - bonding, // 1 - bonded, // 2 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart deleted file mode 100644 index e205abcb..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_priority_enum.dart +++ /dev/null @@ -1,5 +0,0 @@ -enum BmConnectionPriorityEnum { - balanced, // 0 - high, // 1 - lowPower, // 2 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart deleted file mode 100644 index e254b9e9..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/enums/bm_connection_state_enum.dart +++ /dev/null @@ -1,4 +0,0 @@ -enum BmConnectionStateEnum { - disconnected, // 0 - connected, // 1 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart deleted file mode 100644 index dd2bb684..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bluetooth_device.dart +++ /dev/null @@ -1,27 +0,0 @@ -import '../../common/models/device_identifier.dart'; - -class BmBluetoothDevice { - DeviceIdentifier remoteId; - String? platformName; - - BmBluetoothDevice({ - required this.remoteId, - required this.platformName, - }); - - factory BmBluetoothDevice.fromMap( - Map json, - ) { - return BmBluetoothDevice( - remoteId: DeviceIdentifier(json['remote_id']), - platformName: json['platform_name'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'platform_name': platformName, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart deleted file mode 100644 index c2258855..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_bond_state_response.dart +++ /dev/null @@ -1,34 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import '../enums/bm_bond_state_enum.dart'; - -class BmBondStateResponse { - final DeviceIdentifier remoteId; - final BmBondStateEnum bondState; - final BmBondStateEnum? prevState; - - BmBondStateResponse({ - required this.remoteId, - required this.bondState, - this.prevState, - }); - - factory BmBondStateResponse.fromMap( - Map json, - ) { - return BmBondStateResponse( - remoteId: DeviceIdentifier(json['remote_id']), - bondState: BmBondStateEnum.values[json['bond_state'] as int], - prevState: json['prev_state'] != null - ? BmBondStateEnum.values[json['prev_state'] as int] - : null, - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'bond_state': bondState.index, - 'prev_state': prevState?.index, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart deleted file mode 100644 index ad0407d8..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connect_request.dart +++ /dev/null @@ -1,27 +0,0 @@ -import '../../common/models/device_identifier.dart'; - -class BmConnectRequest { - DeviceIdentifier remoteId; - bool autoConnect; - - BmConnectRequest({ - required this.remoteId, - required this.autoConnect, - }); - - factory BmConnectRequest.fromMap( - Map json, - ) { - return BmConnectRequest( - remoteId: DeviceIdentifier(json['remote_id']), - autoConnect: json['auto_connect'] == 1, - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'auto_connect': autoConnect ? 1 : 0, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart deleted file mode 100644 index d9d0c1da..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_priority_request.dart +++ /dev/null @@ -1,29 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import '../enums/bm_connection_priority_enum.dart'; - -class BmConnectionPriorityRequest { - final DeviceIdentifier remoteId; - final BmConnectionPriorityEnum connectionPriority; - - BmConnectionPriorityRequest({ - required this.remoteId, - required this.connectionPriority, - }); - - factory BmConnectionPriorityRequest.fromMap( - Map json, - ) { - return BmConnectionPriorityRequest( - remoteId: DeviceIdentifier(json['remote_id']), - connectionPriority: - BmConnectionPriorityEnum.values[json['connection_priority'] as int], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'connection_priority': connectionPriority.index, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart deleted file mode 100644 index 084deb10..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_connection_state_response.dart +++ /dev/null @@ -1,37 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import '../enums/bm_connection_state_enum.dart'; - -class BmConnectionStateResponse { - final DeviceIdentifier remoteId; - final BmConnectionStateEnum connectionState; - final int? disconnectReasonCode; - final String? disconnectReasonString; - - BmConnectionStateResponse({ - required this.remoteId, - required this.connectionState, - this.disconnectReasonCode, - this.disconnectReasonString, - }); - - factory BmConnectionStateResponse.fromMap( - Map json, - ) { - return BmConnectionStateResponse( - remoteId: DeviceIdentifier(json['remote_id']), - connectionState: - BmConnectionStateEnum.values[json['connection_state'] as int], - disconnectReasonCode: json['disconnect_reason_code'], - disconnectReasonString: json['disconnect_reason_string'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'connection_state': connectionState.index, - 'disconnectReasonCode': disconnectReasonCode, - 'disconnectReasonString': disconnectReasonString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart deleted file mode 100644 index 4fa7460e..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_devices_list.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'dart:collection'; - -import 'bm_bluetooth_device.dart'; - -class BmDevicesList extends ListBase { - final List devices; - - BmDevicesList({ - required this.devices, - }); - - factory BmDevicesList.fromMap( - Map json, - ) { - return BmDevicesList( - devices: (json['devices'] as List?) - ?.map((device) => BmBluetoothDevice.fromMap(device)) - .toList() ?? - [], - ); - } - - Map toMap() { - return { - 'devices': devices.map((device) => device.toMap()).toList(), - }; - } - - @override - int get length { - return devices.length; - } - - @override - set length(int newLength) { - devices.length = newLength; - } - - @override - BmBluetoothDevice operator [](int index) { - return devices[index]; - } - - @override - void operator []=(int index, BmBluetoothDevice value) { - devices[index] = value; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart deleted file mode 100644 index 86138397..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_change_request.dart +++ /dev/null @@ -1,27 +0,0 @@ -import '../../common/models/device_identifier.dart'; - -class BmMtuChangeRequest { - final DeviceIdentifier remoteId; - final int mtu; - - BmMtuChangeRequest({ - required this.remoteId, - required this.mtu, - }); - - factory BmMtuChangeRequest.fromMap( - Map json, - ) { - return BmMtuChangeRequest( - remoteId: DeviceIdentifier(json['remote_id']), - mtu: json['mtu'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'mtu': mtu, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart deleted file mode 100644 index ccd1c2ff..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_mtu_changed_response.dart +++ /dev/null @@ -1,41 +0,0 @@ -import '../../common/models/device_identifier.dart'; - -class BmMtuChangedResponse { - final DeviceIdentifier remoteId; - final int mtu; - final bool success; - final int errorCode; - final String errorString; - - BmMtuChangedResponse({ - required this.remoteId, - required this.mtu, - this.success = true, - this.errorCode = 0, - this.errorString = '', - }); - - factory BmMtuChangedResponse.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmMtuChangedResponse( - remoteId: DeviceIdentifier(json['remote_id']), - mtu: json['mtu'], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'mtu': mtu, - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart deleted file mode 100644 index 75fe4d8b..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_name_changed.dart +++ /dev/null @@ -1,27 +0,0 @@ -import '../../common/models/device_identifier.dart'; - -class BmNameChanged { - DeviceIdentifier remoteId; - String name; - - BmNameChanged({ - required this.remoteId, - required this.name, - }); - - factory BmNameChanged.fromMap( - Map json, - ) { - return BmNameChanged( - remoteId: DeviceIdentifier(json['remote_id']), - name: json['name'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'name': name, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart deleted file mode 100644 index d2c0b630..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_preferred_phy.dart +++ /dev/null @@ -1,35 +0,0 @@ -import '../../common/models/device_identifier.dart'; - -class BmPreferredPhy { - final DeviceIdentifier remoteId; - final int txPhy; - final int rxPhy; - final int phyOptions; - - BmPreferredPhy({ - required this.remoteId, - required this.txPhy, - required this.rxPhy, - required this.phyOptions, - }); - - factory BmPreferredPhy.fromMap( - Map json, - ) { - return BmPreferredPhy( - remoteId: DeviceIdentifier(json['remote_id']), - txPhy: json['tx_phy'], - rxPhy: json['rx_phy'], - phyOptions: json['phy_options'], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'tx_phy': txPhy, - 'rx_phy': rxPhy, - 'phy_options': phyOptions, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart deleted file mode 100644 index 81aa5822..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/device/models/bm_read_rssi_result.dart +++ /dev/null @@ -1,41 +0,0 @@ -import '../../common/models/device_identifier.dart'; - -class BmReadRssiResult { - final DeviceIdentifier remoteId; - final int rssi; - final bool success; - final int errorCode; - final String errorString; - - BmReadRssiResult({ - required this.remoteId, - required this.rssi, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmReadRssiResult.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmReadRssiResult( - remoteId: DeviceIdentifier(json['remote_id']), - rssi: json['rssi'], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'rssi': rssi, - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} From ca7080ccd0c8cd418d76d4444170fcc40f794441 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:51 +0100 Subject: [PATCH 82/90] Revert "refactor: add scan models" This reverts commit 6e8b9a9e5ab585ffe2645b7228ec1d3ac589cffb. --- .../lib/src/scan/models/bm_msd_filter.dart | 31 -------- .../scan/models/bm_scan_advertisement.dart | 71 ----------------- .../lib/src/scan/models/bm_scan_response.dart | 42 ---------- .../lib/src/scan/models/bm_scan_settings.dart | 76 ------------------- .../scan/models/bm_service_data_filter.dart | 33 -------- 5 files changed, 253 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart deleted file mode 100644 index ecd77a4f..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_msd_filter.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:convert/convert.dart'; - -class BmMsdFilter { - int manufacturerId; - List? data; - List? mask; - - BmMsdFilter( - this.manufacturerId, - this.data, - this.mask, - ); - - factory BmMsdFilter.fromMap( - Map json, - ) { - return BmMsdFilter( - json['manufacturer_id'], - json['data'] != null ? hex.decode(json['data']) : null, - json['mask'] != null ? hex.decode(json['mask']) : null, - ); - } - - Map toMap() { - return { - 'manufacturer_id': manufacturerId, - 'data': data != null ? hex.encode(data!) : null, - 'mask': mask != null ? hex.encode(mask!) : null, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart deleted file mode 100644 index 21a2af2d..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_advertisement.dart +++ /dev/null @@ -1,71 +0,0 @@ -import 'package:convert/convert.dart'; - -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmScanAdvertisement { - final DeviceIdentifier remoteId; - final String? platformName; - final String? advName; - final bool connectable; - final int? txPowerLevel; - final int? appearance; // not supported on iOS / macOS - final Map> manufacturerData; - final Map> serviceData; - final List serviceUuids; - final int rssi; - - BmScanAdvertisement({ - required this.remoteId, - required this.platformName, - required this.advName, - required this.connectable, - required this.txPowerLevel, - required this.appearance, - required this.manufacturerData, - required this.serviceData, - required this.serviceUuids, - required this.rssi, - }); - - factory BmScanAdvertisement.fromMap( - Map json, - ) { - return BmScanAdvertisement( - remoteId: DeviceIdentifier(json['remote_id']), - platformName: json['platform_name'], - advName: json['adv_name'], - connectable: json['connectable'] == 1, - txPowerLevel: json['tx_power_level'], - appearance: json['appearance'], - manufacturerData: (json['manufacturer_data'] as Map?) - ?.map((key, value) => MapEntry(key, hex.decode(value))) ?? - {}, - serviceData: (json['service_data'] as Map?) - ?.map((key, value) => MapEntry(Guid(key), hex.decode(value))) ?? - {}, - serviceUuids: (json['service_uuids'] as List?) - ?.map((str) => Guid(str)) - .toList() ?? - [], - rssi: json['rssi'] ?? 0, - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'platform_name': platformName, - 'adv_name': advName, - 'connectable': connectable ? 1 : 0, - 'tx_power_level': txPowerLevel, - 'appearance': appearance, - 'manufacturer_data': manufacturerData - .map((key, value) => MapEntry(key, hex.encode(value))), - 'service_data': - serviceData.map((key, value) => MapEntry(key.str, hex.encode(value))), - 'service_uuids': serviceUuids.map((uuid) => uuid.str).toList(), - 'rssi': rssi, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart deleted file mode 100644 index 90ba85aa..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_response.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'bm_scan_advertisement.dart'; - -class BmScanResponse { - final List advertisements; - final bool success; - final int errorCode; - final String errorString; - - BmScanResponse({ - required this.advertisements, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmScanResponse.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmScanResponse( - advertisements: (json['advertisements'] as List?) - ?.map( - (advertisement) => BmScanAdvertisement.fromMap(advertisement)) - .toList() ?? - [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'advertisements': - advertisements.map((advertisement) => advertisement.toMap()), - 'success': success, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart deleted file mode 100644 index a8d2cc4b..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_scan_settings.dart +++ /dev/null @@ -1,76 +0,0 @@ -import '../../common/models/guid.dart'; -import 'bm_msd_filter.dart'; -import 'bm_service_data_filter.dart'; - -class BmScanSettings { - final List withServices; - final List withRemoteIds; - final List withNames; - final List withKeywords; - final List withMsd; - final List withServiceData; - final bool continuousUpdates; - final int continuousDivisor; - final bool androidLegacy; - final int androidScanMode; - final bool androidUsesFineLocation; - - BmScanSettings({ - required this.withServices, - required this.withRemoteIds, - required this.withNames, - required this.withKeywords, - required this.withMsd, - required this.withServiceData, - required this.continuousUpdates, - required this.continuousDivisor, - required this.androidLegacy, - required this.androidScanMode, - required this.androidUsesFineLocation, - }); - - factory BmScanSettings.fromMap( - Map json, - ) { - return BmScanSettings( - withServices: (json['with_services'] as List?) - ?.map((str) => Guid(str)) - .toList() ?? - [], - withRemoteIds: json['with_remote_ids'], - withNames: json['with_names'], - withKeywords: json['with_keywords'], - withMsd: (json['with_msd'] as List?) - ?.map((manufacturerData) => BmMsdFilter.fromMap(manufacturerData)) - .toList() ?? - [], - withServiceData: (json['with_service_data'] as List?) - ?.map((serviceData) => BmServiceDataFilter.fromMap(serviceData)) - .toList() ?? - [], - continuousUpdates: json['continuous_updates'], - continuousDivisor: json['continuous_divisor'], - androidLegacy: json['android_legacy'], - androidScanMode: json['android_scan_mode'], - androidUsesFineLocation: json['android_uses_fine_location'], - ); - } - - Map toMap() { - return { - 'with_services': withServices.map((uuid) => uuid.str).toList(), - 'with_remote_ids': withRemoteIds, - 'with_names': withNames, - 'with_keywords': withKeywords, - 'with_msd': - withMsd.map((manufacturerData) => manufacturerData.toMap()).toList(), - 'with_service_data': - withServiceData.map((serviceData) => serviceData.toMap()).toList(), - 'continuous_updates': continuousUpdates, - 'continuous_divisor': continuousDivisor, - 'android_legacy': androidLegacy, - 'android_scan_mode': androidScanMode, - 'android_uses_fine_location': androidUsesFineLocation, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart b/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart deleted file mode 100644 index 4f3a9d60..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/scan/models/bm_service_data_filter.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'package:convert/convert.dart'; - -import '../../common/models/guid.dart'; - -class BmServiceDataFilter { - Guid service; - List data; - List mask; - - BmServiceDataFilter( - this.service, - this.data, - this.mask, - ); - - factory BmServiceDataFilter.fromMap( - Map json, - ) { - return BmServiceDataFilter( - Guid(json['service']), - json['data'] != null ? hex.decode(json['data']) : [], - json['mask'] != null ? hex.decode(json['mask']) : [], - ); - } - - Map toMap() { - return { - 'service': service.str, - 'data': hex.encode(data), - 'mask': hex.encode(mask), - }; - } -} From 6c7310e4825ddc8a7e9666093a8e3cc7e43545a8 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:52 +0100 Subject: [PATCH 83/90] Revert "refactor: add service models" This reverts commit 514449b75143be45ef2dde404700cb6ea986df64. --- .../service/models/bm_bluetooth_service.dart | 53 ------------------- .../models/bm_discover_services_result.dart | 46 ---------------- 2 files changed, 99 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart deleted file mode 100644 index bffa8440..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_bluetooth_service.dart +++ /dev/null @@ -1,53 +0,0 @@ -import '../../characteristic/models/bm_bluetooth_characteristic.dart'; -import '../../common/models/device_identifier.dart'; -import '../../common/models/guid.dart'; - -class BmBluetoothService { - final DeviceIdentifier remoteId; - final Guid serviceUuid; - bool isPrimary; - List characteristics; - List includedServices; - - BmBluetoothService({ - required this.serviceUuid, - required this.remoteId, - required this.isPrimary, - required this.characteristics, - required this.includedServices, - }); - - factory BmBluetoothService.fromMap( - Map json, - ) { - return BmBluetoothService( - serviceUuid: Guid(json['service_uuid']), - remoteId: DeviceIdentifier(json['remote_id']), - isPrimary: json['is_primary'] == 1, - characteristics: (json['characteristics'] as List?) - ?.map((characteristic) => - BmBluetoothCharacteristic.fromMap(characteristic)) - .toList() ?? - [], - includedServices: (json['included_services'] as List?) - ?.map((includedService) => - BmBluetoothService.fromMap(includedService)) - .toList() ?? - [], - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'service_uuid': serviceUuid.str, - 'is_primary': isPrimary ? 1 : 0, - 'characteristics': characteristics - .map((characteristic) => characteristic.toMap()) - .toList(), - 'included_services': includedServices - .map((includedService) => includedService.toMap()) - .toList(), - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart b/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart deleted file mode 100644 index f4bf85be..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/service/models/bm_discover_services_result.dart +++ /dev/null @@ -1,46 +0,0 @@ -import '../../common/models/device_identifier.dart'; -import 'bm_bluetooth_service.dart'; - -class BmDiscoverServicesResult { - final DeviceIdentifier remoteId; - final List services; - final bool success; - final int errorCode; - final String errorString; - - BmDiscoverServicesResult({ - required this.remoteId, - required this.services, - required this.success, - required this.errorCode, - required this.errorString, - }); - - factory BmDiscoverServicesResult.fromMap( - Map json, - ) { - final success = json['success'] == null || json['success'] != 0; - - return BmDiscoverServicesResult( - remoteId: DeviceIdentifier(json['remote_id']), - services: (json['services'] as List?) - ?.map( - (e) => BmBluetoothService.fromMap(e as Map)) - .toList() ?? - [], - success: success, - errorCode: !success ? json['error_code'] : 0, - errorString: !success ? json['error_string'] : '', - ); - } - - Map toMap() { - return { - 'remote_id': remoteId.str, - 'services': services.map((service) => service.toMap()).toList(), - 'success': success ? 1 : 0, - 'error_code': errorCode, - 'error_string': errorString, - }; - } -} From f40c7f3f161312528d37462ddaa800bd41dadd05 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:52 +0100 Subject: [PATCH 84/90] Revert "refactor: add adapter enums and models" This reverts commit 67fcfd1f8664e180afc44ea4ec90e93a7e90bc34. --- .../adapter/enums/bm_adapter_state_enum.dart | 9 -------- .../models/bm_bluetooth_adapter_state.dart | 23 ------------------- .../adapter/models/bm_turn_on_response.dart | 21 ----------------- 3 files changed, 53 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart deleted file mode 100644 index 68ea06ab..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/enums/bm_adapter_state_enum.dart +++ /dev/null @@ -1,9 +0,0 @@ -enum BmAdapterStateEnum { - unknown, // 0 - unavailable, // 1 - unauthorized, // 2 - turningOn, // 3 - on, // 4 - turningOff, // 5 - off, // 6 -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart deleted file mode 100644 index 699b2a2d..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_bluetooth_adapter_state.dart +++ /dev/null @@ -1,23 +0,0 @@ -import '../enums/bm_adapter_state_enum.dart'; - -class BmBluetoothAdapterState { - BmAdapterStateEnum adapterState; - - BmBluetoothAdapterState({ - required this.adapterState, - }); - - factory BmBluetoothAdapterState.fromMap( - Map json, - ) { - return BmBluetoothAdapterState( - adapterState: BmAdapterStateEnum.values[json['adapter_state'] as int], - ); - } - - Map toMap() { - return { - 'adapter_state': adapterState.index, - }; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart b/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart deleted file mode 100644 index 524d25b6..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/adapter/models/bm_turn_on_response.dart +++ /dev/null @@ -1,21 +0,0 @@ -class BmTurnOnResponse { - bool userAccepted; - - BmTurnOnResponse({ - required this.userAccepted, - }); - - factory BmTurnOnResponse.fromMap( - Map json, - ) { - return BmTurnOnResponse( - userAccepted: json['user_accepted'] ?? false, - ); - } - - Map toMap() { - return { - 'user_accepted': userAccepted, - }; - } -} From d2cf50126499ec7bbc4bb6c01b8e418ac9208fc5 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:52 +0100 Subject: [PATCH 85/90] Revert "test: add common models" This reverts commit 31ee2a33db232843a328c09b73496c02a0ccafc6. --- .../flutter_blue_plus_platform_interface.dart | 2 - .../src/common/models/device_identifier.dart | 10 +- .../lib/src/common/models/guid.dart | 42 +-- .../test/device_identifier_test.dart | 79 ----- ...ter_blue_plus_platform_interface_test.dart | 0 .../test/guid_test.dart | 289 ------------------ 6 files changed, 16 insertions(+), 406 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart create mode 100644 packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/test/guid_test.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart index b4e9dad8..ea67d9fa 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -1,3 +1 @@ -export 'src/common/models/device_identifier.dart'; -export 'src/common/models/guid.dart'; export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart index 2d090b93..0836671f 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart @@ -13,13 +13,13 @@ class DeviceIdentifier { return str.toLowerCase().hashCode; } - @Deprecated('Use str instead') - String get id { - return str; - } - @override bool operator ==(other) { return other is DeviceIdentifier && hashCode == other.hashCode; } + + @Deprecated('Use str instead') + String get id { + return str; + } } diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart index 4a244914..d0dd9aae 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart @@ -13,19 +13,9 @@ class Guid { 'GUID must be 16, 32, or 128 bit.', ); - Guid.fromString(String input) - : bytes = _fromString(input), - assert( - _checkLen(hex.decode(input.replaceAll('-', '')).length), - 'GUID must be 16, 32, or 128 bit.', - ); + Guid.fromString(String input) : bytes = _fromString(input); - Guid(String input) - : bytes = _fromString(input), - assert( - _checkLen(hex.decode(input.replaceAll('-', '')).length), - 'GUID must be 16, 32, or 128 bit.', - ); + Guid(String input) : bytes = _fromString(input); static List _fromString(String input) { if (input.isEmpty) { @@ -91,27 +81,17 @@ class Guid { } @override - int get hashCode { - return str128.hashCode; - } - - @Deprecated('use str instead') - String get uuid { - return str; - } - - @Deprecated('use str128 instead') - String get uuid128 { - return str128; - } + String toString() => str; @override - operator ==(other) { - return other is Guid && hashCode == other.hashCode; - } + operator ==(other) => other is Guid && hashCode == other.hashCode; @override - String toString() { - return str; - } + int get hashCode => str128.hashCode; + + @Deprecated('use str128 instead') + String get uuid128 => str128; + + @Deprecated('use str instead') + String get uuid => str; } diff --git a/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart b/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart deleted file mode 100644 index b08a090d..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/device_identifier_test.dart +++ /dev/null @@ -1,79 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'DeviceIdentifier', - () { - group( - 'hashCode', - () { - test( - 'returns the hash code of a lower case identifier', - () { - expect( - DeviceIdentifier('str').hashCode, - equals('str'.hashCode), - ); - }, - ); - - test( - 'returns the hash code of a mixed case identifier', - () { - expect( - DeviceIdentifier('sTr').hashCode, - equals('str'.hashCode), - ); - }, - ); - - test( - 'returns the hash code of an upper case identifier', - () { - expect( - DeviceIdentifier('STR').hashCode, - equals('str'.hashCode), - ); - }, - ); - }, - ); - - group( - '==', - () { - test( - 'returns false if the identifiers are not equal', - () { - expect( - DeviceIdentifier('str1') == DeviceIdentifier('str2'), - isFalse, - ); - }, - ); - - test( - 'returns true if the identifiers are equal', - () { - expect( - DeviceIdentifier('str') == DeviceIdentifier('str'), - isTrue, - ); - }, - ); - - test( - 'returns true if the identifiers are equal ignoring case', - () { - expect( - DeviceIdentifier('str') == DeviceIdentifier('STR'), - isTrue, - ); - }, - ); - }, - ); - }, - ); -} diff --git a/packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart b/packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart new file mode 100644 index 00000000..e69de29b diff --git a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart b/packages/flutter_blue_plus_platform_interface/test/guid_test.dart deleted file mode 100644 index 7c2708fa..00000000 --- a/packages/flutter_blue_plus_platform_interface/test/guid_test.dart +++ /dev/null @@ -1,289 +0,0 @@ -import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group( - 'Guid', - () { - group( - 'fromBytes', - () { - test( - 'constructs an instance from a list of 2 bytes', - () { - expect( - Guid.fromBytes([ - 0x01, - 0x02, - ]).bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'constructs an instance from a list of 4 bytes', - () { - expect( - Guid.fromBytes([ - 0x01, - 0x02, - 0x03, - 0x04, - ]).bytes, - orderedEquals([ - 0x01, - 0x02, - 0x03, - 0x04, - ]), - ); - }, - ); - - test( - 'constructs an instance from a list of 16 bytes', - () { - expect( - Guid.fromBytes([ - 0x01, - 0x02, - 0x03, - 0x04, - 0x00, - 0x00, - 0x10, - 0x00, - 0x80, - 0x00, - 0x00, - 0x80, - 0x5F, - 0x9B, - 0x34, - 0xFB, - ]).bytes, - orderedEquals([ - 0x01, - 0x02, - 0x03, - 0x04, - 0x00, - 0x00, - 0x10, - 0x00, - 0x80, - 0x00, - 0x00, - 0x80, - 0x5F, - 0x9B, - 0x34, - 0xFB, - ]), - ); - }, - ); - - test( - 'throws an exception if the list is not 2 nor 4 nor 16 bytes in length', - () { - expect( - () { - Guid.fromBytes([ - 0x01, - 0x02, - 0x03, - ]); - }, - throwsFormatException, - ); - }, - ); - }, - ); - - group( - 'fromString', - () { - test( - 'constructs an instance from a string of 2 bytes', - () { - expect( - Guid.fromString('0102').bytes, - orderedEquals([ - 0x01, - 0x02, - ]), - ); - }, - ); - - test( - 'constructs an instance from a string of 4 bytes', - () { - expect( - Guid.fromString('01020304').bytes, - orderedEquals([ - 0x01, - 0x02, - 0x03, - 0x04, - ]), - ); - }, - ); - - test( - 'constructs an instance from a string of 16 bytes', - () { - expect( - Guid.fromString('0102030400001000800000805f9b34fb').bytes, - orderedEquals([ - 0x01, - 0x02, - 0x03, - 0x04, - 0x00, - 0x00, - 0x10, - 0x00, - 0x80, - 0x00, - 0x00, - 0x80, - 0x5F, - 0x9B, - 0x34, - 0xFB, - ]), - ); - }, - ); - - test( - 'constructs an instance from a uuid formatted string', - () { - expect( - Guid.fromString('01020304-0000-1000-8000-00805f9b34fb').bytes, - orderedEquals([ - 0x01, - 0x02, - 0x03, - 0x04, - 0x00, - 0x00, - 0x10, - 0x00, - 0x80, - 0x00, - 0x00, - 0x80, - 0x5F, - 0x9B, - 0x34, - 0xFB, - ]), - ); - }, - ); - - test( - 'throws an exception if the string is not 2 nor 4 nor 16 bytes in length', - () { - expect( - () { - Guid.fromString('010203'); - }, - throwsFormatException, - ); - }, - ); - }, - ); - }, - ); - - group( - 'str', - () { - test( - 'returns a string of 2 bytes if the list of bytes is 2 bytes in length', - () { - expect( - Guid('0102').str, - equals('0102'), - ); - }, - ); - - test( - 'returns a string of 4 bytes if the list of bytes is 4 bytes in length', - () { - expect( - Guid('01020304').str, - equals('01020304'), - ); - }, - ); - - test( - 'returns a string of 16 bytes if the list of bytes is 16 bytes in length and does not end with the suffix', - () { - expect( - Guid('01020304-0000-0000-0000-000000000000').str, - equals('01020304-0000-0000-0000-000000000000'), - ); - }, - ); - - test( - 'returns a string of 4 bytes if the list of bytes is 16 bytes in length and ends with the suffix', - () { - expect( - Guid('01020304-0000-1000-8000-00805f9b34fb').str, - equals('01020304'), - ); - }, - ); - }, - ); - - group( - 'str128', - () { - test( - 'returns a string of 16 bytes if the list of bytes is 2 bytes in length', - () { - expect( - Guid('0102').str128, - equals('00000102-0000-1000-8000-00805f9b34fb'), - ); - }, - ); - - test( - 'returns a string of 16 bytes if the list of bytes is 4 bytes in length', - () { - expect( - Guid('01020304').str128, - equals('01020304-0000-1000-8000-00805f9b34fb'), - ); - }, - ); - - test( - 'returns a string of 16 bytes if the list of bytes is 16 bytes in length', - () { - expect( - Guid('01020304-0000-1000-8000-00805f9b34fb').str128, - equals('01020304-0000-1000-8000-00805f9b34fb'), - ); - }, - ); - }, - ); -} From 2e2c4b8846e7bd82b97245b812d5de42b1973e34 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:52 +0100 Subject: [PATCH 86/90] Revert "refactor: add common models" This reverts commit 8990aa52311231d4b5eb63d1590c4920167d5c71. --- .../src/common/models/device_identifier.dart | 25 ----- .../lib/src/common/models/guid.dart | 97 ------------------- .../pubspec.yaml | 1 - 3 files changed, 123 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart deleted file mode 100644 index 0836671f..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/device_identifier.dart +++ /dev/null @@ -1,25 +0,0 @@ -class DeviceIdentifier { - final String str; - - DeviceIdentifier(this.str); - - @override - String toString() { - return str; - } - - @override - int get hashCode { - return str.toLowerCase().hashCode; - } - - @override - bool operator ==(other) { - return other is DeviceIdentifier && hashCode == other.hashCode; - } - - @Deprecated('Use str instead') - String get id { - return str; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart b/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart deleted file mode 100644 index d0dd9aae..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/common/models/guid.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'package:convert/convert.dart'; - -class Guid { - static const _suffix = '-0000-1000-8000-00805f9b34fb'; - - final List bytes; - - Guid.empty() : bytes = List.filled(16, 0); - - Guid.fromBytes(this.bytes) - : assert( - _checkLen(bytes.length), - 'GUID must be 16, 32, or 128 bit.', - ); - - Guid.fromString(String input) : bytes = _fromString(input); - - Guid(String input) : bytes = _fromString(input); - - static List _fromString(String input) { - if (input.isEmpty) { - return List.filled(16, 0); - } - - input = input.replaceAll('-', ''); - - List bytes; - try { - bytes = hex.decode(input); - } catch (e) { - throw FormatException('GUID not hex format: $input'); - } - - _checkLen(bytes.length); - - return bytes; - } - - static bool _checkLen(int len) { - if (!(len == 16 || len == 4 || len == 2)) { - throw FormatException( - 'GUID must be 16, 32, or 128 bit, yours: ${len * 8}-bit', - ); - } - return true; - } - - // 128-bit representation - String get str128 { - if (bytes.length == 2) { - // 16-bit uuid - return '0000${hex.encode(bytes)}$_suffix'.toLowerCase(); - } - if (bytes.length == 4) { - // 32-bit uuid - return '${hex.encode(bytes)}$_suffix'.toLowerCase(); - } - // 128-bit uuid - String one = hex.encode(bytes.sublist(0, 4)); - String two = hex.encode(bytes.sublist(4, 6)); - String three = hex.encode(bytes.sublist(6, 8)); - String four = hex.encode(bytes.sublist(8, 10)); - String five = hex.encode(bytes.sublist(10, 16)); - return '$one-$two-$three-$four-$five'.toLowerCase(); - } - - // shortest representation - String get str { - bool starts = str128.startsWith('0000'); - bool ends = str128.endsWith(_suffix); - if (starts && ends) { - // 16-bit - return str128.substring(4, 8); - } - if (ends) { - // 32-bit - return str128.substring(0, 8); - } - // 128-bit - return str128; - } - - @override - String toString() => str; - - @override - operator ==(other) => other is Guid && hashCode == other.hashCode; - - @override - int get hashCode => str128.hashCode; - - @Deprecated('use str128 instead') - String get uuid128 => str128; - - @Deprecated('use str instead') - String get uuid => str; -} diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index 1804d08c..7c1f2450 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -8,7 +8,6 @@ environment: flutter: ">=1.17.0" dependencies: - convert: ^3.0.0 flutter: sdk: flutter plugin_platform_interface: ^2.0.0 From 89c3db3812893c801f5744c85813ca38ee32c2e2 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:53 +0100 Subject: [PATCH 87/90] Revert "chore: add analysis options" This reverts commit 9b94209be5eab430d4a60dd7d838c1ec9795b02f. --- .../flutter_blue_plus_platform_interface/analysis_options.yaml | 1 - packages/flutter_blue_plus_platform_interface/pubspec.yaml | 1 - 2 files changed, 2 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/analysis_options.yaml diff --git a/packages/flutter_blue_plus_platform_interface/analysis_options.yaml b/packages/flutter_blue_plus_platform_interface/analysis_options.yaml deleted file mode 100644 index f9b30346..00000000 --- a/packages/flutter_blue_plus_platform_interface/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:flutter_lints/flutter.yaml diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml index 7c1f2450..cd882ac9 100644 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -13,6 +13,5 @@ dependencies: plugin_platform_interface: ^2.0.0 dev_dependencies: - flutter_lints: ^4.0.0 flutter_test: sdk: flutter From 04ebb62e3ede073da9ffc48a8e3bbc7f48bed51e Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 06:46:53 +0100 Subject: [PATCH 88/90] Revert "refactor: create platform interface package" This reverts commit 4870ffe5dc9b2882288c404a042b0e7885f04b4c. --- LICENSE | 4 +-- .../.gitignore | 29 ------------------- .../.metadata | 10 ------- .../LICENSE | 28 ------------------ .../README.md | 18 ------------ .../flutter_blue_plus_platform_interface.dart | 1 - .../lib/src/flutter_blue_plus_platform.dart | 24 --------------- .../src/method_channel_flutter_blue_plus.dart | 4 --- .../pubspec.yaml | 17 ----------- ...ter_blue_plus_platform_interface_test.dart | 0 10 files changed, 2 insertions(+), 133 deletions(-) delete mode 100644 packages/flutter_blue_plus_platform_interface/.gitignore delete mode 100644 packages/flutter_blue_plus_platform_interface/.metadata delete mode 100644 packages/flutter_blue_plus_platform_interface/LICENSE delete mode 100644 packages/flutter_blue_plus_platform_interface/README.md delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart delete mode 100644 packages/flutter_blue_plus_platform_interface/pubspec.yaml delete mode 100644 packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart diff --git a/LICENSE b/LICENSE index 5341ca7c..1b371f05 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger, Thomas Clark. +Copyright 2017-2023, Paul DeMarco, Bosko Popovic, & Charles Weinberger. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -25,4 +25,4 @@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/packages/flutter_blue_plus_platform_interface/.gitignore b/packages/flutter_blue_plus_platform_interface/.gitignore deleted file mode 100644 index ac5aa989..00000000 --- a/packages/flutter_blue_plus_platform_interface/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ -migrate_working_dir/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. -/pubspec.lock -**/doc/api/ -.dart_tool/ -build/ diff --git a/packages/flutter_blue_plus_platform_interface/.metadata b/packages/flutter_blue_plus_platform_interface/.metadata deleted file mode 100644 index 3bb479b8..00000000 --- a/packages/flutter_blue_plus_platform_interface/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" - channel: "beta" - -project_type: package diff --git a/packages/flutter_blue_plus_platform_interface/LICENSE b/packages/flutter_blue_plus_platform_interface/LICENSE deleted file mode 100644 index 5341ca7c..00000000 --- a/packages/flutter_blue_plus_platform_interface/LICENSE +++ /dev/null @@ -1,28 +0,0 @@ -Copyright 2017-2024, Paul DeMarco, Bosko Popovic, Charles Weinberger, Thomas Clark. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Buffalo PC Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_platform_interface/README.md b/packages/flutter_blue_plus_platform_interface/README.md deleted file mode 100644 index 1a9cac80..00000000 --- a/packages/flutter_blue_plus_platform_interface/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# flutter_blue_plus_platform_interface - -A common platform interface for the [`flutter_blue_plus`][1] plugin. - -This interface allows platform-specific implementations of the `flutter_blue_plus` -plugin, as well as the plugin itself, to ensure they are supporting the -same interface. - -# Usage - -To implement a new platform-specific implementation of `flutter_blue_plus`, extend -[`FlutterBluePlusPlatform`][2] with an implementation that performs the -platform-specific behavior, and when you register your plugin, set the default -`FlutterBluePlusPlatform` by calling -`FlutterBluePlusPlatform.instance = MyPlatformFlutterBluePlus()`. - -[1]: ../flutter_blue_plus -[2]: lib/flutter_blue_plus_platform_interface.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart deleted file mode 100644 index ea67d9fa..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart +++ /dev/null @@ -1 +0,0 @@ -export 'src/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart deleted file mode 100644 index 73e2b21c..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/flutter_blue_plus_platform.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -import 'method_channel_flutter_blue_plus.dart'; - -/// The interface that implementations of flutter_blue_plus must implement. -abstract class FlutterBluePlusPlatform extends PlatformInterface { - FlutterBluePlusPlatform() : super(token: _token); - - static final _token = Object(); - - static FlutterBluePlusPlatform _instance = MethodChannelFlutterBluePlus(); - - /// The default instance of [FlutterBluePlusPlatform] to use. - /// - /// Defaults to [MethodChannelFlutterBluePlus]. - static FlutterBluePlusPlatform get instance => _instance; - - /// Platform-specific plugins should set this with their own platform-specific - /// class that extends [FlutterBluePlusPlatform] when they register themselves. - static set instance(FlutterBluePlusPlatform instance) { - PlatformInterface.verify(instance, _token); - _instance = instance; - } -} diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart b/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart deleted file mode 100644 index a2b8fc02..00000000 --- a/packages/flutter_blue_plus_platform_interface/lib/src/method_channel_flutter_blue_plus.dart +++ /dev/null @@ -1,4 +0,0 @@ -import 'flutter_blue_plus_platform.dart'; - -/// An implementation of [FlutterBluePlusPlatform] that uses method channels. -class MethodChannelFlutterBluePlus extends FlutterBluePlusPlatform {} diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml deleted file mode 100644 index cd882ac9..00000000 --- a/packages/flutter_blue_plus_platform_interface/pubspec.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: flutter_blue_plus_platform_interface -description: A common platform interface for the flutter_blue_plus plugin. -version: 0.0.0 -homepage: https://github.com/boskokg/flutter_blue_plus - -environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=1.17.0" - -dependencies: - flutter: - sdk: flutter - plugin_platform_interface: ^2.0.0 - -dev_dependencies: - flutter_test: - sdk: flutter diff --git a/packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart b/packages/flutter_blue_plus_platform_interface/test/flutter_blue_plus_platform_interface_test.dart deleted file mode 100644 index e69de29b..00000000 From 37d96864ccd66ed07914f138cadf6f12a315433d Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Wed, 21 Aug 2024 08:18:50 +0100 Subject: [PATCH 89/90] refactor: create platform interface package --- .../.gitignore | 29 ++ .../.metadata | 10 + .../CHANGELOG.md | 3 + .../LICENSE | 28 ++ .../README.md | 18 ++ .../flutter_blue_plus_platform_interface.dart | 1 + .../flutter_blue_plus_platform.dart | 299 ++++++++++++++++++ .../pubspec.yaml | 16 + 8 files changed, 404 insertions(+) create mode 100644 packages/flutter_blue_plus_platform_interface/.gitignore create mode 100644 packages/flutter_blue_plus_platform_interface/.metadata create mode 100644 packages/flutter_blue_plus_platform_interface/CHANGELOG.md create mode 100644 packages/flutter_blue_plus_platform_interface/LICENSE create mode 100644 packages/flutter_blue_plus_platform_interface/README.md create mode 100644 packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart create mode 100644 packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart create mode 100644 packages/flutter_blue_plus_platform_interface/pubspec.yaml diff --git a/packages/flutter_blue_plus_platform_interface/.gitignore b/packages/flutter_blue_plus_platform_interface/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/packages/flutter_blue_plus_platform_interface/.metadata b/packages/flutter_blue_plus_platform_interface/.metadata new file mode 100644 index 00000000..3bb479b8 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" + channel: "beta" + +project_type: package diff --git a/packages/flutter_blue_plus_platform_interface/CHANGELOG.md b/packages/flutter_blue_plus_platform_interface/CHANGELOG.md new file mode 100644 index 00000000..0d8803f9 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +* Initial release. diff --git a/packages/flutter_blue_plus_platform_interface/LICENSE b/packages/flutter_blue_plus_platform_interface/LICENSE new file mode 100644 index 00000000..2658ac71 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/LICENSE @@ -0,0 +1,28 @@ +Copyright 2017-2024, Charles Weinberger & Thomas Clark. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Buffalo PC Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_platform_interface/README.md b/packages/flutter_blue_plus_platform_interface/README.md new file mode 100644 index 00000000..1a9cac80 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/README.md @@ -0,0 +1,18 @@ +# flutter_blue_plus_platform_interface + +A common platform interface for the [`flutter_blue_plus`][1] plugin. + +This interface allows platform-specific implementations of the `flutter_blue_plus` +plugin, as well as the plugin itself, to ensure they are supporting the +same interface. + +# Usage + +To implement a new platform-specific implementation of `flutter_blue_plus`, extend +[`FlutterBluePlusPlatform`][2] with an implementation that performs the +platform-specific behavior, and when you register your plugin, set the default +`FlutterBluePlusPlatform` by calling +`FlutterBluePlusPlatform.instance = MyPlatformFlutterBluePlus()`. + +[1]: ../flutter_blue_plus +[2]: lib/flutter_blue_plus_platform_interface.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart new file mode 100644 index 00000000..a3ecf666 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -0,0 +1 @@ +export 'src/platform_interface/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart new file mode 100644 index 00000000..9f376b76 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart @@ -0,0 +1,299 @@ +/// The interface that implementations of flutter_blue_plus must implement. +abstract base class FlutterBluePlusPlatform { + static FlutterBluePlusPlatform? _instance; + + /// The default instance of [FlutterBluePlusPlatform] to use. Throws an [UnsupportedError] if flutter_blue_plus is unsupported on this platform. + static FlutterBluePlusPlatform get instance { + if (_instance case final instance?) { + return instance; + } else { + throw UnsupportedError( + 'flutter_blue_plus is unsupported on this platform', + ); + } + } + + /// Platform-specific plugins should set this with their own platform-specific class that extends [FlutterBluePlusPlatform] when they register themselves. + static set instance( + FlutterBluePlusPlatform instance, + ) { + _instance = instance; + } + + /// Returns a stream of adapter state change events. + Stream get adapterStateChanges { + throw UnimplementedError(); + } + + /// Returns a stream of bond state change events. + Stream get bondStateChanges { + throw UnimplementedError(); + } + + /// Returns a stream of characteristic receive events. + Stream get characteristicReceives { + throw UnimplementedError(); + } + + /// Returns a stream of characteristic write events. + Stream get characteristicWrites { + throw UnimplementedError(); + } + + /// Returns a stream of connection state change events. + Stream get connectionStateChanges { + throw UnimplementedError(); + } + + /// Returns a stream of descriptor read events. + Stream get descriptorReads { + throw UnimplementedError(); + } + + /// Returns a stream of descriptor write events. + Stream get descriptorWrites { + throw UnimplementedError(); + } + + /// Returns a stream of Maximum Transmission Unit (MTU) change events. + Stream get mtuChanges { + throw UnimplementedError(); + } + + /// Returns a stream of name change events. + Stream get nameChanges { + throw UnimplementedError(); + } + + /// Returns a stream of Physical Layer (PHY) change events. + Stream get phyChanges { + throw UnimplementedError(); + } + + /// Returns a stream of Received Signal Strength Indicator (RSSI) read events. + Stream get rssiReads { + throw UnimplementedError(); + } + + /// Returns a stream of scan result events. + Stream get scanResults { + throw UnimplementedError(); + } + + /// Returns a stream of services change events. + Stream get servicesChanges { + throw UnimplementedError(); + } + + /// Returns a stream of services discover events. + Stream get servicesDiscovers { + throw UnimplementedError(); + } + + /// Clears the Generic Attribute Profile (GATT) cache for a [remoteId]. + Future clearGattCache( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Connects to a [remoteId]. + Future connect( + DeviceIdentifier remoteId, { + bool autoConnect = false, + }) { + throw UnimplementedError(); + } + + /// Creates a bond to a [remoteId]. + Future createBond( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Disconnects from a [remoteId]. + Future disconnect( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Discovers the services for a [remoteId]. + Future> discoverServices( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Returns the adapter name. + Future getAdapterName() { + throw UnimplementedError(); + } + + /// Returns the bonded devices. + Future> getBondedDevices() { + throw UnimplementedError(); + } + + /// Returns the Physical Layer (PHY) support. + Future getPhySupport() { + throw UnimplementedError(); + } + + /// Returns the system devices. + Future> getSystemDevices() { + throw UnimplementedError(); + } + + /// Returns [true] if Bluetooth is supported on the hardware. + Future isSupported() { + throw UnimplementedError(); + } + + /// Reads the value for a [characteristicUuid]. + /// + /// Returns the value as a list of bytes. + Future> readCharacteristic( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + ) { + throw UnimplementedError(); + } + + /// Reads the value for a [descriptorUuid]. + /// + /// Returns the value as a list of bytes. + Future> readDescriptor( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + Guid descriptorUuid, + ) { + throw UnimplementedError(); + } + + /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. + Future readRssi( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Removes the bond to a [remoteId]. + Future removeBond( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Requests a change to the connection priority for a [remoteId]. + Future requestConnectionPriority( + DeviceIdentifier remoteId, + ConnectionPriority connectionPriority, + ) { + throw UnimplementedError(); + } + + /// Requests a change to the Maximum Transmission Unit (MTU) for a [remoteId]. + Future requestMtu( + DeviceIdentifier remoteId, + int mtu, + ) { + throw UnimplementedError(); + } + + /// Sets the log level. + Future setLogLevel( + LogLevel level, + ) { + throw UnimplementedError(); + } + + /// Sets the notify and/or indicate value for a [characteristicUuid]. + Future setNotifyValue( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + bool enable, { + bool androidForceIndications = false, + }) { + throw UnimplementedError(); + } + + /// Sets the options. + Future setOptions({ + bool darwinShowPowerAlert = true, + }) { + throw UnimplementedError(); + } + + /// Sets the preferred Physical Layer (PHY). + Future setPreferredPhy( + int txPhy, + int rxPhy, + PhyCoding phyOptions, + ) { + throw UnimplementedError(); + } + + /// Starts scanning for devices. + Future startScan({ + List withServices = const [], + List withRemoteIds = const [], + List withNames = const [], + List withKeywords = const [], + List withMsd = const [], + List withServiceData = const [], + bool continuousUpdates = false, + int continuousDivisor = 1, + bool androidLegacy = false, + AndroidScanMode androidScanMode = AndroidScanMode.lowLatency, + bool androidUsesFineLocation = false, + }) { + throw UnimplementedError(); + } + + /// Stops scanning for devices. + Future stopScan() { + throw UnimplementedError(); + } + + /// Turns off the adapter. + Future turnOff() { + throw UnimplementedError(); + } + + /// Turns on the adapter. + Future turnOn() { + throw UnimplementedError(); + } + + /// Writes a [value] to a [characteristicUuid]. + /// + /// The [value] must be a list of bytes. + Future writeCharacteristic( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + List value, + WriteType writeType, { + bool allowLongWrite = false, + }) { + throw UnimplementedError(); + } + + /// Writes a [value] to a [descriptorUuid]. + /// + /// The [value] must be a list of bytes. + Future writeDescriptor( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + Guid descriptorUuid, + List value, + ) { + throw UnimplementedError(); + } +} diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml new file mode 100644 index 00000000..2911cec0 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -0,0 +1,16 @@ +name: flutter_blue_plus_platform_interface +description: A common platform interface for the flutter_blue_plus plugin. +version: 1.0.0 +homepage: https://github.com/chipweinberger/flutter_blue_plus + +environment: + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" + +dependencies: + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter From fd9f1ef08fc101f35cd41a5e28ad268a8bc39d68 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Thu, 22 Aug 2024 20:17:01 +0100 Subject: [PATCH 90/90] refactor: apply suggestions from code review --- .../flutter_blue_plus_platform.dart | 95 ++++++++++--------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart index 9f376b76..1833c1fb 100644 --- a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart +++ b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart @@ -20,73 +20,78 @@ abstract base class FlutterBluePlusPlatform { _instance = instance; } - /// Returns a stream of adapter state change events. - Stream get adapterStateChanges { + /// Returns a stream of adapter state changed events. + Stream get onAdapterStateChanged { throw UnimplementedError(); } - /// Returns a stream of bond state change events. - Stream get bondStateChanges { + /// Returns a stream of bond state changed events. + Stream get onBondStateChanged { throw UnimplementedError(); } - /// Returns a stream of characteristic receive events. - Stream get characteristicReceives { + /// Returns a stream of characteristic received events. + Stream get onCharacteristicReceived { throw UnimplementedError(); } - /// Returns a stream of characteristic write events. - Stream get characteristicWrites { + /// Returns a stream of characteristic written events. + Stream get onCharacteristicWritten { throw UnimplementedError(); } - /// Returns a stream of connection state change events. - Stream get connectionStateChanges { + /// Returns a stream of connection state changed events. + Stream get onConnectionStateChanged { throw UnimplementedError(); } /// Returns a stream of descriptor read events. - Stream get descriptorReads { + Stream get onDescriptorRead { throw UnimplementedError(); } - /// Returns a stream of descriptor write events. - Stream get descriptorWrites { + /// Returns a stream of descriptor written events. + Stream get onDescriptorWritten { throw UnimplementedError(); } - /// Returns a stream of Maximum Transmission Unit (MTU) change events. - Stream get mtuChanges { + /// Returns a stream of device scanned events. + Stream get onDeviceScanned { throw UnimplementedError(); } - /// Returns a stream of name change events. - Stream get nameChanges { + /// Returns a stream of Maximum Transmission Unit (MTU) changed events. + Stream get onMtuChanged { throw UnimplementedError(); } - /// Returns a stream of Physical Layer (PHY) change events. - Stream get phyChanges { + /// Returns a stream of name changed events. + Stream get onNameChanged { throw UnimplementedError(); } - /// Returns a stream of Received Signal Strength Indicator (RSSI) read events. - Stream get rssiReads { + /// Returns a stream of Physical Layer (PHY) changed events. + Stream get onPhyChanged { throw UnimplementedError(); } - /// Returns a stream of scan result events. - Stream get scanResults { + /// Returns a stream of Physical Layer (PHY) read events. + Stream get onPhyRead { + throw UnimplementedError(); + } + + /// Returns a stream of Received Signal Strength Indicator (RSSI) read events. + Stream get onRssiRead { throw UnimplementedError(); } - /// Returns a stream of services change events. - Stream get servicesChanges { + /// Returns a stream of services changed events. + Stream get onServicesChanged { throw UnimplementedError(); } - /// Returns a stream of services discover events. - Stream get servicesDiscovers { + /// Returns a stream of services discovered events. + Stream get onServicesDiscovered { throw UnimplementedError(); } @@ -136,11 +141,6 @@ abstract base class FlutterBluePlusPlatform { throw UnimplementedError(); } - /// Returns the Physical Layer (PHY) support. - Future getPhySupport() { - throw UnimplementedError(); - } - /// Returns the system devices. Future> getSystemDevices() { throw UnimplementedError(); @@ -157,8 +157,9 @@ abstract base class FlutterBluePlusPlatform { Future> readCharacteristic( DeviceIdentifier remoteId, Guid serviceUuid, - Guid characteristicUuid, - ) { + Guid characteristicUuid, { + Guid? secondaryServiceUuid, + }) { throw UnimplementedError(); } @@ -169,8 +170,14 @@ abstract base class FlutterBluePlusPlatform { DeviceIdentifier remoteId, Guid serviceUuid, Guid characteristicUuid, - Guid descriptorUuid, - ) { + Guid descriptorUuid, { + Guid? secondaryServiceUuid, + }) { + throw UnimplementedError(); + } + + /// Reads the transmitter and receiver Physical Layer (PHY). + Future readPhy() { throw UnimplementedError(); } @@ -197,7 +204,7 @@ abstract base class FlutterBluePlusPlatform { } /// Requests a change to the Maximum Transmission Unit (MTU) for a [remoteId]. - Future requestMtu( + Future requestMtu( DeviceIdentifier remoteId, int mtu, ) { @@ -218,6 +225,7 @@ abstract base class FlutterBluePlusPlatform { Guid characteristicUuid, bool enable, { bool androidForceIndications = false, + Guid? secondaryServiceUuid, }) { throw UnimplementedError(); } @@ -229,11 +237,10 @@ abstract base class FlutterBluePlusPlatform { throw UnimplementedError(); } - /// Sets the preferred Physical Layer (PHY). + /// Sets the preferred transmitter and receiver Physical Layer (PHY). Future setPreferredPhy( - int txPhy, - int rxPhy, - PhyCoding phyOptions, + Phy phy, + PhyOptions phyOptions, ) { throw UnimplementedError(); } @@ -280,6 +287,7 @@ abstract base class FlutterBluePlusPlatform { List value, WriteType writeType, { bool allowLongWrite = false, + Guid? secondaryServiceUuid, }) { throw UnimplementedError(); } @@ -292,8 +300,9 @@ abstract base class FlutterBluePlusPlatform { Guid serviceUuid, Guid characteristicUuid, Guid descriptorUuid, - List value, - ) { + List value, { + Guid? secondaryServiceUuid, + }) { throw UnimplementedError(); } }