Skip to content

Commit 286ed32

Browse files
committed
Improve handling of date-time before the first schedule point
1 parent 304f0b4 commit 286ed32

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

plugwise/helper.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,19 @@ def schedules_temps(
149149
now = dt.datetime.now().time()
150150
today = dt.datetime.now().weekday()
151151
day_0 = schedule_list[i][0]
152-
day_1 = schedule_list[j][0]
153-
# Roll over from end to beginning of schedule = monday
154-
if j < i:
155-
day_1 = 7 # day 7 = day 0
156152
time_0 = schedule_list[i][1]
153+
day_1 = schedule_list[j][0]
157154
time_1 = schedule_list[j][1]
155+
# Handle Monday-now is before first schedule point
156+
if i == 0 and now < time_0:
157+
before_first = True
158+
first_schedule_day = day_0
159+
# Roll over from end to beginning of schedule = next Monday
160+
if j < i:
161+
day_1 = first_schedule_day + 7 # day_7 = day_0, day_8 = day_1 etc.
162+
# Roll over to next Monday when now is before first schedule point
163+
if today == 0 and before_first:
164+
today = 7
158165
if in_between(today, day_0, day_1, now, time_0, time_1):
159166
return schedule_list[i][2]
160167

0 commit comments

Comments
 (0)