Skip to content

Commit 8217257

Browse files
authored
fix timestamp text (#1646)
* fix timestamp text * review
1 parent 1606e94 commit 8217257

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

packages/control/auto_phase_switch_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self,
6565
Params("1to3, enough power, start timer", max_current_single_phase=16, timestamp_auto_phase_switch=None,
6666
phases_to_use=1, required_current=6, evu_surplus=-800, reserved_evu_overhang=0, get_currents=[15.6, 0, 0],
6767
get_power=3450, state=ChargepointState.CHARGING_ALLOWED, expected_phases_to_use=1, expected_current=6,
68-
expected_message=Ev.PHASE_SWITCH_DELAY_TEXT.format("Umschaltung von 1 auf 3", "7 Min. 0 Sek."),
68+
expected_message=Ev.PHASE_SWITCH_DELAY_TEXT.format("Umschaltung von 1 auf 3", "7 Min."),
6969
expected_timestamp_auto_phase_switch=1652683252.0,
7070
expected_state=ChargepointState.PHASE_SWITCH_DELAY),
7171
Params("1to3, not enough power, start timer", max_current_single_phase=16, timestamp_auto_phase_switch=None,
@@ -76,7 +76,7 @@ def __init__(self,
7676
timestamp_auto_phase_switch=1652682952.0, phases_to_use=1, required_current=6,
7777
evu_surplus=-1200, reserved_evu_overhang=460, get_currents=[15.6, 0, 0], get_power=3450,
7878
state=ChargepointState.PHASE_SWITCH_DELAY, expected_phases_to_use=1, expected_current=6,
79-
expected_message=Ev.PHASE_SWITCH_DELAY_TEXT.format("Umschaltung von 1 auf 3", "2 Min. 0 Sek."),
79+
expected_message=Ev.PHASE_SWITCH_DELAY_TEXT.format("Umschaltung von 1 auf 3", "2 Min."),
8080
expected_timestamp_auto_phase_switch=1652683252.0,
8181
expected_state=ChargepointState.PHASE_SWITCH_DELAY),
8282
Params("1to3, not enough power, timer not expired", max_current_single_phase=16,
@@ -96,15 +96,15 @@ def __init__(self,
9696
phases_to_use=3, required_current=6, evu_surplus=0, reserved_evu_overhang=0,
9797
get_currents=[4.5, 4.4, 5.8], get_power=3381, state=ChargepointState.CHARGING_ALLOWED,
9898
expected_phases_to_use=3, expected_current=6,
99-
expected_message="Umschaltung von 3 auf 1 Phasen in 9 Min. 0 Sek..",
99+
expected_message="Umschaltung von 3 auf 1 Phasen in 9 Min..",
100100
expected_timestamp_auto_phase_switch=1652683252.0,
101101
expected_state=ChargepointState.PHASE_SWITCH_DELAY),
102102
Params("3to1, not enough power, timer not expired", max_current_single_phase=16,
103103
timestamp_auto_phase_switch=1652682952.0,
104104
phases_to_use=3, required_current=6, evu_surplus=0, reserved_evu_overhang=-460,
105105
get_currents=[4.5, 4.4, 5.8], get_power=3381, state=ChargepointState.PHASE_SWITCH_DELAY,
106106
expected_phases_to_use=3, expected_current=6,
107-
expected_message="Umschaltung von 3 auf 1 Phasen in 4 Min. 0 Sek..",
107+
expected_message="Umschaltung von 3 auf 1 Phasen in 4 Min..",
108108
expected_timestamp_auto_phase_switch=1652683252.0,
109109
expected_state=ChargepointState.PHASE_SWITCH_DELAY),
110110
Params("3to1, enough power, timer not expired", max_current_single_phase=16,

packages/helpermodules/timecheck.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import copy
44
import logging
55
import datetime
6-
import math
76
from dateutil.relativedelta import relativedelta
87
from typing import Dict, List, Optional, Tuple, TypeVar, Union
98

@@ -344,6 +343,12 @@ def convert_timedelta_to_time_string(timedelta_obj: datetime.timedelta) -> str:
344343

345344

346345
def convert_timestamp_delta_to_time_string(timestamp: int, delta: int) -> str:
347-
diff = delta - (create_timestamp() - timestamp)
348-
minute_diff = int(diff/60)
349-
return f"{f'{minute_diff} Min. ' if minute_diff > 0 else ''}{math.ceil(diff%60)} Sek."
346+
diff = int(delta - (create_timestamp() - timestamp))
347+
seconds_diff = diff % 60
348+
minute_diff = int((diff - seconds_diff) / 60)
349+
if minute_diff > 0 and seconds_diff > 0:
350+
return f"{minute_diff} Min. {seconds_diff} Sek."
351+
elif minute_diff > 0:
352+
return f"{minute_diff} Min."
353+
elif seconds_diff > 0:
354+
return f"{seconds_diff} Sek."

packages/helpermodules/timecheck_test.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,21 @@ def test_check_timeframe(plan: Union[AutolockPlan, TimeChargingPlan], now: str,
151151
assert state == expected_state
152152

153153

154-
def test_convert_timestamp_delta_to_time_string():
154+
@pytest.mark.parametrize("timestamp, expected",
155+
[
156+
pytest.param(1652683202, "40 Sek."),
157+
pytest.param(1652683222, "1 Min."),
158+
pytest.param(1652683221.8, "59 Sek."),
159+
pytest.param(1652683222.2, "1 Min."),
160+
pytest.param(1652683232, "1 Min. 10 Sek.")
161+
]
162+
)
163+
def test_convert_timestamp_delta_to_time_string(timestamp, expected):
155164
# setup
156165
delta = 90
157166

158167
# execution
159-
time_string = timecheck.convert_timestamp_delta_to_time_string(1652683202, delta)
168+
time_string = timecheck.convert_timestamp_delta_to_time_string(timestamp, delta)
160169

161170
# evaluation
162-
assert time_string == "40 Sek."
171+
assert time_string == expected

0 commit comments

Comments
 (0)