azure-iot-explorer icon indicating copy to clipboard operation
azure-iot-explorer copied to clipboard

[BUG] Enum values with 0 are ignored in writable properties

Open rido-min opened this issue 3 years ago • 4 comments

Using a PnP model using an enum in a writable property (below one example).

When updating the writable property from IoT Explorer, the value with 0 is not sent in the payload. (all other values work).

{
  "@context": "dtmi:dtdl:context;2",
  "@id": "dtmi:rido:settings;1",
  "@type": "Interface",
  "contents": [
    {
      "@type": "Component",
      "name": "Settings",
      "schema": {
        "@type": "Interface",
        "@id": "dtmi:rido:settings;1",
        "contents": [
          {
            "@type": "Property",
            "name": "DeviceHealthTelemetryConfiguration",
            "schema": {
              "@type": "Enum",
              "valueSchema": "integer",
              "enumValues": [
                {
                  "name": "None",
                  "enumValue": 0
                },
                {
                  "name": "Required",
                  "enumValue": 1
                },
                {
                  "name": "Optional",
                  "enumValue": 2
                }
              ]
            },
            "writable": true
          }
        ]
      }
    }
  ]
}

rido-min avatar Jul 07 '21 18:07 rido-min

Hi @rido-min We are aware of this issue, which has exist for a long time. Unfortunately, javascript treats 0 as false, and there is no yet a good way to fix it.

YingXue avatar Jul 14 '21 23:07 YingXue

Thanks @YingXue, how can I help to find a valid workaround? Can you point to the code where JS converts the 0 to false?

rido-min avatar Jul 15 '21 12:07 rido-min

Hi @rido-min A possible workaround is, since Enum takes in both integer and string type in DTDL, define "@type": "Enum", "valueSchema": "string", and provide Enum value as '0', '1' and so on. From the code side, this is what I've been tracking down for so long but have not get it working properly: https://github.com/Azure/azure-iot-explorer/blob/master/src/app/devices/shared/components/dataForm.tsx#L127

It could be the library (json schema form) which is taking 0 as undefined, I am not entirely sure. Some help would be nice here.

YingXue avatar Jul 15 '21 16:07 YingXue

we cannot ask users to use valueSchema: string when they intend to use an int . This might be a bug in the json schema form library. (wondering how Central solved this problem).

rido-min avatar Jul 21 '21 17:07 rido-min

Fixed released in https://github.com/Azure/azure-iot-explorer/releases/tag/v0.15.8. Closing.

YingXue avatar Mar 14 '23 17:03 YingXue