-
Notifications
You must be signed in to change notification settings - Fork 2
/
ir_emit.py
executable file
·61 lines (54 loc) · 1.48 KB
/
ir_emit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# ir_emit
#
# When a new song is queued, turn on the stereo system
# When player is paused, stopped or turns off, turn off stereo
# When signalled to quit, turn off the stereo system
import subprocess, time, socket, urllib
def stereoShouldTurnOn(str):
return False
def stereoShouldTurnOff(str):
return False
def turnOnStereo():
global stereoOn
if stereoOn:
return
proc = ['/usr/bin/irsend', '-d', '/dev/lircd1', 'send_once', 'Panasonic_EUR7702260', 'poweron', 'dvd', 'dvd', 'dvd']
res = subprocess.call(proc)
print 'turnOnStereo: res: ' + str(res)
if res != 0:
print 'turnOnStereo: retrying irsend'
time.sleep(2)
subprocess.call(proc)
stereoOn = True
def turnOffStereo():
global stereoOn
if not stereoOn:
return
proc = ['/usr/bin/irsend', '-d', '/dev/lircd1', 'send_once', 'Panasonic_EUR7702260', 'poweroff']
res = subprocess.call(proc)
print 'turnOffStereo: res: ' + str(res)
if res != 0:
print 'turnOffStereo: retrying irsend'
time.sleep(2)
subprocess.call(proc)
stereoOn = False
stereoOn = False
s = socket.create_connection(['localhost','9090'])
if s is None:
print 'Error: unable to connect to socket'
else:
s.send('listen\n')
s.recv(1024)
while True:
data = s.recv(1024)
if data:
#REVISIT: split into single lines of output
data = urllib.unquote(data).rstrip('\n')
print 'Data received: ' + data
if stereoShouldTurnOn(data):
turnOnStereo()
if stereoShouldTurnOff(data):
turnOffStereo()
else:
print 'No data received'