connect method
Ask this DeviceManager to start connecting to the device. Returns the DeviceStatus of the device.
Implementation
@nonVirtual
Future<DeviceStatus> connect() async {
// Fast out if already connecting or connected to the device.
if (isConnecting) return status;
if (!isConfigured) {
warning('$runtimeType has not been configured - cannot connect to it.');
return status;
}
status = DeviceStatus.connecting;
if (!(await hasPermissions())) {
warning(
'$runtimeType has not the permissions required to connect. '
'Call requestPermissions() before calling connect.',
);
return status = DeviceStatus.disconnected;
}
info('$runtimeType - Trying to connect to device of type: $typeName.');
try {
status = await onConnect();
} catch (error) {
warning(
'$runtimeType - Error connecting to device of type: $typeName. $error',
);
status = DeviceStatus.disconnected;
}
return status;
}