From d40ed3e563779c985b0efab0fce483bb531fe824 Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Wed, 7 Oct 2026 16:03:11 +0200 Subject: [PATCH] =?UTF-8?q?Verbraucher:=20Laufzeit-Z=C3=A4hler=20bei=20Bet?= =?UTF-8?q?riebspause=20pausieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/control/consumer/consumer.py | 2 ++ packages/control/consumer/consumer_test.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/control/consumer/consumer.py b/packages/control/consumer/consumer.py index 35fe38de03..0134bed4c3 100644 --- a/packages/control/consumer/consumer.py +++ b/packages/control/consumer/consumer.py @@ -91,6 +91,8 @@ def process_on_time(self): self.data.set.timestamp_wrote_last_on_time = now self.data.set.on_time += now - self.data.set.timestamp_wrote_last_on_time self.data.set.timestamp_wrote_last_on_time = now + else: + self.data.set.timestamp_wrote_last_on_time = None def reset_on_time(self): self.data.set.on_time = 0 diff --git a/packages/control/consumer/consumer_test.py b/packages/control/consumer/consumer_test.py index 1ed387eeef..a871b55f38 100644 --- a/packages/control/consumer/consumer_test.py +++ b/packages/control/consumer/consumer_test.py @@ -182,6 +182,26 @@ def test_wait_for_start_handler_standby_threshold_depends_on_usage_type( assert charging_func.call_count == 0 +def test_process_on_time_pauses_when_charge_state_is_false( + consumer: Consumer, + monkeypatch: pytest.MonkeyPatch): + # setup + monkeypatch.setattr(timecheck, "create_timestamp", Mock(side_effect=[100, 130, 160])) + + # execution + consumer.data.get.charge_state = True + consumer.process_on_time() # Start bei t=100 + consumer.data.get.charge_state = False + consumer.process_on_time() # Pause: Zeitstempel wird verworfen + consumer.data.get.charge_state = True + consumer.process_on_time() # Neustart bei t=130 ohne Nachlauf aus Pause + consumer.process_on_time() # Laufzeit von 30s wird gezaehlt + + # evaluation + assert consumer.data.set.on_time == 30 + assert consumer.data.set.timestamp_wrote_last_on_time == 160 + + @pytest.mark.parametrize( "plans, plan_found, expected", [