updateDevice method

Future<void> updateDevice(
  1. String deviceId, {
  2. String? displayName,
})
inherited

Updates the metadata on the given device.

deviceId The device to update.

displayName The new display name for this device. If not given, the display name is unchanged.

Implementation

Future<void> updateDevice(String deviceId, {String? displayName}) async {
  final requestUri =
      Uri(path: '_api/client/v3/devices/${Uri.encodeComponent(deviceId)}');
  final request = Request('PUT', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    if (displayName != null) 'display_name': displayName,
  }));
  final response = await httpClient.send(request);
  final responseBody = await response.stream.toBytes();
  if (response.statusCode != 200) unexpectedResponse(response, responseBody);
  final responseString = utf8.decode(responseBody);
  final json = jsonDecode(responseString);
  return ignore(json);
}