Repository navigation
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/modules/update_soc.py" line_range="108" />
<code_context>
cp = cp_state_update.chargepoint
if cp.data.config.ev == ev_num:
plug_state = cp.data.get.plug_state
+ plug_time = cp.data.set.plug_time
charge_state = cp.data.get.charge_state
imported = cp.data.get.imported
</code_context>
<issue_to_address>
**SOC updates fail on fallback**
When a matched charge point is plugged with `plug_time` unset and an API request fails or returns stale data, `_get_vehicle_update_data` passes `None` into `VehicleUpdateData`, and `ConfigurableVehicle._get_carstate_by_source` compares the last SOC timestamp with it; the comparison raises `TypeError`, and the exception fallback repeats it, so the SOC update fails instead of using a fallback value.
Guard the timestamp comparison when `plug_time` is `None`, or ensure a valid plug time is set before building `VehicleUpdateData`.
</issue_to_address>|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/modules/common/configurable_vehicle.py" line_range="167" />
<code_context>
vehicle_update_data.plug_state and\
vehicle_update_data.last_soc and\
- vehicle_update_data.last_soc_timestamp >= vehicle_update_data.plug_time and\
+ soc_since_plugged and\
vehicle_update_data.imported -\
(self.calculated_soc_state.last_imported or vehicle_update_data.imported) > 0:
</code_context>
<issue_to_address>
**Calculated SoC fallback is skipped**
When an API response is stale or the request fails while the vehicle is plugged in and a stored SoC or plug-in timestamp is missing, `UpdateSoc._get_vehicle_update_data` can capture `plug_state=True` with `plug_time=None`, making `soc_since_plugged` false; the guard then skips calculated fallback. `_get_carstate_by_source` returns a stale SoC that `update` stores, or a failed request leaves the SoC unchanged until a later update.
Handle missing timestamps in the fallback guard so incomplete timestamp data does not prevent calculated fallback.
Also at `packages/modules/update_soc.py:108`.
</issue_to_address>| vehicle_update_data.plug_state and\ | ||
| vehicle_update_data.last_soc and\ | ||
| vehicle_update_data.last_soc_timestamp >= vehicle_update_data.plug_time and\ | ||
| soc_since_plugged and\ |
There was a problem hiding this comment.
🟡 Medium · Calculated SoC fallback is skipped
When an API response is stale or the request fails while the vehicle is plugged in and a stored SoC or plug-in timestamp is missing, UpdateSoc._get_vehicle_update_data can capture plug_state=True with plug_time=None, making soc_since_plugged false; the guard then skips calculated fallback. _get_carstate_by_source returns a stale SoC that update stores, or a failed request leaves the SoC unchanged until a later update.
Handle missing timestamps in the fallback guard so incomplete timestamp data does not prevent calculated fallback.
Also at packages/modules/update_soc.py:108.
Prompt for AI agents
In `packages/modules/common/configurable_vehicle.py` at line 167:
**Calculated SoC fallback is skipped**
When an API response is stale or the request fails while the vehicle is plugged in and a stored SoC or plug-in timestamp is missing, `UpdateSoc._get_vehicle_update_data` can capture `plug_state=True` with `plug_time=None`, making `soc_since_plugged` false; the guard then skips calculated fallback. `_get_carstate_by_source` returns a stale SoC that `update` stores, or a failed request leaves the SoC unchanged until a later update.
Handle missing timestamps in the fallback guard so incomplete timestamp data does not prevent calculated fallback.
Also at `packages/modules/update_soc.py:108`.
Summary by Sourcery
Handle missing plug-in and SoC timestamps safely when selecting API-based SoC fallbacks.
Bug Fixes:
Enhancements:
Tests: