Azure / azure-iot-cli-extension

Azure IoT extension for Azure CLI
Other
83 stars 65 forks source link

[bug] `az iot central device-template create` does not accept DTDL v2 interfaces #364

Open rido-min opened 3 years ago

rido-min commented 3 years ago

az iot central device-template create does not accept DTDL v2 interfaces

To Reproduce

Install the latest with az extension remove azure-iot && az extension add azure-iot

Follow the reference docs to create a device template

Use the next DTDL v2 Model as the input file

{
  "@context": "dtmi:dtdl:context;2",
  "@id": "dtmi:com:example:basic;1",
  "@type": "Interface",
  "displayName": "basic",
  "contents": [
    {
      "@type": "Telemetry",
      "name": "temperature",
      "schema": "double"
    }
  ]
}

Expected behavior A device template is added to my central app

Observed behavior

{'code': 'InvalidBody', 
'message': "The provided request body contains the following errors: 

should have required property 'capabilityModel'; 

['@type'] should be array. 

Environment (please complete the following information):

C:\code> az --version
azure-cli                         2.19.1 *

core                              2.19.1 *
telemetry                          1.0.6

Extensions:
azure-iot                        0.10.13
interactive                        0.4.4

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\rido2\.azure\cliextensions'

Python (Windows) 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 23 2018, 23:31:17) [MSC v.1916 32 bit (Intel)]
rido-min commented 3 years ago

/c @sandeeppujar @avneet723

yang-hai-feng commented 3 years ago

Try this

{
    "displayName": "Themostat Template 2",
    "capabilityModel": {
        "@id": "dtmi:com:test:Thermostat;1",
        "@type": "Interface",
        "contents": [
            {
                "@type": [
                    "Telemetry",
                    "Temperature"
                ],
                "description": "Temperature in degrees Celsius.",
                "displayName": "Temperature",
                "name": "temperature",
                "schema": "double",
                "unit": "degreeCelsius"
            }
        ],
        "description": "Reports current temperature and provides desired temperature control.",
        "displayName": "Thermostat"
    },
    "@id": "dtmi:com:test:mythemostat",
    "@type": [
        "ModelDefinition",
        "DeviceModel"
    ],
    "@context": [
        "dtmi:iotcentral:context;2",
        "dtmi:dtdl:context;2"
    ]
}

With command: az iot central device-template create -n [applicationid] -k "yourrequest.json" --dtid "dtmi:com:test:mythemostat"

rido-min commented 3 years ago

@yang-hai-feng can you point me to the docs describing that file format? It does not conform to the DTDL v2 spec.

/c @briancr-ms

rido-min commented 3 years ago

@yang-hai-feng I read in docs --dtid The ID of the target device template. Example: somedevicetemplate. but your example suggest to use a malformed dtmi (without the version) can you clarify?

yang-hai-feng commented 3 years ago

@yang-hai-feng I read in docs --dtid The ID of the target device template. Example: somedevicetemplate. but your example suggests using a malformed dtmi (without the version) can you clarify?

You are right, the example wasn't updated, as now --api-version preview will continue support legacy naming "somedevicetemplate", --api-version 1.0 will use the dtmi format, ignore the id example that I provided, we should have more specific documentation regarding this, I will create a bug to track this doc update.

@avneet723, do we have a link of official docs regarding IoT central device template?