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", [