Change in ui filters

@zaidka Has there been a change in how filters are set in the ui configs from the beta version to release? I used to be able to do this in the “Edit device page” (it’s been shortened, there is a lot more in there):

2:
  type: "'parameter-list'"
  parameters:
    - element: "'span.inform'"
      label: "'Last inform'"
      parameter: DATE_STRING(Events.Inform)
      type: "'container'"
      components:
        - type: "'parameter'"
        - chart: "'online'"
          type: "'overview-dot'"
        - type: "'summon-button'"
          parameters:
            - InternetGatewayDevice.DeviceInfo.SoftwareVersion OR
              Device.DeviceInfo.SoftwareVersion
    - label: "'Software version'"
      parameter: InternetGatewayDevice.DeviceInfo.SoftwareVersion OR
        Device.DeviceInfo.SoftwareVersion

Emphasis on this:
- InternetGatewayDevice.DeviceInfo.SoftwareVersion OR Device.DeviceInfo.SoftwareVersion

It doesn’t return the actual value anymore, only “true”.

Never mind, I created virtual parameters to fix this. Seemed like a cleaner solution anyway… :slight_smile:

You may be interested in my solution to this issue. I didn’t like writing a bunch of one-off code to run down a list of parameters and find the one that exists for this device. So I wrote this:

const keys = [
  'InternetGatewayDevice.DeviceInfo.SoftwareVersion',
  'Device.DeviceInfo.SoftwareVersion'
];

return {writable: false, value: [getParameterValue(keys, ''), "xsd:string"]};

function getParameterValue(keys, def) {
    for (let key of keys) {
        let d = declare(key, {value: 1});

        for (let item of d) {
            if (item.value && item.value[0]) {
                return item.value[0];
            }
        }
    }

    return def;
}

For some use-cases, the code is overly generalized, but I wanted uniformity with all my provision and vparam scripts.

1 Like

I saw and copied something like this from the examples in the doc. I assumed that was your work… :slight_smile:

1 Like

I know you sorted this out already, but better late than never.

Replace:

InternetGatewayDevice.DeviceInfo.SoftwareVersion OR Device.DeviceInfo.SoftwareVersion

with:

COALESCE(InternetGatewayDevice.DeviceInfo.SoftwareVersion, Device.DeviceInfo.SoftwareVersion)

This is due a change right before the final release relating to how logical operators are evaluated. Now it’s modeled after SQL so logical operators strictly return true, false, or null. But now you can use COALESCE() or CASE/WHEN expressions which give you more flexibility.

4 Likes