azure-iot-explorer
azure-iot-explorer copied to clipboard
[BUG] Enum values with 0 are ignored in writable properties
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
}
]
}
}
]
}
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.
Thanks @YingXue, how can I help to find a valid workaround? Can you point to the code where JS converts the 0 to false?
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.
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).
Fixed released in https://github.com/Azure/azure-iot-explorer/releases/tag/v0.15.8. Closing.