Skip to content

Commit e8d4a66

Browse files
committed
refactor whichDay() fucntion
1 parent c7d3e83 commit e8d4a66

1 file changed

Lines changed: 19 additions & 33 deletions

File tree

PyPortal_Wakeup_Light/wake_up_light.py

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
up_time_friday = default_wake_up
2020
up_time_saturday = "10:00A"
2121
up_time_sunday = "10:00A"
22+
wake_up_times = (up_time_monday,
23+
up_time_tuesday,
24+
up_time_wednesday,
25+
up_time_thursday,
26+
up_time_friday,
27+
up_time_saturday,
28+
up_time_sunday)
2229

2330
# set neopixel min and max brightness
2431
BRIGHTNESS = 0
@@ -78,38 +85,17 @@ def whichDay():
7885
wake_up_minutes = int(wake_up_minutes[:-1])
7986
print(wake_up_hour, ":", wake_up_minutes)
8087
# if it's after midnight and before the default wakeup time, display the wake up time of today
81-
if current_hour < wake_up_hour and current_minutes < wake_up_minutes:
82-
print("midnight")
83-
if current_day == 0:
84-
input_wake_up_time = up_time_monday
85-
elif current_day == 1:
86-
input_wake_up_time = up_time_tuesday
87-
elif current_day == 2:
88-
input_wake_up_time = up_time_wednesday
89-
elif current_day == 3:
90-
input_wake_up_time = up_time_thursday
91-
elif current_day == 4:
92-
input_wake_up_time = up_time_friday
93-
elif current_day == 5:
94-
input_wake_up_time = up_time_saturday
95-
elif current_day == 6:
96-
input_wake_up_time = up_time_sunday
97-
98-
else: # set wake up time to the next day's wake up time the night before
99-
if current_day == 6:
100-
input_wake_up_time = up_time_monday
101-
elif current_day == 0:
102-
input_wake_up_time = up_time_tuesday
103-
elif current_day == 1:
104-
input_wake_up_time = up_time_wednesday
105-
elif current_day == 2:
106-
input_wake_up_time = up_time_thursday
107-
elif current_day == 3:
108-
input_wake_up_time = up_time_friday
109-
elif current_day == 4:
110-
input_wake_up_time = up_time_saturday
111-
elif current_day == 5:
112-
input_wake_up_time = up_time_sunday
88+
for day in range(len(wake_up_times)):
89+
if current_hour < wake_up_hour and current_minutes < wake_up_minutes:
90+
if current_day == day:
91+
input_wake_up_time = wake_up_times[day]
92+
# set wake up time to the next day's wake up time the night before
93+
else:
94+
if current_day == 6:
95+
input_wake_up_time = wake_up_times[0]
96+
else:
97+
if current_day == day:
98+
input_wake_up_time = wake_up_times[day+1]
11399
input_wake_up_time_text = "Wake up at " + input_wake_up_time
114100
wakeup_time_textarea.text = input_wake_up_time_text
115101
return input_wake_up_time
@@ -209,4 +195,4 @@ def displayTime():
209195
continue
210196
strip.brightness = MIN_BRIGHTNESS
211197
# update every 15 seconds
212-
time.sleep(15)
198+
time.sleep(15)

0 commit comments

Comments
 (0)