tryRegisterConnectedDevice method
Tries to register a connected device which are available in this device's deviceRegistry as well as in the deploymentService.
Implementation
Future<void> tryRegisterConnectedDevice(DeviceDescriptor device) async {
assert(study != null,
"Cannot register a device without a valid study deployment. Call 'initialize()' first.");
String deviceType = device.type;
String? deviceRoleName = device.roleName;
// if this phone supports the device, register it locally
if (deviceRegistry.supportsDevice(deviceType)) {
await deviceRegistry.createDevice(deviceType);
}
// if successful, register at the deployment service
if (deviceRegistry.hasDevice(deviceType)) {
DeviceDataCollector deviceManager = deviceRegistry.getDevice(deviceType)!;
// ask the device manager for a unique id of the device
DeviceRegistration registration = DeviceRegistration(deviceManager.id);
deviceManager.deviceRegistration = registration;
deploymentStatus = (await deploymentService.registerDevice(
study!.studyDeploymentId,
deviceRoleName,
registration,
));
}
}