Action creation

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Thu Feb 28, 2013 4:32 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Action creation

When the action configUI is run are there any callbacks into plugin.py? Specifically, a user may display information on an LCD text display having between 1 and 4 lines. I would like to dynamically change the ConfigUI to take input for all available lines rather than have the action take input for just one line (user defined 1 to 4) -- thus, requiring 4 actions for a 4 line display.

Posted on
Fri Mar 01, 2013 9:41 am
jay (support) offline
Site Admin
User avatar
Posts: 18265
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Action creation

You can change what's displayed in a running dialog via a response to a button press. You can pass back a modified values dict which can end up hiding/showing controls. Not sure if that's the answer you're looking for - if not, can you describe more what it is you're trying to do?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Mar 01, 2013 10:00 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Action creation

Thanks. What I really wanted was what the Button Press gives, but without the button press. I.e. before the window displays, there is a call to some function. But, the button press should do the trick.

Posted on
Fri Mar 01, 2013 11:22 am
jay (support) offline
Site Admin
User avatar
Posts: 18265
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Action creation

Oh, that's different. You can implement this method (the default implementation is shown for example purposes):

Code: Select all
def getDeviceConfigUiValues(self, pluginProps, typeId, devId)
   valuesDict = pluginProps
   errorMsgDict = indigo.Dict()
   return (valuesDict, errorMsgDict)


If the devId is non-zero (which it would be for a new device), then you can modify the valuesDict as necessary to manipulate the UI via visible and/or hidden bindings.

Alternately, you could implement this method (again, the default implementation is shown):

Code: Select all
def getDeviceConfigUiXml(self, typeId, devId):
   if typeId in self.devicesTypeDict:
      return self.devicesTypeDict[typeId][u"ConfigUIRawXml"]
   return None


To modify the XML itself. I wouldn't recommend that approach, but you could do it if you really wanted to... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Mar 01, 2013 1:54 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Action creation

I am not sure we are on the same page.

I am talking about creating a plugin defined action (Trigger-> Action, or Action Group)

After selecting the Type: and Device: and clicking the Edit Action Settings... button I would like the contents of the configuration window to vary based on data stored in the device properties or in the plugin. Specifically, I would like to display a varying number of textfields.

I tried getDeviceConfigUiValues, but it doesn't seem to get called (and the Device context didn't seem right anyway).

I guess I could define as many textfields as I might ever need (4) and hide 1 to 3 of them based on some value returned to the Action dialog in a hidden field. If there was a way to return that field to the action Config.

Posted on
Fri Mar 01, 2013 3:21 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Action creation

It looks like getActionConfigUiXml will work. I can either return all the XML or just set a value in a hidden field to usa as a visibleBindingValue.

Posted on
Sat Mar 02, 2013 1:23 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Action creation

Yes!

getActionConfigUiXml worked perfectly. I structured the Action.xml so the appropriate display was controlled by a value in a hidden textfield. Then, all I needed to do was use re substitution to change the defaultValue received in self.actionsTypeDict[typeId][u"ConfigUIRawXml"] and return the edited xml.

Thanks for the pointers.

Posted on
Sat Mar 02, 2013 1:32 pm
jay (support) offline
Site Admin
User avatar
Posts: 18265
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Action creation

Are you sure getDeviceConfigUiValues isn't getting called every time? That would be the easier place to set that value.

And, for a new device, it doesn't really matter since you don't yet know what kind of device it is (so you'd just show the default amount), right?

You really should think about the DeviceFactory - it's made exactly for what you're trying to do I think.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 02, 2013 1:50 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Action creation

This is an action group creation dialog, not a device config. So, the device always exists, otherwise it could not have appeared tin the device selection pulldown.

I did look at getActionConfigUiValues(self, pluginProps, typeId, devId):
which returns valuesDict and errorMsgDict. But, pluginProps is empty so there is nothing to edit. Essentially this function seems like a noop, at least in the context of creating a new action group.

Posted on
Sat Mar 02, 2013 3:36 pm
jay (support) offline
Site Admin
User avatar
Posts: 18265
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Action creation

Just add the value to pluginProps (well, the copy you make by doing valuesDict = pluginProps) that will hide/show whatever you want. Anything in the pluginProps that corresponds to a field will have that value passed to the <Field>. It's empty on a new action because it's the first time the dialog runs for that action.

I think... ;)

I think the name "pluginProps" is a bit misleading from plugin_base.py - I'm pretty sure it's the props for the action.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 02, 2013 6:20 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Action creation

Well, I think you were right :wink:

getActionConfigUiValues works.

With this field definition from actions.xml:
Code: Select all
<Field id='displayLinesNum' type='textfield' hidden='true' defaultValue='1'>
        <Label/>
</Field>

I set valuesDict to: valuesDict['displayLinesNum'] = '4'
and got what I wanted. This is certainly easier than doing the re substitution... though, I had already coded that, I'm switching to getActionConfigUiValues. Easier to code = easier to maintain.

Thanks.

Posted on
Sat Mar 02, 2013 7:12 pm
jay (support) offline
Site Admin
User avatar
Posts: 18265
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Action creation

berkinet wrote:
Easier to code = easier to maintain.


Totally agree - maintainability is an important design goal. Glad it worked.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests