Skip to content

Commit

Permalink
fixed bug by adding type conversion to input
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Burke committed Nov 26, 2017
1 parent da847b7 commit 9d0d808
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions light-schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,32 @@ def parse_transition_params(params):


func = getattr(device, args.action)

if args.action == 'transition':
#special case
new_attr, duration, start_time = parse_transition_params(args.params)
resp = func(new_attr, duration, start_time)

else:
if args.params:
resp = func(args.params)
elif args.action == 'lightswitch':
# convert to bool
test_arg = args.params[0].lower()
if test_arg == 'true' or test_arg == '1':
func_input = True
elif test_arg == 'false' or test_arg == '0':
func_input = False
else:
resp = func()
func_input = None
# lightswitch() function defaults to True if no input.

resp = func(func_input)

elif args.action in ['set_brightness','set_color','mireds_to_kelvin','kelvin_to_mireds']:
resp = func(int(params[0]))

# Above are just the commonly used functions.
# There's nothing to stop user from calling a lower-level/internal function here, but args won't be used, so some may fail.
else:
resp = func()

if resp:
from pprint import pprint
Expand Down

0 comments on commit 9d0d808

Please sign in to comment.