Repository navigation
MySkoda: Add SoC timestamp and option to calculate SoC - #4328
Open
seaspotter wants to merge 3 commits into
Open
seaspotter wants to merge 3 commits into
seaspotter wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/modules/vehicles/myskoda/soc.py" line_range="33" />
<code_context>
+ soc_timestamp = api.extract_captured_timestamp(data)
- return CarState(soc=soc, range=range_km, odometer=odometer_km, warning=warning)
+ return CarState(soc=soc, range=range_km, soc_timestamp=soc_timestamp, odometer=odometer_km, warning=warning)
</code_context>
<issue_to_address>
**Stale SoC appears fresh**
When the API returns cached charging data without a valid `carCapturedTimestamp`, `extract_captured_timestamp` returns `None`, and `CarState` replaces it with the request time; `ConfigurableVehicle` then treats the stale SoC as fresh and accepts it instead of detecting its age.
Preserve a missing or invalid capture time as unknown or stale so `CarState` cannot substitute the request time and make cached SoC appear fresh.
Also at `packages/modules/vehicles/myskoda/soc.py:31`, `packages/modules/vehicles/myskoda/api.py:105`, `packages/modules/vehicles/myskoda/api.py:112-117`.
</issue_to_address>
### Comment 2
<location path="packages/modules/vehicles/myskoda/api.py" line_range="114" />
<code_context>
+ if not timestamp:
+ return None
+ try:
+ return datetime.fromisoformat(timestamp.replace("Z", "+00:00")).timestamp()
+ except ValueError:
+ log.debug(f"Konnte carCapturedTimestamp nicht parsen: {timestamp}")
</code_context>
<issue_to_address>
**Invalid timestamp aborts fetch**
When the API returns a truthy, non-string `carCapturedTimestamp`, `timestamp.replace(...)` raises `AttributeError`, which the `ValueError` handler does not catch; `fetch` fails instead of returning the vehicle’s otherwise valid SoC.
Check that `timestamp` is a string before calling `replace`, and handle invalid values without aborting the fetch.
</issue_to_address>
### Comment 3
<location path="packages/modules/vehicles/myskoda/config.py" line_range="8" />
<code_context>
class MyskodaConfiguration:
api_key: str = ""
vin: str = ""
+ calculate_soc: bool = False
# wird vom Backend nach jedem erfolgreichen Abruf aus dem API-Response-Header
# zurückgeschrieben (ISO-8601), nicht vom Nutzer editierbar - siehe soc.py
</code_context>
<issue_to_address>
**User setting is overwritten**
When a UI change to `calculate_soc` races with a fetch that publishes a changed API-key expiry, `fetch` publishes its stale full `vehicle_config`, restoring the old `calculate_soc` value and causing the next vehicle instance to use the wrong charging-calculation setting.
Publish the updated API-key expiry without overwriting newer UI changes to `calculate_soc`.
</issue_to_address>
### Comment 4
<location path="packages/modules/vehicles/myskoda/api.py" line_range="116" />
<code_context>
+ try:
+ return datetime.fromisoformat(timestamp.replace("Z", "+00:00")).timestamp()
+ except ValueError:
+ log.debug(f"Konnte carCapturedTimestamp nicht parsen: {timestamp}")
+ return None
+
</code_context>
<issue_to_address>
**Forged entries appear in logs**
When an attacker able to influence the MySkoda API response supplies an invalid `carCapturedTimestamp` containing line breaks, the debug message writes the value verbatim, so embedded CR/LF characters create attacker-controlled entries in the application logs.
Escape or remove control characters from the timestamp before logging it.
</issue_to_address>
### Comment 5
<location path="packages/modules/vehicles/myskoda/soc.py" line_range="31" />
<code_context>
range_km = api.extract_range(data)
odometer_km = api.extract_odometer(data)
warning = api.extract_warning(data)
+ soc_timestamp = api.extract_captured_timestamp(data)
- return CarState(soc=soc, range=range_km, odometer=odometer_km, warning=warning)
</code_context>
<issue_to_address>
**Timestamp contract is misleading**
When a caller relies on the shared `CarState` timestamp contract for MySkoda data, `CarState` documents `soc_timestamp` as the time of the last request, but MySkoda now supplies the vehicle’s capture time. Callers following the documented contract interpret stale vehicle data as request-fresh and misunderstand the freshness checks.
Update the shared `CarState` documentation to define `soc_timestamp` as the timestamp of the SoC data, which may differ from the request time.
</issue_to_address>
Collaborator
Author
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/modules/vehicles/myskoda/soc.py" line_range="31" />
<code_context>
range_km = api.extract_range(data)
odometer_km = api.extract_odometer(data)
warning = api.extract_warning(data)
+ soc_timestamp = api.extract_captured_timestamp(data)
- return CarState(soc=soc, range=range_km, odometer=odometer_km, warning=warning)
</code_context>
<issue_to_address>
**Stale SoC is treated as current**
When the API returns a stale cached SoC with a missing or invalid `carCapturedTimestamp`, `CarState` replaces the missing timestamp with the request time, so `ConfigurableVehicle` treats the SoC as fresh and skips its stale-data fallback; callers see an old SoC as current.
Preserve a missing capture time through `CarState` so `ConfigurableVehicle` can run its stale-data fallback.
Also at `packages/modules/vehicles/myskoda/soc.py:33`, `packages/modules/vehicles/myskoda/api.py:112`.
</issue_to_address>
### Comment 2
<location path="packages/modules/vehicles/myskoda/config.py" line_range="8" />
<code_context>
class MyskodaConfiguration:
api_key: str = ""
vin: str = ""
+ calculate_soc: bool = False
# wird vom Backend nach jedem erfolgreichen Abruf aus dem API-Response-Header
# zurückgeschrieben (ISO-8601), nicht vom Nutzer editierbar - siehe soc.py
</code_context>
<issue_to_address>
**Saved calculation option gets reverted**
When a user changes `calculate_soc` while a fetch is in flight and the fetch publishes a key-expiry update, `fetch` publishes its older full configuration and overwrites the newer `calculate_soc` value, so the retained config restores the old setting and charging continues with it.
Apply the key-expiry update to the latest configuration instead of publishing the in-flight fetch’s stale configuration.
</issue_to_address>
LKuemmel
approved these changes
Nov 16, 2026
seaspotter
force-pushed
the
vehicle-myskoda-calc-soc
branch
from
November 16, 2026 14:22
a17c254 to
ddcc87b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UI: openWB/openwb-ui-settings#1172
#3413 (comment)
Summary by Sourcery
Support reliable MySkoda state-of-charge freshness tracking and optionally calculate state of charge while charging.
New Features:
Bug Fixes:
Tests:
Chores: