-
Notifications
You must be signed in to change notification settings - Fork 115
Repeating the EVSE readout process in case of a timeout/error to prevent unnecessary log entries #3175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeating the EVSE readout process in case of a timeout/error to prevent unnecessary log entries #3175
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pymodbus | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any, Optional, Protocol, Tuple, Union | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -80,12 +81,22 @@ def handle_exception(self: ClientHandlerProtocol, exception: Exception): | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def request_and_check_hardware(self: ClientHandlerProtocol, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fault_state: FaultState) -> Tuple[EvseState, CounterState]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with self.client: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evse_state = self.evse_client.get_evse_state() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evse_check_passed = True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evse_check_passed = self.handle_exception(e) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evse_check_passed = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evse_state: EvseState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # 2x Retry bei EVSE-Auslesen vor dem Absetzen einer Fehlermeldung | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for attempt in (1, 2, 3): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with self.client: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evse_state = self.evse_client.get_evse_state() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evse_check_passed = True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evse_check_passed = self.handle_exception(e) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Wenn nicht "handled" -> maximal zwei Wiederholungen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if attempt < 3 and evse_check_passed is False: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| time.sleep(0.3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+98
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+87
to
+99
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for attempt in (1, 2, 3): | |
| try: | |
| with self.client: | |
| evse_state = self.evse_client.get_evse_state() | |
| evse_check_passed = True | |
| break | |
| except Exception as e: | |
| evse_check_passed = self.handle_exception(e) | |
| # Wenn nicht "handled" -> maximal zwei Wiederholungen | |
| if attempt < 3 and evse_check_passed is False: | |
| time.sleep(0.3) | |
| continue | |
| break | |
| with self.client: | |
| for attempt in (1, 2, 3): | |
| try: | |
| evse_state = self.evse_client.get_evse_state() | |
| evse_check_passed = True | |
| break | |
| except Exception as e: | |
| evse_check_passed = self.handle_exception(e) | |
| # Wenn nicht "handled" -> maximal zwei Wiederholungen | |
| if attempt < 3 and evse_check_passed is False: | |
| time.sleep(0.3) | |
| continue | |
| break |
Copilot
AI
Mar 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes request_and_check_hardware() call get_evse_state() up to 3 times. Existing unit tests/mocks that provide a single-item side_effect list for get_evse_state will now be exhausted (raising StopIteration) and may fail for the wrong reason. Update/add tests to cover: (1) success after 1–2 failures and (2) failure after 3 attempts, ideally also asserting the number of calls and that the delay is applied (with time.sleep mocked).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The retry loop catches and retries on any Exception. This will also retry non-transient errors (e.g., ValueError from
Evse.get_plug_charge_state()when the EVSE reports an unknown state), delaying a real fault and potentially masking programming/configuration issues. Consider restricting retries to known transient Modbus/IO failures (e.g.,pymodbusconnection/io exceptions, or exceptions whose__cause__is one of those), and fail fast for semantic errors like ValueError.