Skip to content

fix trigger phase switch after charge start#3227

Open
LKuemmel wants to merge 1 commit intoopenWB:masterfrom
LKuemmel:fix_phase_switch
Open

fix trigger phase switch after charge start#3227
LKuemmel wants to merge 1 commit intoopenWB:masterfrom
LKuemmel:fix_phase_switch

Conversation

@LKuemmel
Copy link
Contributor

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_switches increments from _is_phase_switch_required().
  • Introduces a local helper in initiate_phase_switch() intended to increment failed_phase_switches when 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() increments failed_phase_switches as 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). Since initiate_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 of PERFORMING_PHASE_SWITCH after the thread ends and phases_in_use still 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.

Comment on lines 394 to 400
# 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.
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants