fix load default after unplug#3309
Conversation
There was a problem hiding this comment.
Pull request overview
This PR targets chargepoint behavior when charging stops/unplug occurs, adjusting which EV data is referenced during unplug handling and changing when the active EV (charging_ev_data) is resolved during the main Chargepoint.update() cycle.
Changes:
- Use
data.data.ev_data[f"ev{...}"]lookups (f-strings) during_process_charge_stop()for chargelog and manual-SoC reset checks. - Move
_get_charging_ev(vehicle, ev_list)inside thecharging_possiblebranch inupdate().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (data.data.ev_data[f"ev{self.data.config.ev}"].soc_module is not None and | ||
| data.data.ev_data[f"ev{self.data.config.ev}"].soc_module.vehicle_config.type == "manual" and | ||
| data.data.ev_data[f"ev{self.data.config.ev}"].soc_module.vehicle_config.configuration.reset_after_unplug): |
There was a problem hiding this comment.
data.data.ev_data[f"ev{self.data.config.ev}"] is looked up three times in the same condition. Please assign it once to a local variable (e.g., ev = ...) and reference ev.soc_module... to reduce duplication and avoid inconsistencies if self.data.config.ev changes in the future (it is mutated later in this block when load_default is set).
|
|
||
| if charging_possible: | ||
| try: | ||
| charging_ev = self._get_charging_ev(vehicle, ev_list) |
There was a problem hiding this comment.
By moving _get_charging_ev(vehicle, ev_list) inside if charging_possible, self.data.set.charging_ev_data is no longer updated on cycles where charging is blocked (e.g., manual lock/autolock while plugged). This object is still used later in update() (e.g., the SoC timestamp comparison against self.data.set.charging_ev_data.data.get.soc_timestamp), so it can become stale and reference the wrong EV. Consider calling _get_charging_ev before the charging_possible branch (as before) or otherwise ensuring charging_ev_data stays in sync with the resolved vehicle even when charging is not allowed.
| if charging_possible: | |
| try: | |
| charging_ev = self._get_charging_ev(vehicle, ev_list) | |
| charging_ev = self._get_charging_ev(vehicle, ev_list) | |
| if charging_possible: | |
| try: |
| try: | ||
| charging_ev = self._get_charging_ev(vehicle, ev_list) | ||
| state, message_ev, submode, required_current, template_phases = charging_ev.get_required_current( |
There was a problem hiding this comment.
This behavioral change in update() (deferring _get_charging_ev until charging_possible is true) doesn’t appear to be covered by existing tests (current chargepoint_test.py focuses on helpers and _process_charge_stop). Please add a regression test for the scenario the PR title mentions (load default after unplug) and/or a case where charging is not allowed while plugged, to ensure charging_ev_data and SoC update behavior remain correct.
No description provided.