[SOLVED]Noob Python questions

Posted on
Thu Jan 09, 2014 4:32 pm
BassMint offline
Posts: 105
Joined: Dec 24, 2013

[SOLVED]Noob Python questions

1st I am a total noob to this stuff, I pick up somewhere between fast and slow and can copy/paste my ass off. So here goes.

I have 4 Onkyo Receivers to control.
I made the files for indigo to call for each function (on, off, volume, input, etc).
How do i make it so I don't have to write the same file for each device.

onkconf.py
Code: Select all
#!/usr/bin/env python
# Onkyo Receivers
import eiscp

# Create a receiver object, connecting to the host
club = eiscp.eISCP('192.168.1.202')
bar = eiscp.eISCP('192.168.1.203')
base = eiscp.eISCP('192.168.1.204')
bed = eiscp.eISCP('192.168.1.205')



onkyo_on-device.py
Code: Select all
#!/usr/bin/env python
import onkconf
import eiscp

# Create a receiver object, connecting to the host
receiver = device

# Turn the receiver on
receiver.command('power=on')
receiver.disconnect()


thats what ive come up with but I dont know what you would call it to look it up.

thanks for looking

Posted on
Thu Jan 09, 2014 5:50 pm
jay (support) offline
Site Admin
User avatar
Posts: 18260
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Noob Python questions

There are a couple of different ways to do this. The best for the community would be to write a plugin - but that takes a bit more work than just a script. That would keep you from having to write a different script for each device and it would mean that you can configure all in the UI - no scripts necessary.

From what I can tell, you're going to have to write separate scripts otherwise.

You could simplify a bit I think by creating a single file that has a function where you can pass the device ID and a command and it would just do the right thing. Then your action would be to execute a python script where you call the handler with the device ID and command. Obviously, I don't have the libraries so this is untested, but the script file would look something like this:

Code: Select all
import eiscp

myReceivers = {'club': '192.168.1.202','bar': '192.168.1.203','base': '192.168.1.204','bed': '192.168.1.205'}

def send_command(deviceName, command):
    receiver = eiscp.eISCP(myReceivers[deviceName])
    receiver.command(command)
    receiver.disconnect()


Save that file (let's call it myHandlers.py) in one of the standard Python library directories (see the docs for details).

Then, your Execute Script action would look something like this:

Code: Select all
import myHandlers
myHandlers.send_command("bar", "power=on")


Something like that anyway.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 09, 2014 9:56 pm
BassMint offline
Posts: 105
Joined: Dec 24, 2013

Re: Noob Python questions

jay (support) wrote:
Code: Select all
import eiscp

myReceivers = {'club': '192.168.1.202','bar': '192.168.1.203','base': '192.168.1.204','bed': '192.168.1.205'}

def send_command(deviceName, command):
    receiver = eiscp.eISCP(myReceivers[deviceName])
    receiver.command(command)
    receiver.disconnect()


Save that file (let's call it myHandlers.py) in one of the standard Python library directories (see the docs for details).

Then, your Execute Script action would look something like this:

Code: Select all
import myHandlers
myHandlers.send_command("bar", "power=on")


Something like that anyway.


Thanks for the response and the tips.
What you showed me works when I run as the separate file. When I tried to imped it it's telling me it cant fine the eiscp. I think it has something to do with the system using python2.7 (and eiscp installed there) and indigo is using 2.5. (as I had to put the handler file in the 2.5)
Looking around to see if i can alias or something. Im learning this as I go aong.

Posted on
Fri Jan 10, 2014 9:36 am
jay (support) offline
Site Admin
User avatar
Posts: 18260
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Noob Python questions

Yes, you need to install those 3rd party libraries in the same place you saved your handler script.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 10, 2014 3:48 pm
BassMint offline
Posts: 105
Joined: Dec 24, 2013

Re: Noob Python questions

jay (support) wrote:
Yes, you need to install those 3rd party libraries in the same place you saved your handler script.


That's what I figured. In the process of doing something I completely fubar'd the system. I'm reinstalling the OS and starting from a clean slate. I'm using a Dell Hackintosh as the host so it's a tweaking process I think I have ironed out now.

Posted on
Fri Jan 10, 2014 4:06 pm
jay (support) offline
Site Admin
User avatar
Posts: 18260
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Noob Python questions

Just FYI - we don't support unsupported Mac OS X installations.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 10, 2014 10:18 pm
BassMint offline
Posts: 105
Joined: Dec 24, 2013

Re: Noob Python questions

jay (support) wrote:
Just FYI - we don't support unsupported Mac OS X installations.


Who would? :lol:

I am building everything on a my MBP, then moving it over to the hack. It was one of those translations that went south. Something I did and undid on the MBP, didn't undo on the hack.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests