|
3 | 3 | timestamp = time.strftime("Time: %H:%M, Date: %Y%m%d, ") |
4 | 4 | print timestamp |
5 | 5 | for device in requests.get('http://localhost/api/devices').json(): |
6 | | - if device['offUrl'].find('heyu') != -1: |
| 6 | + if device['onUrl'].find('heyu') != -1: |
7 | 7 | url = "http://localhost/api/c/lights/%s/bridgeupdatestate" % device['id'] |
8 | | - chtxt = device['offUrl'].replace("foff", "dimlevel").replace("off","dimlevel") |
| 8 | + chtxt = device['onUrl'].replace("python", "").replace(",", "").replace(":", "").replace("\"", "").replace("item", "").replace("typenull", "").replace("typecmdDevice", "").replace("[{", "").replace("}]", "").replace("fon", "dimlevel").replace("on","dimlevel") |
9 | 9 | if chtxt.find('dimlevel') != -1: |
10 | 10 | proc = subprocess.Popen([chtxt], stdout=subprocess.PIPE, shell=True) |
11 | 11 | (dimlevel, err) = proc.communicate() |
|
15 | 15 | state = "true" |
16 | 16 | else: |
17 | 17 | state = "false" |
18 | | - print "Device ID %s set to %s at dim level %s (%s)" % (device['id'], state, dimlevel, device['name']) |
19 | | - r = requests.put(url, json={"on":state, "bri":dimlevel}) |
| 18 | + payload = "{\"on\":%s" % state |
| 19 | + if state == "true": |
| 20 | + payload = "%s, \"bri\":%s" % (payload, dimlevel) |
| 21 | + payload = "%s}" % payload |
| 22 | + print "Device ID %s set to %s (%s)" % (device['id'], payload, device['name']) |
| 23 | + r = requests.put(url, data=payload) |
20 | 24 | else: |
21 | 25 | print "Device ID %s is an X10 command (%s)" % (device['id'], device['name']) |
22 | 26 | else: |
23 | | - print "Device ID %s not an X10 device (%s)" % (device['id'], device['name']) |
| 27 | + print "Device ID %s not an X10 device (%s) - [%s]" % (device['id'], device['name'], device['mapType']) |
0 commit comments