connect method

Ask this DeviceManager to start connecting to the device.

Returns the DeviceStatus of the device.

Implementation

@nonVirtual
Future<DeviceStatus> connect() async {
  info(
      '$runtimeType - Trying to connect to device of type: $typeName and id: $id');

  if (!isInitialized) {
    warning('$runtimeType has not been initialized - cannot connect to it.');
    return status;
  }

  if (!(await hasPermissions())) {
    warning('$runtimeType has not the permissions required to connect. '
        'Call requestPermissions() before calling connect.');
    return status;
  }

  try {
    status = await onConnect();
  } catch (error) {
    warning(
        '$runtimeType - Error connecting to device of type: $typeName. $error');
  }

  return status;
}