-
-
Save therg/82d8041a96819af9acfe89700bc41a0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time | |
import telnetlib | |
def inittn(): | |
tn = telnetlib.Telnet("192.168.1.24", 23, 3) | |
tn.read_until("login:") | |
tn.write("lutron\r\n") | |
tn.read_until("password:") | |
tn.write("integration\r\n") | |
return tn | |
def closetn(tn): | |
time.sleep(1) | |
tn.close() | |
def setlight(id, value=75, fadetime=1): | |
tn = inittn() | |
tn.write("#OUTPUT,"+str(id)+",1,"+str(value)+","+str(fadetime)+"\r\n") | |
closetn(tn) | |
def pressbutton(panel, button, value=3): | |
tn = inittn() | |
tn.write("#DEVICE,"+str(panel)+","+str(button)+","+str(value)+"\r\n") | |
closetn(tn) | |
if __name__ == "__main__": | |
import cgi | |
import cgitb | |
cgitb.enable(display=0, logdir="/tmp") | |
print("Content-Type: text/html") | |
print("") | |
form = cgi.FieldStorage() | |
type = form.getfirst("type", "").upper() | |
id = form.getfirst("id", "").upper() | |
id2 = form.getfirst("id2", "").upper() | |
value = form.getfirst("value", "").upper() | |
button = form.getfirst("button", "").upper() | |
if (type == "DEVICE"): | |
pressbutton(id, id2) | |
print("button " + str(id) + " pressed") | |
elif (type == "OUTPUT"): | |
setlight(id, value) | |
print("light " + str(id) + " set to " + str(value)) | |
else: | |
print("invalid command") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment