Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ def create_parser():
return parser

def help():
print "syntax: nest.py [options] command [command_args]"
print "options:"
print " --user <username> ... username on nest.com"
print " --password <password> ... password on nest.com"
print " --celsius ... use celsius (the default is farenheit)"
print " --serial <number> ... optional, specify serial number of nest to use"
print " --index <number> ... optional, 0-based index of nest"
print " (use --serial or --index, but not both)"
print
print "commands:"
print " temp <temperature> ... set target temperature"
print " fan [auto|on] ... set fan state"
print " mode [cool|heat|range|off] ... set mode state"
print " away ... toggle away"
print " show ... show everything"
print " curtemp ... print current temperature"
print " curhumid ... print current humidity"
print " curmode ... print current mode"
print " curtarget ... print current target temp"
print
print "examples:"
print " nest.py --user [email protected] --password swordfish temp 73"
print " nest.py --user [email protected] --password swordfish fan auto"
print( "syntax: nest.py [options] command [command_args]")
print( "options:")
print( " --user <username> ... username on nest.com")
print( " --password <password> ... password on nest.com")
print( " --celsius ... use celsius (the default is farenheit)")
print( " --serial <number> ... optional, specify serial number of nest to use")
print( " --index <number> ... optional, 0-based index of nest")
print( " (use --serial or --index, but not both)")
print()
print( "commands:")
print( " temp <temperature> ... set target temperature")
print( " fan [auto|on] ... set fan state")
print( " mode [cool|heat|range|off] ... set mode state")
print( " away ... toggle away")
print( " show ... show everything")
print( " curtemp ... print current temperature")
print( " curhumid ... print current humidity")
print( " curmode ... print current mode")
print( " curtarget ... print current target temp")
print()
print( "examples:")
print( " nest.py --user [email protected] --password swordfish temp 73")
print( " nest.py --user [email protected] --password swordfish fan auto")

def main():
parser = create_parser()
Expand All @@ -65,7 +65,7 @@ def main():
sys.exit(-1)

if (not opts.user) or (not opts.password):
print "how about specifying a --user and --password option next time?"
print( "how about specifying a --user and --password option next time?")
sys.exit(-1)

if opts.celsius:
Expand All @@ -81,17 +81,17 @@ def main():

if (cmd == "temp"):
if len(args)<2:
print "please specify a temperature"
print( "please specify a temperature")
sys.exit(-1)
n.set_temperature(int(args[1]))
elif (cmd == "fan"):
if len(args)<2:
print "please specify a fan state of 'on' or 'auto'"
print( "please specify a fan state of 'on' or 'auto'")
sys.exit(-1)
n.set_fan(args[1])
elif (cmd == "mode"):
if len(args)<2:
print "valid modes are cool, heat, range, and off"
print( "valid modes are cool, heat, range, and off")
sys.exit(-1)
n.set_mode(args[1])
elif (cmd == "away"):
Expand All @@ -105,10 +105,10 @@ def main():
elif (cmd == "curtarget"):
n.show_target()
elif (cmd == "curhumid"):
print n.status["device"][n.serial]["current_humidity"]
print( n.status["device"][n.serial]["current_humidity"])
else:
print "misunderstood command:", cmd
print "do 'nest.py help' for help"
print( "misunderstood command: %s" % cmd)
print( "do 'nest.py help' for help")

if __name__=="__main__":
main()
19 changes: 10 additions & 9 deletions nest_thermostat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_status(self):
response.raise_for_status()
res = response.json()

self.structure_id = res["structure"].keys()[0]
self.structure_id = list(res["structure"].keys())[0]

if (self.serial is None):
self.device_id = res["structure"][self.structure_id]["devices"][self.index]
Expand Down Expand Up @@ -79,38 +79,39 @@ def show_status(self):
allvars = shared
allvars.update(device)

for k in sorted(allvars.keys()):
print k + "."*(32-len(k)) + ":", allvars[k]
for k in sorted(allvars):
v = allvars[k] or ''
print("%s: %s" % (k, v))

def show_curtemp(self):
temp = self.status["shared"][self.serial]["current_temperature"]
temp = self.temp_out(temp)

print "%0.1f" % temp
print("%0.1f" % temp)

def show_target(self):
temp = self.status["shared"][self.serial]["target_temperature"]
temp = self.temp_out(temp)

print temp
print( temp)

def show_curmode(self):
mode = self.status["shared"][self.serial]["target_temperature_type"]

print mode
print( mode)

def _set(self, data, which):
if (self.debug): print json.dumps(data)
if (self.debug): print( json.dumps(data))
url = "%s/v2/put/%s.%s" % (self.transport_url, which, self.serial)
if (self.debug): print url
if (self.debug): print( url)
response = requests.post(url,
data = json.dumps(data),
headers = {"user-agent":"Nest/1.1.0.10 CFNetwork/548.0.4",
"Authorization":"Basic " + self.access_token,
"X-nl-protocol-version": "1"})

if response.status_code > 200:
if (self.debug): print response.content
if (self.debug): print( response.content)
response.raise_for_status()
return response

Expand Down