Page 1 of 1

Help with adding action with values

Posted: Mon Nov 26, 2012 1:32 am
by rdgerken
Can anyone please help me, by showing me how to pass values to actions? I have been struggling with this for quite some time now, and this will be my last effort before I ditch the whole thing.

For example, I have some code that Fiasco started (and I think it was copied from Bitmonster initially - this is for the RadioRA2 plugin for Lutron), and there is a problem that I cannot solve. Essentially, what happens is, when the plugin gets loaded, it runs through a for loop adding several actions into the tree. The last values of the for loop that were parsed, ends up on ALL the actions. I can't figure out why, and I've exhausted all my searching. Apparently Fiasco was also struggling with this problem, because he put this issue in his original thread for this plugin, but unfortunately, his question/problem went unanswered. If anyone would be kind enough to show the following example:

For a list of values and descriptions:

100, Room A
200, Room B
300, Room C
400, Room D

Show me how to add actions to the tree automatically when the plugin is loaded, and then when the action is executed, how I would be able to access these values that were passed into the action when the action was created (so that I can use the values when I generate traffic out of the tcp port for example). The way the plugin works now, I get all 4 actions created in the tree ok (with the proper value and description), but when the action is executed, they all execute with "400, Room D"


Here is the original post from Fiasco describing the problem:


----------------------------------------------------------------------------------
In the following code within the RadioRa plugin

Code: Select all

                if devicetype == 'maestro':
                   group = self.AddGroup('RadioRa2 Maestro Dimmer/Switch - ' + deviceid + ' ' + devicelocation )
                   for className, descr, act, pre in MAESTRO_DEVICE_ACTIONS:

                       print pre + 'OUTPUT,' + deviceid + ',' + act               
                       
                       clsAttributes = dict(
                       name=descr + ' ' + deviceid,
                       action=act,
                       prefix=pre,
                       deviceid=deviceid,
                       devicetype=devicetype,
                       devicelocation=devicelocation,
                       command = pre + 'OUTPUT,' + deviceid + ',' + act
                       )
                       if ( className == "SETZONELEVEL" ):
                          cls = ClassType(className, (MaestroAction,), clsAttributes)
                       else:
                          cls = ClassType(className, (NvAction,), clsAttributes)
                       group.AddAction(cls)    

This is iterated through to build the command list for RA.

The command assigned is in the print statement and I see these iterated through correctly when I add the plugin and it creates the command list.

However, the name of the function always has the first deviceID that is parsed (name = descr + " " + deviceid) and the command that is ultimately called has the deviceid of the last deviceid parsed.

the device ID is always correct in the group name What am I doing wrong?

*Attachment removed - problem resolved - see RadioRA2 Plugin thread for download

Thanks in advance for anyone willing to take the time to help me with this.

Re: Help with adding action with values

Posted: Mon Nov 26, 2012 7:42 am
by Pako
I'd like to help.
But it is very difficult to confess in what you wrote and attached to the post.
For example:
- I installed the attached plugin. When I run EventGhost, no printing (in a loop), which you describe, I do not see
- I can nowhere find any mention of "Room A" to "Room D" in the code
- I do not own RadioRa

I think if you want to help, you must do everything you can to ensure that the problem was easily reproducible. So, for example, help if you attached the most simplified code plugin in which the described problem occurs. Also, you should describe exactly how to do that this behavior occurred.

Pako

Re: Help with adding action with values

Posted: Tue Nov 27, 2012 1:55 am
by rdgerken
Pako,

Thanks for offering to help. I have modified the plugin to "dumb it down" to the essentials to make it run and demonstrate the issue that I'm having. If you load this plugin, it will automatically run a for loop and add macros and actions on load. What you should notice is, that all actions are configured with the last parsed items values (which is not what I want). What I want it to do is to load the appropriate values for that action as they are added.

Please let me know if what I'm asking, and the example I have worked up are not enough for you to help me troubleshoot. Thanks again - I really appreciate you taking the time to help.

Re: Help with adding action with values

Posted: Tue Nov 27, 2012 9:27 am
by Pako
The problem is that you are creating classes that have the same classname.
So always then apply those attributes that were used the last time.
The solution is simple, just add an identifier to the name of the class.

Pako

Re: Help with adding action with values

Posted: Tue Nov 27, 2012 6:14 pm
by rdgerken
Thank you, thank you, and thank you again!

Re: Help with adding action with values

Posted: Wed Nov 28, 2012 3:58 am
by rdgerken
Pako,

Is there a way to access an event's payload from within the actionstringparameter dialog?

For example... when i click on my action to adjust a light's intensity, the dialog shows up, and I would enter in a 50 for 50%. That works fine. Now, i'm trying to use voxcommando to set the light level to 50 via a voxcommando generated event with a payload of 50. I just don't understand what I need to do to pass the payload value into the action.

I have voxcommand generating the event with the payload properly. It shows up as Broadcast.RoomA.Light '50', and then when i drag that event from the log to the macro where the action is defined, it shows up fine - I just don't know how to get that payload from the event linked into the action for this macro.

Thanks for your help!

Re: Help with adding action with values

Posted: Wed Nov 28, 2012 6:07 am
by Pako
rdgerken wrote:Is there a way to access an event's payload from within the actionstringparameter dialog?
This is very simple.
You must do two things:
1. Into your code, you must add the line value = eg.ParseString(value) as follows::

Code: Select all

class MyAction(eg.ActionWithStringParameter):
    name = "Action Test"
    description = "This action tests values."

    def __call__(self, value):
        value = eg.ParseString(value)
        print "Action Test called: user value   = " + value
        print "Action Test called: command value   = " + self.command
2. Configuration dialog set as follows:
eg.event.payload.jpg
Pako

Re: Help with adding action with values

Posted: Wed Nov 28, 2012 6:24 pm
by rdgerken
Excellent!

I did figure out how to accomplish this on my own using the Python Script action, but I think this may be a cleaner solution in quite a few places.

Thank you again for your help.