Device advanced settings using dropdown for boolean setting?

Hi

I am writing a device driver. Is there a way to have the UI show a “dropdown” for a particular device setting that is a boolean?

The only way that I have been able to have homey correctly set a boolean setting’s values is to mark that setting as a boolean. This is ok for some settings, but it doesn’t make sense for a lot of settings.

For instance, a checkbox works great for “Smart Bulb Mode”, because this mode is either enabled or disabled. So the checkbox slider UI works great.
But another setting is of “Switch Mode” where the two options are act like a dimmer or act like a switch, doesn’t make sense to be represented as a checkbox slider UI. That makes more sense to be a drop down with boolean values.

What I am finding is that when I setup Switch Mode as a radio or dropdown, the values must be sent as strings because it always sends something that the switch interprets as a 1 value for the boolean value.

If I use something like this in my driver.settings.componse.json file, then I get the proper values being sent to the device:

      {
        "id": "switchMode",
        "type": "checkbox",
        "value": false,
        "label": {
          "en": "Switch Mode",
        }
      },

but if I try to use something like this, I get both values setting a positive boolean value and I can never get the device to go to the switchMode that is enabled with a false value.

      {
        "id": "switchMode",
        "type": "radio",
        "value": "0",
        "label": {
          "en": "Switch Mode",
        },
        "values": [
          {
            "id": "0",
            "type": "checkbox",
            "label": {
              "en": "Dimmer",
            }
          },
          {
            "id": "1",
            "type": "checkbox",
            "label": {
              "en": "On/Off Switch",
            }
          }
        ]
      }

The same thing happens if I change this to a “dropdown” rather than a radio.
And if I use true and false for the ids of the values, then I get a compile error and the driver wont build.

Any suggestions?

I think I have found a solution.
In device.ts, in onSettings, I convert the new setting to an int before sending it to cluster.writeAttributes.

I found that I had to first check to see if the value was a boolean rather than a string and deal with that separately. But this now allows me to use a dropdown or a radio to display a boolean value.

      let value: number;
      if (typeof(newSettings[key]) === 'boolean') {
        value = newSettings[key] ? 1 : 0;
      }
      else {
        value = parseInt(newSettings[key], 10);
      }
      await cluster.writeAttributes({ [key]: newSettings[key] });