forked from RandyLevensalor/pynest
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate the temperature is a valid float between 50 and 90
- Loading branch information
Randy Levensalor
committed
Jan 6, 2013
1 parent
bc69abc
commit 510885f
Showing
1 changed file
with
15 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,15 @@ def help(): | |
print " nest.py --user [email protected] --password swordfish temp 73" | ||
print " nest.py --user [email protected] --password swordfish fan auto" | ||
|
||
def validate_temp(temp): | ||
try: | ||
new_temp = float(temp) | ||
except ValueError: | ||
return -1 | ||
if new_temp < 50 or new_temp > 90: | ||
return -1 | ||
return new_temp | ||
|
||
def main(): | ||
parser = create_parser() | ||
(opts, args) = parser.parse_args() | ||
|
@@ -249,10 +258,13 @@ def main(): | |
cmd = args[0] | ||
|
||
if (cmd == "temp"): | ||
if len(args)<2: | ||
print "please specify a temperature" | ||
new_temp = -1 | ||
if len(args)>1: | ||
new_temp = validate_temp(args[1]) | ||
if new_temp == -1: | ||
print "please specify a temperature between 50 and 90" | ||
sys.exit(-1) | ||
n.set_temperature(int(args[1])) | ||
n.set_temperature(new_temp) | ||
elif (cmd == "fan"): | ||
if len(args)<2 or args[1] not in {"on", "auto"}: | ||
print "please specify a fan state of 'on' or 'auto'" | ||
|