invokeDeviceMethod method

Future<InvokeDeviceMethodResponse> invokeDeviceMethod({
  1. required String deviceId,
  2. DeviceMethod? deviceMethod,
  3. String? deviceMethodParameters,
})

Given a device ID, issues a request to invoke a named device method (with possible parameters). See the "Example POST" code snippet below.

May throw InvalidRequestException. May throw PreconditionFailedException. May throw InternalFailureException. May throw ResourceNotFoundException. May throw RangeNotSatisfiableException. May throw ResourceConflictException.

Parameter deviceId : The unique identifier of the device.

Parameter deviceMethod : The device method to invoke.

Parameter deviceMethodParameters : A JSON encoded string containing the device method request parameters.

Implementation

Future<InvokeDeviceMethodResponse> invokeDeviceMethod({
  required String deviceId,
  DeviceMethod? deviceMethod,
  String? deviceMethodParameters,
}) async {
  ArgumentError.checkNotNull(deviceId, 'deviceId');
  final $payload = <String, dynamic>{
    if (deviceMethod != null) 'deviceMethod': deviceMethod,
    if (deviceMethodParameters != null)
      'deviceMethodParameters': deviceMethodParameters,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/devices/${Uri.encodeComponent(deviceId)}/methods',
    exceptionFnMap: _exceptionFns,
  );
  return InvokeDeviceMethodResponse.fromJson(response);
}