From 94c3f8238e50feae189637e6466ac777e34f287a Mon Sep 17 00:00:00 2001 From: Christian Iuga Date: Wed, 27 Sep 2023 15:01:26 +0200 Subject: [PATCH 1/2] Fix issue #32 ( https://github.com/oncleben31/ha-pool_pump/issues/32 ) --- src/pypool_pump/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pypool_pump/__init__.py b/src/pypool_pump/__init__.py index 465e17f..1bc3332 100644 --- a/src/pypool_pump/__init__.py +++ b/src/pypool_pump/__init__.py @@ -42,6 +42,15 @@ def update_schedule(self,pivot_time:datetime) -> List[Run]: second_start = pivot_time + timedelta(hours=2/3 * self._schedule_config['break_duration']) second_duration = 2 * first_duration + # If second_start + second_duration > 0h00 : update first_start with (second_start + second_duration - 0h00) + if second_start + timedelta(hours=second_duration) >= datetime.combine(second_start, datetime.max.time(), second_start.tzinfo): + delta = second_start + timedelta(hours=second_duration) - datetime.combine(second_start + timedelta(hours=second_duration), datetime.min.time(), second_start.tzinfo) + # First start need to be earlier + first_start = first_start - delta + # TODO: Update first_duration + first_duration = int( (pivot_time - first_start).total_seconds() ) / 3600 + # TODO: Update second_duration + second_duration = int( ( datetime.combine(second_start, datetime.max.time(), second_start.tzinfo) - pivot_time ).total_seconds() ) / 3600 return [Run(first_start, first_duration), Run(second_start, second_duration)] From 748eaed726fb5738b378a14ea3e2051e9241c737 Mon Sep 17 00:00:00 2001 From: Christian Iuga Date: Wed, 27 Sep 2023 15:11:15 +0200 Subject: [PATCH 2/2] remove TODO comments as it's done --- src/pypool_pump/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pypool_pump/__init__.py b/src/pypool_pump/__init__.py index 1bc3332..4fc1ae0 100644 --- a/src/pypool_pump/__init__.py +++ b/src/pypool_pump/__init__.py @@ -47,9 +47,9 @@ def update_schedule(self,pivot_time:datetime) -> List[Run]: delta = second_start + timedelta(hours=second_duration) - datetime.combine(second_start + timedelta(hours=second_duration), datetime.min.time(), second_start.tzinfo) # First start need to be earlier first_start = first_start - delta - # TODO: Update first_duration + # Update first_duration first_duration = int( (pivot_time - first_start).total_seconds() ) / 3600 - # TODO: Update second_duration + # Update second_duration second_duration = int( ( datetime.combine(second_start, datetime.max.time(), second_start.tzinfo) - pivot_time ).total_seconds() ) / 3600 return [Run(first_start, first_duration), Run(second_start, second_duration)]