Skip to content

Commit

Permalink
Add function to shift runs
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Nov 30, 2023
1 parent 084b1e1 commit d1ee479
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions custom_components/irrigation_unlimited/irrigation_unlimited.py
Original file line number Diff line number Diff line change
Expand Up @@ -2645,6 +2645,50 @@ def next_sequence_zone(
break
return result

def advance(
self, stime: datetime, duration: timedelta, runs: list[IURun] = None
) -> None:
"""Advance the sequence run. If duration is positive runs will be
extended if running or delayed if in the future. If duration is
negative runs will shortened or even skipped. The system will
require a full muster as the status of runs, zones and sequences
could have altered."""

def update_run(stime: datetime, duration: timedelta, run: IURun) -> None:
if run is None or run.expired:
return
if duration > timedelta(0):
if run.running:
run.end_time += duration
elif run.future:
run.start_time += duration
run.end_time += duration
else:
if run.running:
run.end_time = max(run.end_time + duration, run.start_time)
elif run.future:
run.start_time = max(run.start_time + duration, stime)
run.end_time = max(run.end_time + duration, run.start_time)
run.duration = run.end_time - run.start_time
run.update_status(stime)
run.update_time_remaining(stime)

if self.running:
if runs is None:
runs = self.runs
for run in runs:
update_run(stime, duration, run)
if run.master_run is not None:
update_run(stime, duration, run.master_run)

end_time: datetime = None
for run in self.runs:
if end_time is None or run.end_time > end_time:
end_time = run.end_time
self._end_time = end_time

self.update()

def update(self) -> bool:
"""Update the status of the sequence"""
result = False
Expand Down

0 comments on commit d1ee479

Please sign in to comment.