pair static method
Pair a device.
It throws error if pairing fails.
On Apple and Web, it only works on devices with encrypted characteristics.
It is advised to pass a pairingCommand with an encrypted read or write characteristic.
When not passing a pairingCommand, you should afterwards use isPaired with a pairingCommand
to verify the pairing state.
On Web/Windows and Web/Linux, it does not work for devices that use ConfirmOnly pairing.
Can throw PairingException, ConnectionException or PlatformException.
Implementation
static Future<void> pair(
String deviceId, {
BleCommand? pairingCommand,
Duration? timeout,
}) async {
if (BleCapabilities.hasSystemPairingApi) {
bool paired = await _bleCommandQueue.queueCommand(
() => _platform.pair(deviceId),
deviceId: deviceId,
timeout: timeout,
);
if (!paired) throw PairingException();
} else {
if (pairingCommand == null) {
UniversalLogger.logWarning("PairingCommand required to get result");
}
await _connectAndExecuteBleCommand(
deviceId,
pairingCommand,
timeout: timeout,
);
}
}