Homey Community Forum

Custom capability Enum dynamic values

Hello everyone,

I am developing an app where the user can select/set the TV channel by picking it from a list. I figured the list should be a custom capability of type enum, however, it requires me to set the values in the app.json. I do not want this, as the values should be the TV channels coming from the tv’s API.

// app.json

  ...
  "capabilities": {
    "channel_set": {
      "type": "enum",
      "title": {
        "en": "Channel"
      },
      "uiComponent": "picker",
      "getable": true,
      "setable": true,
      "values": [{
        "id": "empty",
        "title": {
          "en": "Empty"
        }
      }],
      "icon": "/assets/icon.svg"
    }
  },
  drivers: [
    ...
    "capabilities": [
      ...
      "channel_set"
    ],
  ]

This shows a picker with only 1 value, ‘Empty’. This is good, so far, now I want to change the picker values. So what I tried, when the TV connects (device.js), gather the list from the API and map it correctly.

// device.js

    ... // TV connects here
    const channelList = [
        {
            id: 'some_id',
            title: {
                en: "Some Title"
            }
        }
    ]
    this.setCapabilityOptions('channel_set', {values: channelList}).then(() => {
        this.log('Finished setting list'); // THIS IS CALLED, SO I EXPECT AN UPDATED PICKER
    }, (error) => {
        this.error(error)
    });

This however does not seem to do anything.

The picker in the app still has the values declared in the app.json instead of what is set in the device.js. Any help or pointers are welcome.

capabilities are static as soon as the device is paired, so values need to be determined before/during pairing, that also includes the enum values.
This is done on purpose, as it might be confusing if a user suddenly has more or less values to select from, also breaking flows.

Thanks for pointing this out, I partially agree with the reason why (but that’s not up for discussion anyway). How to deal with these situations? Is there a workaround or a different technique I should look into?

I tried setting the capabilities in the createDevice method during pairing, however I cannot seem to get this to work? Am I missing something?