subscribeAlarms method

Future<AlarmSubscription> subscribeAlarms(
  1. int deviceId, {
  2. required int notificationClass,
  3. BacnetRecipient? recipient,
  4. int? processId,
  5. bool confirmed = false,
  6. BacnetEventTransitionBits transitions = const BacnetEventTransitionBits(toOffNormal: true, toFault: true, toNormal: true),
  7. Duration? timeout,
})

Adds this client to the recipients of Notification Class notificationClass of deviceId and returns the subscription, whose AlarmSubscription.notifications are the alarms and events of the objects that report to that class.

The recipient is the address of this client (localAddress) unless recipient says otherwise (e.g. the address a NAT router forwards); processId distinguishes the subscription from others of this client (allocated by default). confirmed requests confirmed notifications; transitions selects the reported transitions.

Devices without AddListElement get the destination appended to their Recipient_List with WriteProperty (read, append, write back; a concurrent change by another client between read and write is lost).

final alarms = await client.subscribeAlarms(1234, notificationClass: 1);
alarms.notifications.listen((event) async {
  print('${event.object} ${event.toState.label}');
  if (event.ackRequired) {
    await client.acknowledgeEvent(event, source: 'operator');
  }
});
// ...
await alarms.cancel();

Implementation

Future<AlarmSubscription> subscribeAlarms(
  int deviceId, {
  required int notificationClass,
  BacnetRecipient? recipient,
  int? processId,
  bool confirmed = false,
  BacnetEventTransitionBits transitions = const BacnetEventTransitionBits(
    toOffNormal: true,
    toFault: true,
    toNormal: true,
  ),
  Duration? timeout,
}) async {
  final subscription = AlarmSubscription._(
    this,
    deviceId,
    BacnetObject(
      type: BacnetObjectType.notificationClass,
      instance: notificationClass,
    ),
    BacnetDestination(
      recipient: recipient ?? await localAddress(),
      processId: processId ?? allocateProcessId(),
      issueConfirmedNotifications: confirmed,
      transitions: transitions,
    ),
    timeout,
  );
  await subscription._add();
  return subscription;
}