Skip to content

Commit cf44b80

Browse files
authored
Update devices.py
1 parent 51ea01f commit cf44b80

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

devices.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
timestamp = time.strftime("Time: %H:%M, Date: %Y%m%d, ")
44
print timestamp
55
for device in requests.get('http://localhost/api/devices').json():
6-
if device['offUrl'].find('heyu') != -1:
6+
if device['onUrl'].find('heyu') != -1:
77
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")
99
if chtxt.find('dimlevel') != -1:
1010
proc = subprocess.Popen([chtxt], stdout=subprocess.PIPE, shell=True)
1111
(dimlevel, err) = proc.communicate()
@@ -15,9 +15,13 @@
1515
state = "true"
1616
else:
1717
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)
2024
else:
2125
print "Device ID %s is an X10 command (%s)" % (device['id'], device['name'])
2226
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

Comments
 (0)