createDevice method

  1. @override
Future<DeviceManager<DeviceConfiguration<DeviceRegistration>>?> createDevice(
  1. String deviceType
)
override

Create and register a DeviceDataCollector based on a deviceType. Returns null if a device cannot be created.

Implementation

@override
Future<DeviceManager?> createDevice(String deviceType) async {
  // early out if already registered
  if (_devices.containsKey(deviceType)) return _devices[deviceType]!;

  info('$runtimeType - Creating device manager for device type: $deviceType');

  // look for a device manager of this type in the sampling packages
  DeviceManager? manager;
  for (var package in SamplingPackageRegistry().packages) {
    if (package.deviceType == deviceType) manager = package.deviceManager;
  }

  if (manager == null) {
    warning('$runtimeType - No device manager found for device: $deviceType');
  } else {
    registerDevice(deviceType, manager);
  }

  return manager;
}