View unanswered posts | View active topics It is currently Sat May 25, 2013 5:32 pm



Reply to topic  [ 32 posts ]  Go to page: 1, 2, 3  Next
 Using variables in Python with DirectTV Plugin 
Author Message

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Using variables in Python with DirectTV Plugin
Having totally driven myself crazy, I need a little help with what should be a very simple script. But I couldn't find the answer in any of the examples.

I'm using the DirectTV Plugin, which I like a lot. But I have a bunch of DirecTV Boxes and have a variable the user sets by a toggle identifying the particular room where the box is located and it sets the ip address for that box. That variable is DVR_Address.

All I want to do is use that variable in the command to send a key press or channel request, but I can't seem to get it to work. The basic code for the plugin is:

dvrPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.directvdvrcontrol")
if dvrPlugin.isEnabled():
dvrPlugin.executeAction("sendKeyPress", props={'address': 'xxx.xxx.xxx.xxx', 'keyToPress':"menu"})

How do I substitute the indigo variable DVR_Address for the address property?

Any help will be much appreciated.

BTW, I also tried putting the variable name (in quotes or not) in the Address field for the plugin in the pop-up. That didn't work either, but it would be nice to use a variable in those fields. It would make it much more versatile....


Thu Dec 15, 2011 9:56 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Using variables in Python with DirectTV Plugin
Code: Select all
dvrPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.directvdvrcontrol")
if dvrPlugin.isEnabled():
    address = indigo.variables[VARIABLEID]
    dvrPlugin.executeAction("sendKeyPress", props={'address': address.value,  'keyToPress':"menu"})

_________________
Jay (Indigo Support)
Image


Thu Dec 15, 2011 10:44 pm
Profile WWW

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Re: Using variables in Python with DirectTV Plugin
Ahhh. Address.value. Thanks

Maybe I missed it, but I didn't see any example of anything like that in any of the docs. It would be helpful for other morons like me....


Fri Dec 16, 2011 8:21 am
Profile

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Re: Using variables in Python with DirectTV Plugin
One further question.

Does Python include the ability to define methods which are loaded with the server like we could with AppleScript attachments? As I mentioned, I have 4 rooms with DirecTV boxes, each with a different IP address. Can I create a user defined method in a global file to be called by any Python script that lets me do something like this:

room= indigo.variable[ID]
IPAddress = GetIPAddress(room.value)

I know I could do that with AppleScript so I hope the Python implementation doesn't take that away, but I don't see where that would be set up.

Thanks


Fri Dec 16, 2011 8:40 am
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Using variables in Python with DirectTV Plugin
kennybroh wrote:Maybe I missed it, but I didn't see any example of anything like that in any of the docs. It would be helpful for other morons like me....


A couple of places where variable examples are in the docs: Scripting Tutorial and the Variable class page.

kennybroh wrote: Does Python include the ability to define methods which are loaded with the server like we could with AppleScript attachments? As I mentioned, I have 4 rooms with DirecTV boxes, each with a different IP address.


While your example is a bit contrived (room.value IS the IP address, right?), I understand your question. There is a mechanism that Python uses - unfortunately it's broken at the moment for embedded and script files (it does work for interactive shells). We'll get to the bottom of that bug in an upcoming release.

_________________
Jay (Indigo Support)
Image


Fri Dec 16, 2011 11:05 am
Profile WWW

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Re: Using variables in Python with DirectTV Plugin
Actually it isn't contrived. The value of room is "Kitchen" "Study" etc. There is a control which cycles through choices of those variables, including "All" and they are used for a variety of things enablling me to use one control page to control different things depending on the variable's value. So if the room is kitchen, the directtv method would return the ip address for the directv box, and similar methods could be used for addresses or information about other devices, say the ip address of a sonos box, which I also have. (BTW, a Sonos plugin would be AWESOME....)

BTW, I looked at those examples and the class docs before posting this question and in the tutorial about variables all I saw were examples creating, updating, duplicating and deleting variables. I didn't see any code there or in the DirecTV Plugin script docs to get the value of a variable and use it in another method. Let me know where it is if I missed it.


Fri Dec 16, 2011 11:18 am
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Using variables in Python with DirectTV Plugin
Classes are a basic Python concept (just like they are in AppleScript) so using a property (aka instance variable) of an object is a basic function of using Python. Our IOM specific documentation is already quite large and takes a significant amount of time to develop and maintain - we have to assume a certain level of knowledge about Python (just like we did with AppleScript but the IOM docs are significantly better than the AS docs were). Here's a good discussion of Python's object-orientation.

I'll add an example of using the variable object's value property to the tutorial - but we can't spend the time documenting all of Python's features and all possible combinations in addition to documenting our software.

_________________
Jay (Indigo Support)
Image


Fri Dec 16, 2011 12:31 pm
Profile WWW
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Using variables in Python with DirectTV Plugin
jay wrote:There is a mechanism that Python uses - unfortunately it's broken at the moment for embedded and script files (it does work for interactive shells). We'll get to the bottom of that bug in an upcoming release.


We were just pointing to the wrong folder in the link above - the instructions in the documentation now point to the right folder and it works like a charm.

_________________
Jay (Indigo Support)
Image


Fri Dec 16, 2011 4:16 pm
Profile WWW

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Re: Using variables in Python with DirectTV Plugin
Thanks. I assume that will make clear where I define the class and its behavior...


Fri Dec 16, 2011 4:39 pm
Profile

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Re: Using variables in Python with DirectTV Plugin
Just read the first couple of lines and its obviously dead on and exactly what I was hoping for. Cool.


Fri Dec 16, 2011 4:40 pm
Profile

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Re: Using variables in Python with DirectTV Plugin
One question: the "import indigoAttachments" goes in any script in which I want to use the particular methods? There's no way to load that once for the Indigo Server?


Fri Dec 16, 2011 4:54 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Using variables in Python with DirectTV Plugin
Nope.

_________________
Jay (Indigo Support)
Image


Fri Dec 16, 2011 5:35 pm
Profile WWW

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Re: Using variables in Python with DirectTV Plugin
That means it precedes any call to a class or method I've defined in each script. Are you considering loading it once?


Fri Dec 16, 2011 5:46 pm
Profile

Joined: Dec 13, 2009
Posts: 192
Location: Baltimore
Post Re: Using variables in Python with DirectTV Plugin
OK, the $64 question: can I put plugin calls and other indigo commands into the methods I'm creating? E.g. could the getplugin commands and the actual calls be part of a method so all my script has to do is pass in values? Could the indigo.variable[ID] be in a user defined method?


Fri Dec 16, 2011 5:57 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Using variables in Python with DirectTV Plugin
Are you considering loading it once?


Probably not. This behavior is how Python works - you only import the libs that you need. Not every script is going to need all the handler files and it's much more difficult to track down problems with libraries are auto-loaded.

could the getplugin commands and the actual calls be part of a method so all my script has to do is pass in values? Could the indigo.variable[ID] be in a user defined method?


As the example script on that link shows/says, yes, as long as the script is run by Indigo, you have access to the full IOM (with a few exceptions that are server plugin specific - e.g. updating plugin props and plugin device states).

_________________
Jay (Indigo Support)
Image


Fri Dec 16, 2011 9:09 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 32 posts ]  Go to page: 1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.