Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions packages/control/algorithm/integration_test/pv_charging_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class ParamsPhaseSwitch(ParamsExpectedSetCurrent, ParamsExpectedCounterSet):
raw_power_left: float = 0
raw_currents_left_counter0: List[float] = field(default_factory=currents_list_factory)
raw_currents_left_counter6: List[float] = field(default_factory=currents_list_factory)
expected_timestamp_auto_phase_switch_cp3: Optional[str] = None
expected_timestamp_auto_phase_switch_cp4: Optional[str] = None
expected_timestamp_auto_phase_switch_cp5: Optional[str] = None
expected_timestamp_last_phase_switch_cp3: Optional[str] = None
expected_timestamp_last_phase_switch_cp4: Optional[str] = None
expected_timestamp_last_phase_switch_cp5: Optional[str] = None


def assert_counter_set(params: ParamsExpectedCounterSet):
Expand Down Expand Up @@ -243,9 +243,9 @@ def test_surplus(params: ParamsSurplus, all_cp_pv_charging_3p, all_cp_charging_3
raw_power_left=32580,
raw_currents_left_counter0=[40]*3,
raw_currents_left_counter6=[16]*3,
expected_timestamp_auto_phase_switch_cp3=1652683252.0,
expected_timestamp_auto_phase_switch_cp4=None,
expected_timestamp_auto_phase_switch_cp5=None,
expected_timestamp_last_phase_switch_cp3=1652683252.0,
expected_timestamp_last_phase_switch_cp4=None,
expected_timestamp_last_phase_switch_cp5=None,
expected_current_cp3=10,
expected_current_cp4=6,
expected_current_cp5=6,
Expand All @@ -257,9 +257,9 @@ def test_surplus(params: ParamsSurplus, all_cp_pv_charging_3p, all_cp_charging_3
raw_power_left=42580,
raw_currents_left_counter0=[40]*3,
raw_currents_left_counter6=[16]*3,
expected_timestamp_auto_phase_switch_cp3=1652683252.0,
expected_timestamp_auto_phase_switch_cp4=None,
expected_timestamp_auto_phase_switch_cp5=None,
expected_timestamp_last_phase_switch_cp3=1652683252.0,
expected_timestamp_last_phase_switch_cp4=None,
expected_timestamp_last_phase_switch_cp5=None,
expected_current_cp3=32,
expected_current_cp4=6,
expected_current_cp5=6,
Expand All @@ -281,21 +281,16 @@ def test_phase_switch(all_cp_pv_charging_3p, all_cp_charging_3p, monkeypatch):
monkeypatch.setattr(algorithm_data.data.general_data, "get_phases_chargemode", mockget_get_phases_chargemode)
data.data.cp_data[
"cp3"].data.control_parameter.state = ChargepointState.CHARGING_ALLOWED
data.data.cp_data[
"cp3"].data.control_parameter.timestamp_last_phase_switch = 1652682252

# execution
Algorithm().calc_current()

# evaluation
assert_expected_current(cases_phase_switch[0])
assert data.data.cp_data[
"cp3"].data.control_parameter.timestamp_auto_phase_switch == cases_phase_switch[
0].expected_timestamp_auto_phase_switch_cp3
assert data.data.cp_data[
"cp4"].data.control_parameter.timestamp_auto_phase_switch == cases_phase_switch[
0].expected_timestamp_auto_phase_switch_cp4
assert data.data.cp_data[
"cp5"].data.control_parameter.timestamp_auto_phase_switch == cases_phase_switch[
0].expected_timestamp_auto_phase_switch_cp5
"cp3"].data.control_parameter.state == ChargepointState.PHASE_SWITCH_DELAY
assert_counter_set(cases_phase_switch[0])


Expand All @@ -311,6 +306,7 @@ def test_phase_switch_1p_3p(all_cp_pv_charging_1p, monkeypatch):
monkeypatch.setattr(algorithm_data.data.general_data, "get_phases_chargemode", mockget_get_phases_chargemode)
data.data.cp_data["cp3"].data.get.currents = [32, 0, 0]
data.data.cp_data["cp3"].data.get.power = 7360
data.data.cp_data["cp3"].data.control_parameter.timestamp_last_phase_switch = 1652682252
data.data.cp_data["cp4"].data.get.currents = [0, 0, 0]
data.data.cp_data["cp5"].data.get.currents = [0, 0, 0]

Expand All @@ -320,11 +316,4 @@ def test_phase_switch_1p_3p(all_cp_pv_charging_1p, monkeypatch):
# evaluation
assert_counter_set(cases_phase_switch[1])
assert data.data.cp_data[
"cp3"].data.control_parameter.timestamp_auto_phase_switch == cases_phase_switch[
1].expected_timestamp_auto_phase_switch_cp3
assert data.data.cp_data[
"cp4"].data.control_parameter.timestamp_auto_phase_switch == cases_phase_switch[
1].expected_timestamp_auto_phase_switch_cp4
assert data.data.cp_data[
"cp5"].data.control_parameter.timestamp_auto_phase_switch == cases_phase_switch[
1].expected_timestamp_auto_phase_switch_cp5
"cp3"].data.control_parameter.state == ChargepointState.PHASE_SWITCH_DELAY
42 changes: 17 additions & 25 deletions packages/control/auto_phase_switch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Params:
def __init__(self,
name: str,
max_current_single_phase: int,
timestamp_auto_phase_switch: Optional[float],
timestamp_last_phase_switch: Optional[float],
phases_to_use: int,
required_current: float,
evu_surplus: int,
Expand All @@ -41,11 +41,10 @@ def __init__(self,
expected_phases_to_use: int,
expected_current: float,
expected_state: ChargepointState,
expected_message: Optional[str] = None,
expected_timestamp_auto_phase_switch: Optional[float] = None) -> None:
expected_message: Optional[str] = None) -> None:
self.name = name
self.max_current_single_phase = max_current_single_phase
self.timestamp_auto_phase_switch = timestamp_auto_phase_switch
self.timestamp_last_phase_switch = timestamp_last_phase_switch
self.phases_to_use = phases_to_use
self.required_current = required_current
self.available_power = evu_surplus
Expand All @@ -56,64 +55,57 @@ def __init__(self,
self.expected_current = expected_current
self.expected_state = expected_state
self.expected_message = expected_message
self.expected_timestamp_auto_phase_switch = expected_timestamp_auto_phase_switch


cases = [
Params("1to3, enough power, start timer", max_current_single_phase=16, timestamp_auto_phase_switch=None,
Params("1to3, enough power, start timer", max_current_single_phase=16, timestamp_last_phase_switch=1652683202,
phases_to_use=1, required_current=6, evu_surplus=800, get_currents=[15.6, 0, 0],
get_power=3450, state=ChargepointState.CHARGING_ALLOWED, expected_phases_to_use=1, expected_current=6,
expected_message=Ev.PHASE_SWITCH_DELAY_TEXT.format("Umschaltung von 1 auf 3", "7 Min."),
expected_timestamp_auto_phase_switch=1652683252.0,
expected_message=Ev.PHASE_SWITCH_DELAY_TEXT.format("Umschaltung von 1 auf 3", "4 Min. 10 Sek."),
expected_state=ChargepointState.PHASE_SWITCH_DELAY),
Params("1to3, not enough power, start timer", max_current_single_phase=16, timestamp_auto_phase_switch=None,
Params("1to3, not enough power, start timer", max_current_single_phase=16, timestamp_last_phase_switch=1652683202,
phases_to_use=1, required_current=6, evu_surplus=300, get_currents=[15.6, 0, 0],
get_power=3450, state=ChargepointState.CHARGING_ALLOWED, expected_phases_to_use=1, expected_current=6,
expected_state=ChargepointState.CHARGING_ALLOWED),
Params("1to3, enough power, timer not expired", max_current_single_phase=16,
timestamp_auto_phase_switch=1652682952.0, phases_to_use=1, required_current=6,
timestamp_last_phase_switch=1652683202.0, phases_to_use=1, required_current=6,
evu_surplus=1460, get_currents=[15.6, 0, 0], get_power=3450,
state=ChargepointState.PHASE_SWITCH_DELAY, expected_phases_to_use=1, expected_current=6,
expected_message=Ev.PHASE_SWITCH_DELAY_TEXT.format("Umschaltung von 1 auf 3", "2 Min."),
expected_timestamp_auto_phase_switch=1652683252.0,
expected_message=Ev.PHASE_SWITCH_DELAY_TEXT.format("Umschaltung von 1 auf 3", "4 Min. 10 Sek."),
expected_state=ChargepointState.PHASE_SWITCH_DELAY),
Params("1to3, not enough power, timer not expired", max_current_single_phase=16,
timestamp_auto_phase_switch=1652682952.0, phases_to_use=1, required_current=6,
timestamp_last_phase_switch=1652683202.0, phases_to_use=1, required_current=6,
evu_surplus=460, get_currents=[15.6, 0, 0], get_power=3450,
state=ChargepointState.PHASE_SWITCH_DELAY, expected_phases_to_use=1, expected_current=6,
expected_message=f"Verzögerung für die Umschaltung von 1 auf 3 Phasen abgebrochen{Ev.NOT_ENOUGH_POWER}",
expected_timestamp_auto_phase_switch=1652683252.0,
expected_state=ChargepointState.CHARGING_ALLOWED),
Params("1to3, enough power, timer expired", max_current_single_phase=16,
timestamp_auto_phase_switch=1652682772.0, phases_to_use=1, required_current=6,
timestamp_last_phase_switch=1652682802.0, phases_to_use=1, required_current=6,
evu_surplus=1640, get_currents=[15.6, 0, 0], get_power=3450,
state=ChargepointState.PHASE_SWITCH_DELAY,
expected_phases_to_use=3, expected_current=6, expected_state=ChargepointState.PHASE_SWITCH_AWAITED),

Params("3to1, not enough power, start timer", max_current_single_phase=16, timestamp_auto_phase_switch=None,
Params("3to1, not enough power, start timer", max_current_single_phase=16, timestamp_last_phase_switch=1652683202,
phases_to_use=3, required_current=6, evu_surplus=0,
get_currents=[4.5, 4.4, 5.8], get_power=3381, state=ChargepointState.CHARGING_ALLOWED,
expected_phases_to_use=3, expected_current=6,
expected_message="Umschaltung von 3 auf 1 Phasen in 9 Min..",
expected_timestamp_auto_phase_switch=1652683252.0,
expected_message="Umschaltung von 3 auf 1 Phasen in 4 Min. 10 Sek..",
expected_state=ChargepointState.PHASE_SWITCH_DELAY),
Params("3to1, not enough power, timer not expired", max_current_single_phase=16,
timestamp_auto_phase_switch=1652682952.0,
timestamp_last_phase_switch=1652683202.0,
phases_to_use=3, required_current=6, evu_surplus=-460,
get_currents=[4.5, 4.4, 5.8], get_power=3381, state=ChargepointState.PHASE_SWITCH_DELAY,
expected_phases_to_use=3, expected_current=6,
expected_message="Umschaltung von 3 auf 1 Phasen in 4 Min..",
expected_timestamp_auto_phase_switch=1652683252.0,
expected_message="Umschaltung von 3 auf 1 Phasen in 4 Min. 10 Sek..",
expected_state=ChargepointState.PHASE_SWITCH_DELAY),
Params("3to1, enough power, timer not expired", max_current_single_phase=16,
timestamp_auto_phase_switch=1652682952.0, phases_to_use=3, required_current=6,
timestamp_last_phase_switch=1652683202.0, phases_to_use=3, required_current=6,
evu_surplus=860, get_currents=[4.5, 4.4, 5.8],
get_power=3381, state=ChargepointState.PHASE_SWITCH_DELAY, expected_phases_to_use=3, expected_current=6,
expected_message=f"Verzögerung für die Umschaltung von 3 auf 1 Phasen abgebrochen{Ev.ENOUGH_POWER}",
expected_timestamp_auto_phase_switch=1652683252.0,
expected_state=ChargepointState.CHARGING_ALLOWED),
Params("3to1, not enough power, timer expired", max_current_single_phase=16,
timestamp_auto_phase_switch=1652682592.0, phases_to_use=3, required_current=6,
timestamp_last_phase_switch=1652682802.0, phases_to_use=3, required_current=6,
evu_surplus=-460, get_currents=[4.5, 4.4, 5.8],
get_power=3381, state=ChargepointState.PHASE_SWITCH_DELAY, expected_phases_to_use=1, expected_current=16,
expected_state=ChargepointState.PHASE_SWITCH_AWAITED),
Expand All @@ -133,7 +125,7 @@ def test_auto_phase_switch(monkeypatch, vehicle: Ev, params: Params):

vehicle.ev_template.data.max_current_single_phase = params.max_current_single_phase
control_parameter = ControlParameter()
control_parameter.timestamp_auto_phase_switch = params.timestamp_auto_phase_switch
control_parameter.timestamp_last_phase_switch = params.timestamp_last_phase_switch
control_parameter.phases = params.phases_to_use
control_parameter.required_current = params.required_current
control_parameter.state = params.state
Expand Down
9 changes: 4 additions & 5 deletions packages/control/chargepoint/chargepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,16 @@ def check_phase_switch_completed(self):
# Umschaltung abgeschlossen
try:
timestamp_not_expired = timecheck.check_timestamp(
self.data.control_parameter.timestamp_perform_phase_switch,
self.data.control_parameter.timestamp_last_phase_switch,
6 + phase_switch_pause - 1)
except TypeError:
# so wird in jedem Fall die erforderliche Zeit abgewartet
self.data.control_parameter.timestamp_perform_phase_switch = create_timestamp()
self.data.control_parameter.timestamp_last_phase_switch = create_timestamp()
timestamp_not_expired = timecheck.check_timestamp(
self.data.control_parameter.timestamp_perform_phase_switch,
self.data.control_parameter.timestamp_last_phase_switch,
6 + phase_switch_pause - 1)
if not timestamp_not_expired:
log.debug("phase switch running")
self.data.control_parameter.timestamp_perform_phase_switch = None
# Aktuelle Ladeleistung und Differenz wieder freigeben.
if self.data.set.phases_to_use == 1:
evu_counter.data.set.reserved_surplus -= charging_ev.ev_template. \
Expand Down Expand Up @@ -488,7 +487,7 @@ def initiate_phase_switch(self):
evu_counter.data.set.reserved_surplus += charging_ev. \
ev_template.data.max_current_single_phase * 3 * 230
# Timestamp für die Durchführungsdauer
self.data.control_parameter.timestamp_perform_phase_switch = create_timestamp()
self.data.control_parameter.timestamp_last_phase_switch = create_timestamp()
self.set_state_and_log(message)
if self.data.set.phases_to_use != self.data.control_parameter.phases:
Pub().pub("openWB/set/chargepoint/"+str(self.num)+"/set/phases_to_use",
Expand Down
6 changes: 2 additions & 4 deletions packages/control/chargepoint/control_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ class ControlParameter:
state: ChargepointState = field(default=ChargepointState.NO_CHARGING_ALLOWED,
metadata={"topic": "control_parameter/state"})
submode: Chargemode_enum = field(default=Chargemode_enum.STOP, metadata={"topic": "control_parameter/submode"})
timestamp_auto_phase_switch: Optional[float] = field(
default=None, metadata={"topic": "control_parameter/timestamp_auto_phase_switch"})
timestamp_charge_start: Optional[float] = field(
default=None, metadata={"topic": "control_parameter/timestamp_charge_start"})
timestamp_perform_phase_switch: Optional[float] = field(
default=None, metadata={"topic": "control_parameter/timestamp_perform_phase_switch"})
timestamp_last_phase_switch: float = field(
default=0, metadata={"topic": "control_parameter/timestamp_last_phase_switch"})
timestamp_switch_on_off: Optional[float] = field(
default=None, metadata={"topic": "control_parameter/timestamp_switch_on_off"})

Expand Down
8 changes: 4 additions & 4 deletions packages/control/chargepoint/get_phases_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self,
phases_in_use: int,
imported_since_plugged: float,
expected_phases: int,
timestamp_perform_phase_switch: Optional[str] = None,
timestamp_last_phase_switch: Optional[str] = None,
charge_state: bool = False) -> None:
self.name = name
self.connected_phases = connected_phases
Expand All @@ -45,7 +45,7 @@ def __init__(self,
self.phases_in_use = phases_in_use
self.imported_since_plugged = imported_since_plugged
self.expected_phases = expected_phases
self.timestamp_perform_phase_switch = timestamp_perform_phase_switch
self.timestamp_last_phase_switch = timestamp_last_phase_switch
self.charge_state = charge_state


Expand All @@ -61,7 +61,7 @@ def __init__(self,
expected_phases=1, charge_state=True),
Params("don't change during phase switch", connected_phases=3, auto_phase_switch_hw=True,
prevent_phase_switch=False, chargemode_phases=0, phases_in_use=1, imported_since_plugged=0,
expected_phases=1, timestamp_perform_phase_switch="2022/05/11, 15:00:02"),
expected_phases=1, timestamp_last_phase_switch="2022/05/11, 15:00:02"),
Params("auto phase during charge 3", connected_phases=3, auto_phase_switch_hw=True,
prevent_phase_switch=False, chargemode_phases=0, phases_in_use=1, imported_since_plugged=0,
expected_phases=1, charge_state=True),
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_get_phases_by_selected_chargemode(monkeypatch, cp: Chargepoint, params:
cp.data.set.log.imported_since_plugged = params.imported_since_plugged
charging_ev_data = cp.data.set.charging_ev_data
charging_ev_data.ev_template.data.prevent_phase_switch = params.prevent_phase_switch
cp.data.control_parameter.timestamp_perform_phase_switch = params.timestamp_perform_phase_switch
cp.data.control_parameter.timestamp_last_phase_switch = params.timestamp_last_phase_switch
cp.data.control_parameter.phases = params.phases_in_use

# execution
Expand Down
Loading