diff --git a/nest.py b/nest.py index 2f1fa50..5e523f6 100755 --- a/nest.py +++ b/nest.py @@ -32,29 +32,29 @@ def create_parser(): return parser def help(): - print "syntax: nest.py [options] command [command_args]" - print "options:" - print " --user ... username on nest.com" - print " --password ... password on nest.com" - print " --celsius ... use celsius (the default is farenheit)" - print " --serial ... optional, specify serial number of nest to use" - print " --index ... optional, 0-based index of nest" - print " (use --serial or --index, but not both)" - print - print "commands:" - print " temp ... 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 joe@user.com --password swordfish temp 73" - print " nest.py --user joe@user.com --password swordfish fan auto" + print( "syntax: nest.py [options] command [command_args]") + print( "options:") + print( " --user ... username on nest.com") + print( " --password ... password on nest.com") + print( " --celsius ... use celsius (the default is farenheit)") + print( " --serial ... optional, specify serial number of nest to use") + print( " --index ... optional, 0-based index of nest") + print( " (use --serial or --index, but not both)") + print() + print( "commands:") + print( " temp ... 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 joe@user.com --password swordfish temp 73") + print( " nest.py --user joe@user.com --password swordfish fan auto") def main(): parser = create_parser() @@ -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: @@ -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"): @@ -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() diff --git a/nest_thermostat/__init__.py b/nest_thermostat/__init__.py index 34a488b..9742c1c 100644 --- a/nest_thermostat/__init__.py +++ b/nest_thermostat/__init__.py @@ -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] @@ -79,30 +79,31 @@ 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", @@ -110,7 +111,7 @@ def _set(self, data, which): "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