disconnect method

  1. @nonVirtual
Future<bool> disconnect()
inherited

Ask this DeviceManager to disconnect from the device.

All sampling on this device will be stopped before disconnection is initiate.

Returns true if successful, false if not.

Implementation

@nonVirtual
Future<bool> disconnect() async {
  bool success = false;
  if (status == DeviceStatus.connected || status == DeviceStatus.connecting) {
    info(
        '$runtimeType - Trying to disconnect from device of type: $typeName and id: $id');

    // Stop all sampling on this device.
    stop();

    success = await onDisconnect();
    status = (success) ? DeviceStatus.disconnected : DeviceStatus.error;

    return success;
  } else {
    warning(
        '$runtimeType is not connected, so nothing to disconnect from....');
    return true;
  }
}