Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rido-min opened this issue Jul 7, 2021 · 5 comments
Closed

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

rido-min opened this issue Jul 7, 2021 · 5 comments
Labels
bug Something isn't working Plug and Play Feature: Plug and Play related workaround provided

Comments

@rido-min
Copy link
Member

rido-min commented Jul 7, 2021

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 rido-min added bug Something isn't working needs review Review required by team member labels Jul 7, 2021
@YingXue
Copy link
Member

YingXue commented Jul 14, 2021

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 YingXue removed the needs review Review required by team member label Jul 14, 2021
@rido-min
Copy link
Member Author

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

@YingXue
Copy link
Member

YingXue commented Jul 15, 2021

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.

@rido-min
Copy link
Member Author

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).

@YingXue YingXue added the Plug and Play Feature: Plug and Play related label Aug 30, 2022
@YingXue
Copy link
Member

YingXue commented Mar 14, 2023

@YingXue YingXue closed this as completed Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Plug and Play Feature: Plug and Play related workaround provided
Projects
None yet
Development

No branches or pull requests

2 participants