subscribeCOVPropertyMultiple method

  1. @override
Future<void> subscribeCOVPropertyMultiple(
  1. int deviceId,
  2. List<BacnetCovSubscriptionSpecification> specifications, {
  3. int processId = 1,
  4. Duration lifetime = const Duration(minutes: 5),
  5. bool confirmed = false,
  6. Duration? maxNotificationDelay,
  7. Duration? timeout,
})
override

Subscribes to changes of several properties of several objects with one request (SubscribeCOVPropertyMultiple), e.g. to watch a whole plant room. The device sends COVNotificationMultiple, which arrive as one CovNotificationEvent per object on covEvents (with CovNotificationEvent.changeTimes for timestamped references). maxNotificationDelay lets the device collect changes before it notifies.

When the device refuses a subscription the BacnetProtocolException.firstFailedSubscription names it; devices without the service reject the request (BacnetRejectException), use subscribeCOV for those.

await client.subscribeCOVPropertyMultiple(1234, [
  BacnetCovSubscriptionSpecification(supplyTemp, const [
    BacnetCovReference(BacnetPropertyId.presentValue, covIncrement: 0.2),
    BacnetCovReference(BacnetPropertyId.statusFlags),
  ]),
  BacnetCovSubscriptionSpecification(fan, const [
    BacnetCovReference(BacnetPropertyId.presentValue, timestamped: true),
  ]),
], processId: 7, lifetime: const Duration(minutes: 10));

Implementation

@override
Future<void> subscribeCOVPropertyMultiple(
  int deviceId,
  List<BacnetCovSubscriptionSpecification> specifications, {
  int processId = 1,
  Duration lifetime = const Duration(minutes: 5),
  bool confirmed = false,
  Duration? maxNotificationDelay,
  Duration? timeout,
}) {
  // validates like the real client
  encodeSubscribeCovPropertyMultiple(
    subscriberProcessId: processId,
    specifications: specifications,
    confirmed: confirmed,
    lifetime: lifetime.inSeconds,
  );
  requests.add(
    FakeBacnetRequest(
      'subscribeCOVPropertyMultiple',
      deviceId: deviceId,
      arguments: {
        'specifications': List<BacnetCovSubscriptionSpecification>.of(
          specifications,
          growable: false,
        ),
        'processId': processId,
        'confirmed': confirmed,
      },
    ),
  );
  return _request(
    BacnetConfirmedService.subscribeCovPropertyMultiple,
    deviceId,
    null,
    (device) {
      for (final specification in specifications) {
        final object = specification.object;
        for (final reference in specification.references) {
          try {
            device._read(object.type, object.instance, reference.property);
          } on BacnetProtocolException catch (e) {
            throw BacnetProtocolException(
              'device $deviceId returned an error',
              errorClass: e.errorClass,
              errorCode: e.errorCode,
              firstFailedSubscription: BacnetFailedCovSubscription(
                object: object,
                property: reference.property,
                arrayIndex: reference.arrayIndex,
                errorClass: e.errorClass,
                errorCode: e.errorCode,
              ),
            );
          }
        }
      }
      for (final specification in specifications) {
        final object = specification.object;
        for (final reference in specification.references) {
          _subscriptions
            ..removeWhere(
              (s) => _same(
                s,
                deviceId,
                object.type,
                object.instance,
                reference.property,
                processId,
              ),
            )
            ..add((
              deviceId: deviceId,
              type: object.type,
              instance: object.instance,
              property: reference.property,
              processId: processId,
              confirmed: confirmed,
              timestamped: reference.timestamped,
            ));
        }
      }
    },
  );
}