Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,17 @@ def store_state(chargepoint_state: ChargepointState) -> None:

def perform_phase_switch(self, phases_to_use: int) -> None:
gpio_cp, gpio_relay = self._client.get_pins_phase_switch(phases_to_use)
with SingleComponentUpdateContext(self.fault_state, update_always=False):
self._client.evse_client.set_current(0)
time.sleep(5)
evse = self._client.evse_client
with SingleComponentUpdateContext(self.fault_state, update_always=False, reraise=True):
evse.set_current(0)
for _ in range(20): # poll up to 10s (20 × 0.5s) for EVSE to confirm 0 A
_, _, evse_current = evse.get_plug_charge_state()
if evse_current == 0:
break
time.sleep(0.5)
Comment on lines +149 to +153
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The "poll up to 10s" timeout isn’t actually bounded to ~10s: each loop iteration also includes EVSE.get_plug_charge_state() (0.1s sleep) and evse.set_current() (0.1s sleep) in addition to the 0.5s sleep, so the worst-case runtime is noticeably >10s (plus Modbus latency). Consider implementing the timeout using a monotonic deadline (e.g., loop until time.monotonic() >= start+10) or adjusting the sleep/iteration count so the maximum wall time matches the intended 10s.

Suggested change
for _ in range(20): # poll up to 10s (20 × 0.5s) for EVSE to confirm 0 A
_, _, evse_current = evse.get_plug_charge_state()
if evse_current == 0:
break
time.sleep(0.5)
deadline = time.monotonic() + 10
while time.monotonic() < deadline: # poll up to 10s for EVSE to confirm 0 A
_, _, evse_current = evse.get_plug_charge_state()
if evse_current == 0:
break
remaining = deadline - time.monotonic()
if remaining <= 0:
break
time.sleep(min(0.5, remaining))

Copilot uses AI. Check for mistakes.
evse.set_current(0)
else:
raise Exception("Ladung konnte nicht gestoppt werden - Phasenumschaltung abgebrochen.")
GPIO.output(gpio_cp, GPIO.HIGH) # CP off
GPIO.output(gpio_relay, GPIO.HIGH) # 3 on/off
time.sleep(5)
Expand Down
Loading