Partager via


DeviceManagementClient.GetDeviceClass(String, RequestContext) Méthode

Définition

Obtient les propriétés d’une classe d’appareil.

public virtual Azure.Response GetDeviceClass (string deviceClassId, Azure.RequestContext context = default);
abstract member GetDeviceClass : string * Azure.RequestContext -> Azure.Response
override this.GetDeviceClass : string * Azure.RequestContext -> Azure.Response
Public Overridable Function GetDeviceClass (deviceClassId As String, Optional context As RequestContext = Nothing) As Response

Paramètres

deviceClassId
String

Identificateur de classe d’appareil.

context
RequestContext

Contexte de requête, qui peut remplacer les comportements par défaut du pipeline client par appel.

Retours

Réponse retournée par le service. Les détails du schéma du corps de la réponse se trouvent dans la section Remarques ci-dessous.

Exceptions

deviceClassId a la valeur null.

deviceClassId est une chaîne vide, et on s’attendait à ce qu’elle ne soit pas vide.

Le service a retourné un code de status non réussi.

Exemples

Cet exemple montre comment appeler GetDeviceClass avec les paramètres requis et analyser le résultat.

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

Response response = client.GetDeviceClass("<deviceClassId>");

JsonElement result = JsonDocument.Parse(response.ContentStream).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());

Remarques

Vous trouverez ci-dessous le schéma JSON pour la charge utile de réponse.

Corps de réponse :

Schéma pour DeviceClass:

{
              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.
            }

S’applique à