fix trigger phase switch after charge start#3227
fix trigger phase switch after charge start#3227LKuemmel wants to merge 1 commit intoopenWB:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts phase-switch retry/failure handling in the chargepoint control logic to address phase-switch triggering behavior after charging starts (per linked forum report).
Changes:
- Removes
failed_phase_switchesincrements from_is_phase_switch_required(). - Introduces a local helper in
initiate_phase_switch()intended to incrementfailed_phase_switcheswhen a phase switch is considered failed. - Calls the new failure-counter logic when a phase switch is deemed required.
Comments suppressed due to low confidence (1)
packages/control/chargepoint/chargepoint.py:404
_set_failed_phase_switches()incrementsfailed_phase_switchesas soon as_is_phase_switch_required()returns true (i.e., before any phase-switch attempt has been performed and even before confirming a switch thread can be started). Sinceinitiate_phase_switch()runs every process cycle, this will count “failures” repeatedly while phases differ and can quickly hit the retry limit, preventing legitimate phase switching later (and mislabeling successful switches as failures). Consider removing this pre-increment and instead incrementing exactly once per unsuccessful completed phase-switch attempt (e.g., when transitioning out ofPERFORMING_PHASE_SWITCHafter the thread ends andphases_in_usestill doesn’t match the requested phases), and optionally resetting the counter on success.
def _set_failed_phase_switches() -> None:
# Umschaltung fehlgeschlagen
if self.data.set.phases_to_use != self.data.get.phases_in_use:
self.data.control_parameter.failed_phase_switches += 1
try:
if self.data.get.evse_signaling == EvseSignaling.HLC:
return
evu_counter = data.data.counter_all_data.get_evu_counter()
charging_ev = self.data.set.charging_ev_data
# Wenn noch kein Eintrag im Protokoll erstellt wurde, wurde noch nicht geladen und die Phase kann noch
# umgeschaltet werden.
if (not charging_ev.ev_template.data.prevent_phase_switch or
self.data.set.log.imported_since_plugged == 0):
# Einmal muss die Anzahl der Phasen gesetzt werden.
if self.data.set.phases_to_use == 0:
self.data.set.phases_to_use = self.data.control_parameter.phases
if self.hw_supports_phase_switch():
if self._is_phase_switch_required():
_set_failed_phase_switches()
# Wenn die Umschaltverzögerung aktiv ist, darf nicht umgeschaltet werden.
if (self.data.control_parameter.state != ChargepointState.PERFORMING_PHASE_SWITCH and
(self.data.control_parameter.state != ChargepointState.WAIT_FOR_USING_PHASES or
(self.data.control_parameter.state == ChargepointState.WAIT_FOR_USING_PHASES and
self.data.get.charge_state is False))):
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Einmal muss die Anzahl der Phasen gesetzt werden. | ||
| if self.data.set.phases_to_use == 0: | ||
| self.data.set.phases_to_use = self.data.control_parameter.phases | ||
| if self.hw_supports_phase_switch(): | ||
| if self._is_phase_switch_required(): | ||
| _set_failed_phase_switches() | ||
| # Wenn die Umschaltverzögerung aktiv ist, darf nicht umgeschaltet werden. |
There was a problem hiding this comment.
The logic around failed_phase_switches has been changed significantly (increment moved out of _is_phase_switch_required into initiate_phase_switch), but there is no automated test covering when/how the counter is incremented and how it affects failed_phase_switches_reached() behavior. Adding/adjusting unit tests to assert the counter only changes after a genuinely failed phase-switch attempt would help prevent regressions in the retry/disable logic.
https://forum.openwb.de/viewtopic.php?p=141064#p141064