-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewLightControl.py
executable file
·63 lines (52 loc) · 1.39 KB
/
NewLightControl.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
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import xml.etree.ElementTree as ET
from os.path import expanduser
import logging
import logging.handlers
import httplib
import time
import urllib
from tellcore.telldus import TelldusCore, Device
def LampON():
device = Device(4)
device.turn_on()
def LampOFF():
device = Device(4)
device.turn_off()
serverURL = 'http://192.168.1.55:32400/status/sessions'
state = ''
playstatus = ''
core = TelldusCore()
while True:
server = urllib2.urlopen(serverURL) # Replace the IP and Port with those of your server
data = server.read()
server.close()
tree = ET.fromstring(data)
for video in tree.iter('Video'):
state = video.find('Player').get('state')
# Playstatus displays current status, and is initialized from null
# State is the value read from the player, the difference from last status (Playstatus) determines action
if playstatus == 'playing':
if state == 'paused':
#Changed from playing2paused
LampON()
playstatus = 'paused'
elif state == '':
playstatus = ''
LampON()
if playstatus == 'paused':
if state == 'playing':
playstatus = 'playing'
#Changed from paused2playing
LampOFF()
elif state == '':
playstatus = ''
LampON()
if playstatus == '':
if state == 'playing':
playstatus = 'playing'
LampOFF()
time.sleep(3)
state = ''