Last active
January 15, 2018 21:08
-
-
Save davidfg4/5287c443cdd3227dd6c1ae7a148299f4 to your computer and use it in GitHub Desktop.
This file contains 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.111", 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) | |
def getallinfo(): | |
for id in range(20): | |
tn.write("?OUTPUT,"+str(id)+",1\r\n") | |
# TODO: parse this data using tn.read_eager() | |
# Note that it may take time for data to return, recommended to wait 200 ms between each read and only finish when no more data is returned |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment