Page 1 of 1

Python and Airfoil

PostPosted: Mon Oct 16, 2017 9:19 pm
by jltnol
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)

Re: Python and Airfoil

PostPosted: Tue Oct 17, 2017 4:16 am
by FlyingDiver
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)

Re: Python and Airfoil

PostPosted: Tue Oct 17, 2017 6:49 am
by jltnol
Thanks ever so much

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

Re: Python and Airfoil

PostPosted: Tue Oct 17, 2017 6:52 am
by FlyingDiver
Notice I added text to identify which exception was caught. You probably want to change the print statements to indigo log statements.

Re: Python and Airfoil

PostPosted: Tue Oct 17, 2017 9:53 am
by jay (support)
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.