Correct Syntax for supportedValues when empty?

If I have an enum type that defines supportedValues, what is the correct way to tell the UI that the device doesn’t support anything?

For example:

Capability

attributes:
  supportedAlerts:
    schema:
      type: object
      properties:
        value:
          type: array
          items:
            type: string
      additionalProperties: false
      required: []
    enumCommands: []

Presentation:

automation:
  conditions: []
  actions:
    - label: MyCapability
      displayType: list
      list:
        alternatives:
          - key: one
            value: One
            type: active
          - key: two
            value: Two
            type: active
        supportedValues: supportedAlerts.value
        command: apply
        argumentType: string

Driver:

device:emit_event(capability_alerts.supportedAlerts({ 'one' })) -- WORKS
device:emit_event(capability_alerts.supportedAlerts({})) -- NO EFFECT
device:emit_event(capability_alerts.supportedAlerts(nil)) -- NO EFFECT

I can see the event is emitted with {} or nil, but there is no difference. Never setting it all works fine. If I don’t set it, the UI is greyed out as desired. That is what I am hoping to do with setting the empty list.

You mean dynamically set the supportedValues from the driver so the UI can update itself? I had asked a similar question but was told that isn’t supposed at this time. Would be a nice feature through.

@nayelyz

@RBoy Yes. I currently use it to change the supported values dynamically. It does work as desired other than the case above where I want to list no options and have it greyed out as if it was never set to begin with.

If you want to disable the widget so users cannot enter a value, you can use visibleCondition instead, it helps you enable/disable the usability of a capability. This property is set in the deviceConfig.
Here’s an example:

"visibleCondition": {
    "capability": "schoolwater29967.vacation",/*compared capability*/
    "version": 1,
    "component": "main", /*device's component where the capability is located*/
    "value": "vacationMode.value", /*reference to which attribute will be compared*/
    "operator": "DOES_NOT_EQUAL",
    "operand": "enabled" /*value assigned to the attribute compared in this condition*/
}

@RBoy, I think you mean this post? Custom Capability and CLI Developer Preview - #214 by erickv
That was in 2020, so, currently, the supportedValues property is considered, there was an issue in the past with it but it has been working correctly lately.

1 Like

This just completely changed things for me :+1:

I had been creating a bunch of different profiles and switching between them. This looks more appropriate.

@nayelyz In my case these are shown based on a setting. Is there a way to tie it to preferences directly, or would I need to set a capability attribute based on the preference?

yes, this must be part of the presentation and the value of the capability attribute can change based on the selection in the preference. Also, if you have different profiles, you can use the same capability to condition others to be usable or not.

Is this supposed to be limited to automation views, or should it work in the detailed view as well?

I’ve only used it in the detail view, in the documentation, this property also appears for the automation view but I’m not sure how it appears there…

Do you know of an existing capability that I can check for an example? I am getting an error when trying to do this with yaml. I created a boolean capability and tried this in my presentation

- component: main
  capability: myDynamicCapability
  version: 1
  values: []
  patch: []
  exclusion: []
  visibleCondition:
    capability: myBooleanCapability
    version: 1
    component: main
    value: enabled.value
    operator: EQUALS
    operand: true

Edit: Fixed syntax error causing failure

Can you share with me the ID of your capability so I can try to use it, please? Maybe is because of the attribute’s type, I haven’t used it with Boolean before…You can do it over DM

@nayelyz Thanks for working through this. I can confirm this is working nicely in the detailed view, but it isn’t impacting my automation views. The docs show it being used in an automation view, so it is probably a bug in the app.

I’ll check this with the team, thank you for sharing the behavior you observed.

@nayelyz Do you know where we can find documentation on visibleCondition? I am only finding vague references and code samples. I would like to find out what options are available for the operator. I would like to see if it is possible to check if an array attribute contains a certain value.

Hi!

First, an update about visibleCondition in automation:

The team mentioned this will be supported but it’s not yet implemented in the app. There’s no ETA for that yet.

In the API reference (create device-config), you can find this property in the menu:

I made a sample a while ago about a value in an array and it worked at the time, please let me know your results:

"detailView": [
    {
        "component": "main",
        "capability": "temperatureMeasurement",
        "version": 1,
        "visibleCondition": {
            "component": "main",
            "capability": "thermostatMode",
            "version": 1,
            "value": "thermostatMode.value",
            "operator": "ONE_OF",
            "operand": "[\"auto\", \"manual\"]"
        },
        "values": [],
        "patch": []
    }

As a reference, this is the VID: 822a802f-2ead-356a-a3bf-166ddb61c57a.

Edit: Oh, but that’s a String attribute and compares an array of values, sorry, I confused them. What made the difference, in this case, was the scaping of the symbol ", that can help…

1 Like