Announcement

Collapse
No announcement yet.

Control with Text DropDown sorts incorrectly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Control with Text DropDown sorts incorrectly

    I'm attempting to add a feature with a text dropdown control in a plug-in environment. The control displays the keys in an order that is not sorted, or what was originally used to build the control. It uses a sorted dictionary, so shouldn't this display alphabetically by key?
    Click image for larger version

Name:	image.png
Views:	144
Size:	5.9 KB
ID:	1578890

    My code to add the feature starts like this.

    Dim ff = FeatureFactory.CreateFeature(pluginId)
    Dim Sources As New SortedDictionary(Of String, Double) From {{"TV", 0}, {"HDMI1", 1280}, {"HDMI2", 1281}, {"HDMI3", 1282}, {"HDMI4", 1283}}
    ff.OnDevice(parent.Ref)​
    ff.AddTextDropDown(Sources)
    Dim nfd As NewFeatureData = ff.PrepareForHs()
    HomeSeerSystem.CreateFeatureForDevice(nfd)​

    So is this a bug, or am I doing something wrong?

    Also wondering if there is a way to display the key that matches the current value of the feature. When closed, the dropdown always displays TV. If this does work for others out there, it is possible that it does not work for me due to the values for HDMI don't actually match the status value of the feature. This quirk is because the command to change to HDMI1 is one thing, and the status reported as HDMI1 is a different number. I could work around that, but just wondering if it normally sync's. I suppose a simple work-around would be to set the default to "_Choose" or something that will be placed first in the list. Then don't react if the user actually chooses that one.

    Third, I tried this first as a ff.AddRadioSelectList(Sources), but no buttons displayed at all on the feature so I abandoned that one. Does this work for others?

    #2
    I don't yet see what you would be doing wrong. Just tried it myself, as I was about to add a text dropdown in a new plugin. I do it in C#. Copied your data:

    SortedDictionary<string, double> textOptions = new SortedDictionary<string, double> { { "TV", 0 }, { "HDMI1", 1280 }, { "HDMI2", 1281 }, { "HDMI3", 1282 }, { "HDMI4", 1283 } };

    Result:
    Click image for larger version  Name:	afbeelding.png Views:	0 Size:	5.0 KB ID:	1579901

    What you could try to figure it out:
    1. To see if they match, add the value to the strings too. {{"1. TV", 0}, {"1280. HDMI1", 1280}, {"1281. HDMI2", 1281}, {"1283. HDMI3", 1282}, {"1283. HDMI4", 1283}}

    2. Check Status/Graphics:
    Click image for larger version  Name:	afbeelding.png Views:	0 Size:	40.1 KB ID:	1579907

    3. Check the devices page source. Mine says:
    Code:
    option  action='control' value='0' ref='3166' ccindex='0' >TV</Option> <option  action='control' value='1280' ref='3166' ccindex='1' >HDMI1</Option> <option  action='control' value='1281' ref='3166' ccindex='2' >HDMI2</Option> <option  action='control' value='1282' ref='3166' ccindex='3' >HDMI3</Option> <option  action='control' value='1283' ref='3166' ccindex='4' >HDMI4</Option>
    Plugins I developed for HS4: Somfy Local, MiLight (LimitlessLED), Updates, Volvo (VoC), OpenTherm Gateway (OTGW)
    Running HS4 Pro on Windows 10 Pro on a Synology VM, with Node-RED running as a container.

    Comment


      #3
      Thanks for the response. I actually got the feature by reference and JSON serialized it to a log to see the configuration. The order was just as you show it above. I tried a restart of HS and a different browser (Chrome vs Edge), and the order still showed incorrectly. I deleted the feature and let the same code create it. This time the order shows correctly. Very odd...

      Comment


        #4
        I played around a bit and see that the order shown on the devices page is truly sorted by value, range start, or key if you prefer. The order it will be displayed in the dropdown is the order in which it was added to the feature, whether it was added at the time of creation by code or added later in the "Edit Controls" screen above. The only way to change the order it will be displayed in the dropdown would be to remove all controls and add in that order. I'm really not sure why mine displayed this way, but at least I understand the functionality now.

        On my second question, the dropdown will select per the feature value if one matches, otherwise the first in the list (at creation, not per the sorted view in Edit Controls) will be displayed. I will have to map my control values to the correct value while processing the button press so I can match the values. I could also add Choose as the first control created and then ignore that value in processing if a user selects Choose.

        I have not played around with the radio buttons enough to see why that didn't work, but I'll stay with the dropdown anyway.

        Comment

        Working...
        X