Skip to content

soc update: set missing attribute - #4428

Open
LKuemmel wants to merge 2 commits into
openWB:masterfrom
LKuemmel:fix-soc
Open

LKuemmel wants to merge 2 commits into
openWB:masterfrom
LKuemmel:fix-soc

Conversation

@LKuemmel

@LKuemmel LKuemmel commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Handle missing plug-in and SoC timestamps safely when selecting API-based SoC fallbacks.

Bug Fixes:

  • Prevent SoC fallback calculations from comparing missing plug-in or SoC timestamps, and report which timestamp is missing.

Enhancements:

  • Allow vehicle plug-in timestamps to be unset and pass the charge point's plug-in time into vehicle update data.

Tests:

  • Add coverage for API fallback and stale SoC values when either timestamp is missing or the SoC timestamp predates plug-in.

@LKuemmel LKuemmel added this to the 2.5.0 milestone Dec 1, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 is free for open source - if you like our reviews please consider sharing them ✨

Comment thread packages/modules/update_soc.py Resolved
@LKuemmel

LKuemmel commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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\

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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`.

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.

1 participant