updateDevice method

Future<Device> updateDevice({
  1. required String pushNotificationsToken,
  2. required bool pushNotificationsEnabled,
})

Sets and/or updates the push notifications settings for the currently connected device.

If you do not want to have push notifications, you can safely ignore this method — in which case also no information about the currently connected device will be stored in the Kabelwerk database.

Implementation

Future<Device> updateDevice(
    {required String pushNotificationsToken,
    required bool pushNotificationsEnabled}) {
  _ensureReady();

  final Completer<Device> completer = Completer();

  _channel.push('update_device', {
    'push_notifications_token': pushNotificationsToken,
    'push_notifications_enabled': pushNotificationsEnabled
  })
    ..onReply('ok', (PushResponse pushResponse) {
      final device = Device.fromPayload(pushResponse.response);
      completer.complete(device);
    })
    ..onReply('error', (error) {
      completer.completeError(ErrorEvent());
    })
    ..onReply('timeout', (error) {
      completer.completeError(ErrorEvent());
    });

  return completer.future;
}