Share via


DeviceManagementClient.GetDeviceClassesAsync(String, RequestContext) Method

Definition

Gets a list of all device classes (sets of devices compatible with the same updates based on the model Id and compat properties reported in the Device Update PnP interface in IoT Hub) for all devices connected to Device Update for IoT Hub.

public virtual Azure.AsyncPageable<BinaryData> GetDeviceClassesAsync (string filter = default, Azure.RequestContext context = default);
abstract member GetDeviceClassesAsync : string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
override this.GetDeviceClassesAsync : string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
Public Overridable Function GetDeviceClassesAsync (Optional filter As String = Nothing, Optional context As RequestContext = Nothing) As AsyncPageable(Of BinaryData)

Parameters

filter
String

Restricts the set of device classes returned. You can filter on friendly name.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The AsyncPageable<T> from the service containing a list of BinaryData objects. Details of the body schema for each item in the collection are in the Remarks section below.

Exceptions

Service returned a non-success status code.

Examples

This sample shows how to call GetDeviceClassesAsync and parse the result.

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

await foreach (var data in client.GetDeviceClassesAsync())
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("deviceClassId").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("compatProperties").GetProperty("<test>").ToString());
}

This sample shows how to call GetDeviceClassesAsync with all parameters, and how to parse the result.

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

await foreach (var data in client.GetDeviceClassesAsync("<filter>"))
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("deviceClassId").ToString());
    Console.WriteLine(result.GetProperty("friendlyName").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("contractModel").GetProperty("id").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("contractModel").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("compatProperties").GetProperty("<test>").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("provider").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("version").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("description").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("friendlyName").ToString());
}

Remarks

Below is the JSON schema for one item in the pageable response.

Response Body:

Schema for DeviceClassesListValue:

{
              deviceClassId: string, # Required. The device class identifier. This is generated from the model Id and the compat properties reported by the device update agent in the Device Update PnP interface in IoT Hub. It is a hex-encoded SHA1 hash.
              friendlyName: string, # Optional. The device class friendly name. This can be updated by callers after the device class has been automatically created.
              deviceClassProperties: {
                contractModel: {
                  id: string, # Required. The Device Update agent contract model Id of the device class. This is also used to calculate the device class Id.
                  name: string, # Required. The Device Update agent contract model name of the device class. Intended to be a more readable form of the contract model Id.
                }, # Optional. The Device Update agent contract model.
                compatProperties: Dictionary<string, string>, # Required. The compat properties of the device class. This object can be thought of as a set of key-value pairs where the key is the name of the compatibility property and the value is the value of the compatibility property. There will always be at least 1 compat property
              }, # Required. The device class properties that are used to calculate the device class Id
              bestCompatibleUpdate: {
                updateId: {
                  provider: string, # Required. Update provider.
                  name: string, # Required. Update name.
                  version: string, # Required. Update version.
                }, # Required. Update identifier.
                description: string, # Optional. Update description.
                friendlyName: string, # Optional. Friendly update name.
              }, # Optional. Update that is the highest version compatible with this device class.
            }

Applies to