registerDevice method

  1. @override
Future<StudyDeploymentStatus?> registerDevice(
  1. String studyDeploymentId,
  2. String deviceRoleName,
  3. DeviceRegistration registration
)
override

Register the device with the specified deviceRoleName for the study deployment with studyDeploymentId.

registration is a matching configuration for the device with deviceRoleName. Returns null if studyDeploymentId is not found.

Implementation

@override
Future<StudyDeploymentStatus?> registerDevice(
  String studyDeploymentId,
  String deviceRoleName,
  DeviceRegistration registration,
) async {
  if (_repository[studyDeploymentId] == null) return null;

  StudyDeployment deployment = _repository[studyDeploymentId]!;

  // check if already registered - if not register device
  DeviceConfiguration device = deployment.registeredDevices.keys.firstWhere(
      (configuration) => configuration.roleName == deviceRoleName,
      orElse: () => DeviceConfiguration(roleName: deviceRoleName));

  deployment.registerDevice(device, registration);

  return deployment.status;
}