/* * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for * license information. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is * regenerated. */ import * as msRest from "@azure/ms-rest-js"; import * as Models from "../models"; import * as Mappers from "../models/devicesMappers"; import * as Parameters from "../models/parameters"; import { IotHubGatewayServiceAPIsContext } from "../iotHubGatewayServiceAPIsContext"; /** Class representing a Devices. */ export class Devices { private readonly client: IotHubGatewayServiceAPIsContext; /** * Create a Devices. * @param {IotHubGatewayServiceAPIsContext} client Reference to the service client. */ constructor(client: IotHubGatewayServiceAPIsContext) { this.client = client; } /** * Gets the identities of multiple devices from the IoT Hub identity registry. Not recommended. Use * the IoT Hub query API to retrieve device twin and device identity information. See * https://docs.microsoft.com/en-us/rest/api/iothub/service/queryiothub and * https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-query-language for more * information. * @param [options] The optional parameters * @returns Promise */ getDevices(options?: Models.DevicesGetDevicesOptionalParams): Promise; /** * @param callback The callback */ getDevices(callback: msRest.ServiceCallback): void; /** * @param options The optional parameters * @param callback The callback */ getDevices(options: Models.DevicesGetDevicesOptionalParams, callback: msRest.ServiceCallback): void; getDevices(options?: Models.DevicesGetDevicesOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.client.sendOperationRequest( { options }, getDevicesOperationSpec, callback) as Promise; } /** * Gets a device from the identity registry of the IoT Hub. * @param id The unique identifier of the device. * @param [options] The optional parameters * @returns Promise */ getIdentity(id: string, options?: msRest.RequestOptionsBase): Promise; /** * @param id The unique identifier of the device. * @param callback The callback */ getIdentity(id: string, callback: msRest.ServiceCallback): void; /** * @param id The unique identifier of the device. * @param options The optional parameters * @param callback The callback */ getIdentity(id: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; getIdentity(id: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.client.sendOperationRequest( { id, options }, getIdentityOperationSpec, callback) as Promise; } /** * Creates or updates the identity of a device in the identity registry of the IoT Hub. * @param id The unique identifier of the device. * @param device The contents of the device identity. * @param [options] The optional parameters * @returns Promise */ createOrUpdateIdentity(id: string, device: Models.Device, options?: Models.DevicesCreateOrUpdateIdentityOptionalParams): Promise; /** * @param id The unique identifier of the device. * @param device The contents of the device identity. * @param callback The callback */ createOrUpdateIdentity(id: string, device: Models.Device, callback: msRest.ServiceCallback): void; /** * @param id The unique identifier of the device. * @param device The contents of the device identity. * @param options The optional parameters * @param callback The callback */ createOrUpdateIdentity(id: string, device: Models.Device, options: Models.DevicesCreateOrUpdateIdentityOptionalParams, callback: msRest.ServiceCallback): void; createOrUpdateIdentity(id: string, device: Models.Device, options?: Models.DevicesCreateOrUpdateIdentityOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.client.sendOperationRequest( { id, device, options }, createOrUpdateIdentityOperationSpec, callback) as Promise; } /** * Deletes the identity of a device from the identity registry of the IoT Hub. * @param id The unique identifier of the device. * @param [options] The optional parameters * @returns Promise */ deleteIdentity(id: string, options?: Models.DevicesDeleteIdentityOptionalParams): Promise; /** * @param id The unique identifier of the device. * @param callback The callback */ deleteIdentity(id: string, callback: msRest.ServiceCallback): void; /** * @param id The unique identifier of the device. * @param options The optional parameters * @param callback The callback */ deleteIdentity(id: string, options: Models.DevicesDeleteIdentityOptionalParams, callback: msRest.ServiceCallback): void; deleteIdentity(id: string, options?: Models.DevicesDeleteIdentityOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.client.sendOperationRequest( { id, options }, deleteIdentityOperationSpec, callback); } /** * Gets the device twin. See https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-device-twins * for more information. * @param id The unique identifier of the device. * @param [options] The optional parameters * @returns Promise */ getTwin(id: string, options?: msRest.RequestOptionsBase): Promise; /** * @param id The unique identifier of the device. * @param callback The callback */ getTwin(id: string, callback: msRest.ServiceCallback): void; /** * @param id The unique identifier of the device. * @param options The optional parameters * @param callback The callback */ getTwin(id: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; getTwin(id: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.client.sendOperationRequest( { id, options }, getTwinOperationSpec, callback) as Promise; } /** * Replaces the tags and desired properties of a device twin. See * https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-device-twins for more information. * @param id The unique identifier of the device. * @param deviceTwinInfo The device twin info that will replace the existing info. * @param [options] The optional parameters * @returns Promise */ replaceTwin(id: string, deviceTwinInfo: Models.Twin, options?: Models.DevicesReplaceTwinOptionalParams): Promise; /** * @param id The unique identifier of the device. * @param deviceTwinInfo The device twin info that will replace the existing info. * @param callback The callback */ replaceTwin(id: string, deviceTwinInfo: Models.Twin, callback: msRest.ServiceCallback): void; /** * @param id The unique identifier of the device. * @param deviceTwinInfo The device twin info that will replace the existing info. * @param options The optional parameters * @param callback The callback */ replaceTwin(id: string, deviceTwinInfo: Models.Twin, options: Models.DevicesReplaceTwinOptionalParams, callback: msRest.ServiceCallback): void; replaceTwin(id: string, deviceTwinInfo: Models.Twin, options?: Models.DevicesReplaceTwinOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.client.sendOperationRequest( { id, deviceTwinInfo, options }, replaceTwinOperationSpec, callback) as Promise; } /** * Updates the tags and desired properties of a device twin. See * https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-device-twins for more information. * @param id The unique identifier of the device. * @param deviceTwinInfo The device twin info containing the tags and desired properties to be * updated. * @param [options] The optional parameters * @returns Promise */ updateTwin(id: string, deviceTwinInfo: Models.Twin, options?: Models.DevicesUpdateTwinOptionalParams): Promise; /** * @param id The unique identifier of the device. * @param deviceTwinInfo The device twin info containing the tags and desired properties to be * updated. * @param callback The callback */ updateTwin(id: string, deviceTwinInfo: Models.Twin, callback: msRest.ServiceCallback): void; /** * @param id The unique identifier of the device. * @param deviceTwinInfo The device twin info containing the tags and desired properties to be * updated. * @param options The optional parameters * @param callback The callback */ updateTwin(id: string, deviceTwinInfo: Models.Twin, options: Models.DevicesUpdateTwinOptionalParams, callback: msRest.ServiceCallback): void; updateTwin(id: string, deviceTwinInfo: Models.Twin, options?: Models.DevicesUpdateTwinOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.client.sendOperationRequest( { id, deviceTwinInfo, options }, updateTwinOperationSpec, callback) as Promise; } /** * Invokes a direct method on a device. See * https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-direct-methods for more information. * @param deviceId The unique identifier of the device. * @param directMethodRequest The parameters to execute a direct method on the device. * @param [options] The optional parameters * @returns Promise */ invokeMethod(deviceId: string, directMethodRequest: Models.CloudToDeviceMethod, options?: msRest.RequestOptionsBase): Promise; /** * @param deviceId The unique identifier of the device. * @param directMethodRequest The parameters to execute a direct method on the device. * @param callback The callback */ invokeMethod(deviceId: string, directMethodRequest: Models.CloudToDeviceMethod, callback: msRest.ServiceCallback): void; /** * @param deviceId The unique identifier of the device. * @param directMethodRequest The parameters to execute a direct method on the device. * @param options The optional parameters * @param callback The callback */ invokeMethod(deviceId: string, directMethodRequest: Models.CloudToDeviceMethod, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; invokeMethod(deviceId: string, directMethodRequest: Models.CloudToDeviceMethod, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.client.sendOperationRequest( { deviceId, directMethodRequest, options }, invokeMethodOperationSpec, callback) as Promise; } } // Operation Specifications const serializer = new msRest.Serializer(Mappers); const getDevicesOperationSpec: msRest.OperationSpec = { httpMethod: "GET", path: "devices", queryParameters: [ Parameters.top, Parameters.apiVersion ], responses: { 200: { bodyMapper: { serializedName: "parsedResponse", type: { name: "Sequence", element: { type: { name: "Composite", className: "Device" } } } } }, default: {} }, serializer }; const getIdentityOperationSpec: msRest.OperationSpec = { httpMethod: "GET", path: "devices/{id}", urlParameters: [ Parameters.id ], queryParameters: [ Parameters.apiVersion ], responses: { 200: { bodyMapper: Mappers.Device }, default: {} }, serializer }; const createOrUpdateIdentityOperationSpec: msRest.OperationSpec = { httpMethod: "PUT", path: "devices/{id}", urlParameters: [ Parameters.id ], queryParameters: [ Parameters.apiVersion ], headerParameters: [ Parameters.ifMatch ], requestBody: { parameterPath: "device", mapper: { ...Mappers.Device, required: true } }, responses: { 200: { bodyMapper: Mappers.Device }, default: {} }, serializer }; const deleteIdentityOperationSpec: msRest.OperationSpec = { httpMethod: "DELETE", path: "devices/{id}", urlParameters: [ Parameters.id ], queryParameters: [ Parameters.apiVersion ], headerParameters: [ Parameters.ifMatch ], responses: { 204: {}, default: {} }, serializer }; const getTwinOperationSpec: msRest.OperationSpec = { httpMethod: "GET", path: "twins/{id}", urlParameters: [ Parameters.id ], queryParameters: [ Parameters.apiVersion ], responses: { 200: { bodyMapper: Mappers.Twin }, default: {} }, serializer }; const replaceTwinOperationSpec: msRest.OperationSpec = { httpMethod: "PUT", path: "twins/{id}", urlParameters: [ Parameters.id ], queryParameters: [ Parameters.apiVersion ], headerParameters: [ Parameters.ifMatch ], requestBody: { parameterPath: "deviceTwinInfo", mapper: { ...Mappers.Twin, required: true } }, responses: { 200: { bodyMapper: Mappers.Twin }, default: {} }, serializer }; const updateTwinOperationSpec: msRest.OperationSpec = { httpMethod: "PATCH", path: "twins/{id}", urlParameters: [ Parameters.id ], queryParameters: [ Parameters.apiVersion ], headerParameters: [ Parameters.ifMatch ], requestBody: { parameterPath: "deviceTwinInfo", mapper: { ...Mappers.Twin, required: true } }, responses: { 200: { bodyMapper: Mappers.Twin }, default: {} }, serializer }; const invokeMethodOperationSpec: msRest.OperationSpec = { httpMethod: "POST", path: "twins/{deviceId}/methods", urlParameters: [ Parameters.deviceId ], queryParameters: [ Parameters.apiVersion ], requestBody: { parameterPath: "directMethodRequest", mapper: { ...Mappers.CloudToDeviceMethod, required: true } }, responses: { 200: { bodyMapper: Mappers.CloudToDeviceMethodResult }, default: {} }, serializer };