addTrigger method

void addTrigger(
  1. TriggerConfiguration trigger
)

Add the trigger to this protocol.

Implementation

void addTrigger(TriggerConfiguration trigger) {
  // early out if already added
  if (triggers.values.contains(trigger)) return;

  // if source is not defined, use the primary device role name
  trigger.sourceDeviceRoleName ??= primaryDevice.roleName;

  // so much for null-safety "#%"&?
  if (trigger.requiresPrimaryDevice != null &&
      trigger.requiresPrimaryDevice!) {
    assert(
        hasPrimaryDevice(trigger.sourceDeviceRoleName!),
        'The passed trigger cannot be initiated by its specified source device '
        'since it is not a primary device which is part of this protocol.');
  }

  triggers['${triggers.length}'] = trigger;
}