Possible to get default value(s) for custom menu?

Posted on
Fri Jul 15, 2016 5:00 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Possible to get default value(s) for custom menu?

If I'm calling a custom menu the one thing that drives me nuts is not having a default value returned with the list of options. I can't find anything in the docs that let you return more than the list of options for that field, is there a way to let Indigo know to use one of the returned values as a default?

For instance:
Code: Select all
# THIS FIELD IN DEVICES.XML:
<Field type="menu" id="customList">
   <Label>Custom List:</Label>
   <List class="self" filter="" method="getCustomList" dynamicReload="true"/>
</Field>

# CALLS THIS FUNCTION IN PLUGIN.PY:
def getCustomList(filter, valuesDict, typeId, targetId):
   ret = [("default", "No items found")]
   
   try:
      listRet = []
      
      # Loop over options
      listRet.append((0, "First Option"))
      listRet.append((1, "Second Option"))
      
      # Return custom list to Indigo
      return listRet
      
   except:
      return ret
      
   

I want to be able to return that list and say "defaultValue = 1" along with it.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Fri Jul 15, 2016 6:34 pm
jay (support) offline
Site Admin
User avatar
Posts: 16816
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Possible to get default value(s) for custom menu?

Try:

Code: Select all
defaultValue=""

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jul 15, 2016 7:02 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Possible to get default value(s) for custom menu?

Tried that, in fact that's the way I generally have it and that doesn't do it, nor does leaving that off the attributes entirely. Technically I can set that default value to be something but since that something is dynamically changing depending on the selection of another field it cannot be static.

I was hoping I could return a tuple like you can with validation but my hacks to try that have failed. It just ends up being blank and at the very bottom of the combobox, which is ugly and useless so hence the question :). I wrote a pseudo workaround for it but it breaks easily.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Sat Jul 16, 2016 10:04 am
jay (support) offline
Site Admin
User avatar
Posts: 16816
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Possible to get default value(s) for custom menu?

Yeah, I couldn't remember if that worked or not. The problem is that currently default values are set only when the dialog first opens, and not when the contents of a control changes. It's a bit tricky in that situation because the popup can change at any time, which makes determining what to do with selection tricky as well. I just checked and I already have this on our list to look into, but we just haven't gotten to it.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Jul 16, 2016 10:28 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Possible to get default value(s) for custom menu?

jay (support) wrote:
I already have this on our list to look into, but we just haven't gotten to it

Well since you obviously have nothing else to work on at the moment then you should give that some love. Come on Jay.

jay (support) wrote:
only when the dialog first opens, and not when the contents of a control changes

Unless you have a callback on a field and the list field is set to dynamicReload....

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Tue Feb 16, 2021 10:12 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Possible to get default value(s) for custom menu?

Just checking on this as in a few months it will be the fifth anniversary of this thread. :wink:

I have a device settings dialogue with three menu items that are dynamic lists. If whilst editing the device, the first list selection is changed I want to regenerate the lists for menu items 2 and 3. This works OK by using dynamic reload and callbacks but what I can’t fathom out is how to set a default selection for the modified menus 2 and 3. I don't want the default select item message. Setting defaults is OK when the dialogue first opens.

Can this now be done and I have missed how or is it (or was it ever) on the to-do list? :)
Last edited by autolog on Thu Feb 18, 2021 1:52 am, edited 1 time in total.

Posted on
Wed Feb 17, 2021 5:41 pm
matt (support) offline
Site Admin
User avatar
Posts: 20568
Joined: Jan 27, 2003
Location: Texas

Re: Possible to get default value(s) for custom menu?

There isn't an easy way to do it, but since you are already using the dynamic refreshCallbackMethod callback I believe that should work. You'll just set the valuesDict for those popups to whatever you want and they should change. You'll have to handle the logic for when to change the popup to the default you want. Something like:

Code: Select all
   def refreshUiCallback(self, valuesDict, typeId="", devId=None):
      errorsDict = indigo.Dict()
      if needToSetDefaultForFoo:
         valuesDict['Foo'] = "new default"
      return (valuesDict, errorsDict)

So basically you can use the refresh callback to change any of the UI values, so in this case you'll use that to set the default values at the appropriate times. We definitely need to make this simpler.

Image

Posted on
Wed Feb 17, 2021 5:56 pm
FlyingDiver offline
User avatar
Posts: 5337
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Possible to get default value(s) for custom menu?

For a dialog box with three generated menus, how would I set the default for the first menu? The refreshCallbackMethod doesn't get called for the first one.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Feb 17, 2021 6:03 pm
matt (support) offline
Site Admin
User avatar
Posts: 20568
Joined: Jan 27, 2003
Location: Texas

Re: Possible to get default value(s) for custom menu?

I'm referring to the periodic refreshCallbackMethod method that gets called periodically (~1 second if I remember correctly), not the CallbackMethod that gets called when a control is pressed/changed.

Image

Posted on
Wed Feb 17, 2021 6:48 pm
FlyingDiver offline
User avatar
Posts: 5337
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Possible to get default value(s) for custom menu?

Oh, my bad.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Feb 18, 2021 12:08 pm
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Possible to get default value(s) for custom menu?

Hi Matt,
matt (support) wrote:
There isn't an easy way to do it, but since you are already using the dynamic refreshCallbackMethod callback I believe that should work. You'll just set the valuesDict for those popups to whatever you want and they should change. You'll have to handle the logic for when to change the popup to the default you want. Something like:

Code: Select all
   def refreshUiCallback(self, valuesDict, typeId="", devId=None):
      errorsDict = indigo.Dict()
      if needToSetDefaultForFoo:
         valuesDict['Foo'] = "new default"
      return (valuesDict, errorsDict)

So basically you can use the refresh callback to change any of the UI values, so in this case you'll use that to set the default values at the appropriate times. We definitely need to make this simpler.

Thanks for this - it helped resolve the issue for me! :)

Posted on
Sat Mar 20, 2021 9:08 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Possible to get default value(s) for custom menu?

A follow-up question on this:

I now have a problem that that when I click Save on the Edit Device Settings... dialogue and there there is a validation error, i.e errorsDict is returned with a field in error from validateDeviceConfigUi, the red error message appears briefly and then disappears. :?

I presume this is because of the statement errorsDict = indigo.Dict() at the start of the the refreshUiCallback method.

Is there a work-around for this?

Posted on
Sat Mar 20, 2021 9:54 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Possible to get default value(s) for custom menu?

autolog wrote:
... Is there a work-around for this?

Answering part of my question: using error_dict["showAlertText"] = "Error Message" creates a modal dialogue with the error message that is an effective work-around.
At least the user can see what the error is although the field in question is not highlighted as the red highlight is still disappearing. :)

Posted on
Sat Mar 20, 2021 10:23 am
jay (support) offline
Site Admin
User avatar
Posts: 16816
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Possible to get default value(s) for custom menu?

Does your dialog have a recurring callback? I wonder if an error generated sometimes during a callback but then the next time it's called the error is gone - thus the on/off behavior.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 20, 2021 10:54 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Possible to get default value(s) for custom menu?

jay (support) wrote:
Does your dialog have a recurring callback? I wonder if an error generated sometimes during a callback but then the next time it's called the error is gone - thus the on/off behavior.

It does have a recurring callback. The error isn't gone but the errorDict gets "nuked" by the recurring callback which has been coded according to Matt's example below. So the error appears after clicking Save, the recurring callback is then invoked and then the error disappears.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests