Skip to content

Instantly share code, notes, and snippets.

@lukesnow
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukesnow/b4d29f949c59dafaf5d0 to your computer and use it in GitHub Desktop.
Save lukesnow/b4d29f949c59dafaf5d0 to your computer and use it in GitHub Desktop.
thermostat
# coding: utf-8
import ui
import paramiko
maxwell='192.168.X.X'
class Thermo(object):
def __init__(self):
pass
def oneshot(self, minutes):
self.strcommand='nohup /home/thermostat/bin/one-shot.sh ' + minutes + ' && exit &'
self.send_command(self.strcommand)
def turnoff(self):
self.strcommand='/home/USERNAME/bin/turn-off.sh'
self.send_command(self.strcommand)
def turnon(self):
self.strcommand='/home/USERNAME/bin/turn-on.sh'
self.send_command(self.strcommand)
def send_command(self, strcommand):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=maxwell, username="USERNAME", password="PASSWORD")
stdin, stdout, stderr = client.exec_command(strcommand)
stdin, stdout, stderr = client.exec_command('/home/thermostat/bin/thermostatus.sh')
client.close()
stdout.read()
def button_tapped(sender):
# Get information from form.
'@type sender: ui.Button'
t = sender.title
label = sender.superview['label2']
label.text = 'Please wait...'
nummins = sender.superview['textfield1']
number_of_minutes = nummins.text
# Run command based on form.
# response = send_command(number_of_minutes)
therm = Thermo()
therm.oneshot(number_of_minutes)
label.text = 'Success'
def button_tappedOn(sender):
# Get information from form.
'@type sender: ui.Button'
t = sender.title
label = sender.superview['label2']
label.text = 'Please wait...'
# Run command based on form.
# response = send_command(number_of_minutes)
therm = Thermo()
therm.turnon()
label.text = 'Success'
def button_tappedOff(sender):
# Get information from form.
'@type sender: ui.Button'
t = sender.title
label = sender.superview['label2']
label.text = 'Please wait...'
# Run command based on form.
# response = send_command(number_of_minutes)
therm = Thermo()
therm.turnoff()
label.text = 'Success'
v = ui.load_view('thermostat')
if ui.get_screen_size()[1] >= 768:
# iPad
v.present('popover')
else:
# iPhone
v.present(orientations=['portrait'])
[{"class":"View","attributes":{"background_color":"RGBA(1.000000,1.000000,1.000000,1.000000)","tint_color":"RGBA(0.000000,0.478000,1.000000,1.000000)","enabled":true,"border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","flex":""},"frame":"{{0, 0}, {540, 575}}","nodes":[{"class":"Label","attributes":{"font_size":17,"enabled":true,"text":" The Snows Thermostat","flex":"","name":"label1","border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","text_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","alignment":"left","uuid":"B0BE98F8-0656-4A77-B4E1-ABF1C18433B0"},"frame":"{{99, 25}, {341.5, 32}}","nodes":[]},{"class":"TextField","attributes":{"font_size":17,"enabled":true,"flex":"","name":"textfield1","border_style":3,"text_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","alignment":"left","border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","placeholder":"Enter thermostat time in minutes.","uuid":"A6CA1F3F-FA39-4717-90D9-E425738E6DA9"},"frame":"{{126, 116}, {286.5, 32}}","nodes":[]},{"class":"Button","attributes":{"font_size":15,"enabled":true,"flex":"","font_bold":false,"name":"button1","uuid":"E2340DDE-5B4D-4D2E-8388-4CADC4E5AE4F","border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","action":"button_tapped","title":"Go"},"frame":"{{201, 187}, {136.5, 32}}","nodes":[]},{"class":"Label","attributes":{"font_size":17,"enabled":true,"text":" Status","flex":"","name":"label2","border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","text_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","alignment":"left","uuid":"76BC272A-312A-4AAC-BA18-ADE45F055AE1"},"frame":"{{195, 271}, {150, 32}}","nodes":[]},{"class":"Button","attributes":{"font_size":15,"enabled":true,"flex":"","font_bold":false,"name":"button2","uuid":"D9CD3FAA-5E94-41E2-8641-4DD6230F0000","border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","action":"button_tappedOn","title":"Turn On"},"frame":"{{201, 390}, {136.5, 32}}","nodes":[]},{"class":"Button","attributes":{"font_size":15,"enabled":true,"flex":"","font_bold":false,"name":"button3","uuid":"C62C1925-E836-4E73-A028-0D652ACDB6C2","border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","action":"button_tappedOff","title":"Turn Off"},"frame":"{{201, 440}, {136.5, 32}}","nodes":[]}]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment