tryRegisterConnectedDevice method

Future<void> tryRegisterConnectedDevice(
  1. DeviceConfiguration<DeviceRegistration> device
)
inherited

Tries to register a connected device which is available in this device's deviceRegistry in the deploymentService

Implementation

Future<void> tryRegisterConnectedDevice(DeviceConfiguration device) async {
  assert(
      study != null,
      "Cannot register a device without a valid study deployment. "
      "Call 'configure()' first.");

  String deviceType = device.type;
  String? deviceRoleName = device.roleName;

  if (deviceRegistry.hasDevice(deviceType)) {
    DeviceDataCollector deviceManager = deviceRegistry.getDevice(deviceType)!;

    // create a registration based on the device manager's unique id and name of the device
    var registration = deviceManager.configuration?.createRegistration(
      deviceId: deviceManager.id,
      deviceDisplayName: deviceManager.displayName,
    );

    if (registration != null) {
      try {
        deploymentStatus = (await deploymentService.registerDevice(
          study!.studyDeploymentId,
          deviceRoleName,
          registration,
        ));
      } catch (error) {
        print("$runtimeType - failed to register device with role name "
            "'$deviceRoleName' for study deployment '${study!.studyDeploymentId}' "
            "at deployment service '$deploymentService'.\n"
            "Error: $error\n"
            "Continuing without registration.");
      }
    }
  }
}