Python and Airfoil

Posted on
Mon Oct 16, 2017 9:19 pm
jltnol offline
Posts: 322
Joined: Oct 15, 2013

Python and Airfoil

So I've read the Wiki for AirFoil, and it has been a big help, since my Python ability is limited. I am curious about "chaining" commands... like the ability to connect 2 different speakers... or connect a speaker and set the volume....

While the following does work, I'm curious is there is a simpler way to do this, since most of the 2 commands are identical. I've tried a few things, re-arranging pieces, parts, deleting things that seemed redundant, including listing the execute actions part in (parentheses) back to back, then with a space, and then with a comma, but didn't get anywhere..

Is there a way to make multiple commands like this simpler?



Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction("connect", deviceId= 1346544642, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred: %s" % unicode(e)


airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction('setVolume', deviceId=1346544642, props={'volume': 52}, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred: %s" % unicode(e)

Posted on
Tue Oct 17, 2017 4:16 am
FlyingDiver offline
Posts: 2611
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python and Airfoil

Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction("connect", deviceId= 1346544642, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred  on connect: %s" % unicode(e)
    try:
        result = airfoilPlugin.executeAction('setVolume', deviceId=1346544642, props={'volume': 52}, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred on setVolume: %s" % unicode(e)

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

Posted on
Tue Oct 17, 2017 6:49 am
jltnol offline
Posts: 322
Joined: Oct 15, 2013

Re: Python and Airfoil

Thanks ever so much

this is one of the combos that I tried, but obviously didn't have something exactly right.

Posted on
Tue Oct 17, 2017 6:52 am
FlyingDiver offline
Posts: 2611
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python and Airfoil

Notice I added text to identify which exception was caught. You probably want to change the print statements to indigo log statements.

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

Posted on
Tue Oct 17, 2017 9:53 am
jay (support) offline
Site Admin
User avatar
Posts: 14880
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python and Airfoil

You could further simplify by putting all calls in the same try block:

Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction("connect", deviceId= 1346544642, waitUntilDone=True)  # ID of Speaker device
        result = airfoilPlugin.executeAction('setVolume', deviceId=1346544642, props={'volume': 52}, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred: %s" % unicode(e)


Exceptions here are pretty unlikely, so my guess is that if the first one works the second one will almost always work, and any exception you get will very likely be because of some systemic problem and you're probably seeing a LOT of other problems as well.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests