Skip to content

Feature vw euda refactoring - #4148

Merged
LKuemmel merged 6 commits into
masterfrom
feature_vw_eua_refactoring
Nov 12, 2026
Merged

LKuemmel merged 6 commits into
masterfrom
feature_vw_eua_refactoring

Conversation

@LKuemmel

@LKuemmel LKuemmel commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

@rleidner Es stand ja noch ein Refactoring Deiner VW Implementierung aus.
Ich habe mich da mit der KI mal dran gewagt. Das Problem mit dem Hintergrund-Thread habe ich durch ein verkürztes Abfrage-Intervall, dass das Modul vorgeben kann, gelöst: #4147
Die Paket-Daten werden in Variablen abgelegt, nicht in Dateien. Die Anforderungen aufgrund der spezifischen Portal-Eigenheiten habe ich der KI mitgegeben. Bitte schau mal rein und teste, ob Du mit diesem Stand weiter arbeiten kannst.

Vor Nutzung muss die kontinuierliche Abfrage im Portal angestoßen werden:
https://eu-data-act.drivesomethinggreater.com/de/de/eu-data-act.html
Benutzerdefinierte Daten abrufen - All Data - 15 min.
Es kann mehrere Stunden dauern, bis erste nicht-leere Datenpakete ankommen.
Die Fahrzeugdaten können auch danach deutlich verzögert eintreffen.

Das Modul fragt das Portal synchron über den normalen openWB-SoC-Scheduler ab.
Empfehlung: die Abfrageintervalle während und außerhalb des Ladens auf 600 Sekunden
setzen. Bei Abruffehlern fordert das Modul über den Intervall-Callback höchstens
60 Sekunden bis zum nächsten Versuch an, unabhängig vom Drei-Fehler-Zähler.
Nach erfolgreichem Abruf gelten wieder die konfigurierten Intervalle.
Manuelle und reguläre frühere Abfragen bleiben möglich; die Einstellung für
Abfragen nur bei eingestecktem Fahrzeug gilt auch für Wiederholungen.

Alle noch nicht verarbeiteten Datenpakete werden von alt nach neu ausgewertet.
Fehlende, ungültige oder ältere SoC-Werte überschreiben keinen gültigen Stand.
Fehlende Reichweite und Kilometerstand bleiben aus dem letzten gültigen Stand
erhalten; der Kilometerstand wird nicht zurückgesetzt. Numerische Nullwerte gelten.
Der Zeitstempel stammt vorrangig aus dem Caddy-SoC-Feld timestampUtc, sonst aus
dem Maximum aller car_captured_time-Werte, ersatzweise aus timestamp (PR #4127).
Wenn keine Reichweite bekannt ist, wird sie aus SoC, Kapazität und Verbrauch berechnet.

Cache, verarbeitete Datensätze und Retry-Flag bleiben ausschließlich im Arbeitsspeicher
des Fahrzeugmoduls. Es werden weder persistente Zustandsdateien noch Rohdaten in der
Ramdisk gespeichert oder eingelesen. Nach einem Prozessneustart oder einer Neuerstellung
des Moduls muss der Cache durch einen erfolgreichen Portalabruf neu gefüllt werden.
Bei Portalausfall wird der Cache mit ursprünglichem Zeitstempel und Warnung
zurückgegeben. Ohne gültigen Cache wird ein Fehler gemeldet, kein künstlicher 0%-Wert.
In beiden Fällen wird nach höchstens einer Minute erneut versucht.

Code-Aufbau:
api.py Login, Wiederanmeldung und HTTP-/ZIP-Abrufe
vehicle_data.py Feldzuordnung, Zeitstempel und Datenauswertung
libeuda.py Synchroner Abruf und In-Memory-Cache
soc.py Einbindung und gemeinsamer Zustand der Scheduler-Callbacks

Summary by Sourcery

Refactor the VW EU Data Act vehicle module to use synchronous scheduler-based portal access with robust in-memory caching and measurement validation.

New Features:

  • Add synchronous Volkswagen Group EU Data Act portal access with brand-aware authentication, dataset retrieval, and vehicle data extraction.

Bug Fixes:

  • Prevent invalid, stale, missing, or regressive measurements from replacing valid cached vehicle state.

Enhancements:

  • Replace the background polling thread and filesystem-based state with scheduler-driven requests and an in-memory vehicle cache.
  • Preserve valid cached data during portal failures, retry failed requests within 60 seconds, and report errors without fabricating zero measurements.
  • Improve handling of portal datasets, timestamps, optional vehicle values, range calculation, session renewal, and malformed archives.

Tests:

  • Add coverage for portal authentication flows, session expiry, archive handling, timestamp selection, data validation, cache behavior, and scheduler retries.

Chores:

  • Split the EU Data Act integration into dedicated API, data parsing, cache, and scheduler integration modules.

@LKuemmel
LKuemmel added this pull request to stack #4149 October 20, 2026 12:48
@LKuemmel
LKuemmel marked this pull request as draft October 20, 2026 12:48
@LKuemmel
LKuemmel requested a review from rleidner October 20, 2026 12:49
@LKuemmel
LKuemmel marked this pull request as ready for review October 21, 2026 06:33
@LKuemmel LKuemmel changed the title Feature vw eua refactoring Feature vw euda refactoring Oct 21, 2026
@LKuemmel

Copy link
Copy Markdown
Contributor Author

Ich habe das VW-EUDA-Modul vorerst aus der Beta genommen. Sobald wir mit diesem PR eine konistente Lösung haben, nehmen wir es gerne ins 2.4.0 Release auf.

@rleidner rleidner left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@LKuemmel ,
tested and it basically works.
2 observations:

  1. directly after restarting openWB I see 2 errors http 429, disappears after a few minutes
    EDIT: looks like error 429 is returned by the portal when all 30 datasets are downloaded in a very short time.
    I added for a test a time.sleep(.5) after each file and the 429 disappeared. #4161

  2. in logging level DEBUG I get large binary data written to soc.log, example:
    2026-10-20 22:08:29,668 - {modules.common.req:53} - {DEBUG:fetch soc_ev2} - Get-Response: PC T]y J {G%WVWZZZE1Zxxxxxxxx_20261020200139.json [o 7 } _a u B N M GX[2d9 x @i j ....

Apart it works pretty well and refactored code is definitely a considerable improvement.

@LKuemmel
LKuemmel force-pushed the feature_vw_eua_refactoring branch from 7be4ab8 to 5833099 Compare October 22, 2026 07:34
@LKuemmel
LKuemmel removed this pull request from stack #4149 October 22, 2026 07:36
@LKuemmel
LKuemmel changed the base branch from feature-soc-request-retry to feature_filter_log_file_types October 22, 2026 07:36
@LKuemmel
LKuemmel added this pull request to stack #4165 October 22, 2026 07:37
@LKuemmel
LKuemmel force-pushed the feature_vw_eua_refactoring branch from 5833099 to 763838b Compare October 22, 2026 07:41
@LKuemmel

LKuemmel commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Danke für Dein Feedback!

Punkt 2 habe ich hier gelöst: #4164

@LKuemmel LKuemmel added this to the 2.4.0 milestone Oct 22, 2026
@LKuemmel LKuemmel moved this to In progress in openWB Roadmap Oct 29, 2026
Base automatically changed from feature_filter_log_file_types to master November 11, 2026 13:06
@LKuemmel
LKuemmel force-pushed the feature_vw_eua_refactoring branch from 051576f to a7cfcf5 Compare November 11, 2026 13:16
@sourcery-ai

sourcery-ai Bot commented Nov 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define normalized vehicle measurements, field precedence, and dataset timestamp selection that the cache and scheduler rely on.

  • packages/modules/vehicles/vweuda/vehicle_data.py L1-74

API

Provide the synchronous portal client interface for login, reauthentication, metadata and dataset retrieval, and ZIP decoding.

  • packages/modules/vehicles/vweuda/api.py L1-252

Uses of the API

Connect the vehicle module to the SoC scheduler and share its in-memory portal cache and retry interval across callbacks.

  • packages/modules/vehicles/vweuda/soc.py L1 (removed lines), L6-22

Implementation

Replace background polling and file-based state with synchronous dataset polling, validation, and an in-memory cache that preserves the last valid state.

  • packages/modules/vehicles/vweuda/libeuda.py L1-115

Documentation

Remove the former VW EU Data Act README.

  • packages/modules/vehicles/vweuda/README.txt (deleted)

Tests

Exercise portal login flows, transient errors, session renewal, and dataset downloads.

  • packages/modules/vehicles/vweuda/api_test.py L1-166

Verify vehicle-field parsing and timestamp selection, including fallback fields and zero values.

  • packages/modules/vehicles/vweuda/libeuda_test.py L49-114

Check dataset selection, cache validity, outage fallback, and scheduler retry behavior.

  • packages/modules/vehicles/vweuda/scheduler_test.py L1-207

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Archive processing can lose telemetry and miss newer SoC values, while unhandled corrupt ZIP errors can abort polling and block subsequent retries.

2 open issues
What changed in this PR

Refactors the Volkswagen EU Data Act integration to retrieve vehicle data through openWB’s regular SoC scheduler, replacing background polling and file persistence with a shared in-memory cache.

Changes:

  • Separates authentication, dataset parsing, cache management, and scheduler integration.
  • Adds cached fallback readings and shorter retry intervals after retrieval failures.
  • Expands tests for login flows, timestamps, measurement validation, and scheduler state.
File Description
packages/​modules/​vehicles/​vweuda/​vehicle_data.py Extracts field mapping, numeric validation, and timestamp parsing.
packages/​modules/​vehicles/​vweuda/​soc.py Connects updater and interval callbacks to shared portal state.
packages/​modules/​vehicles/​vweuda/​scheduler_test.py Tests dataset selection, cache preservation, and retry behavior.
packages/​modules/​vehicles/​vweuda/​README.txt Removes documentation for the previous implementation.
packages/​modules/​vehicles/​vweuda/​libeuda.py Replaces background workers and files with synchronous retrieval and memory caching.
packages/​modules/​vehicles/​vweuda/​libeuda_test.py Adds field-precedence and timestamp-fallback tests.
packages/​modules/​vehicles/​vweuda/​api.py Introduces synchronous authentication, session recovery, and ZIP downloads.
packages/​modules/​vehicles/​vweuda/​api_test.py Tests authentication, HTTP errors, and download session recovery.

Review effort: Balanced

Comment thread packages/modules/vehicles/vweuda/api.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

No-cache failures can publish a fabricated 0% SoC, while unbounded archive processing after restart can exceed the scheduler timeout and delay other vehicles’ updates.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Handle unsupported ZIP methods without blocking archive polling

packages/​modules/​vehicles/​vweuda/​api.py:251

An unsupported ZIP compression method makes archive.read() raise NotImplementedError, which escapes this handler and stops polling before newer valid archives are read. Because the archive is not marked processed, every retry encounters the same blocker. Convert this exception to DatasetError too so the polling loop can skip it.

Medium severity Compare valid capture timestamps as parsed datetimes

packages/​modules/​vehicles/​vweuda/​vehicle_data.py:68

Taking the maximum of raw timestamp strings can select an older instant when fractional seconds or UTC offsets differ, giving SoC the wrong timestamp. A null capture value alongside a valid value also raises TypeError, causing the archive to be permanently skipped. Filter invalid candidates and compare parsed datetimes while retaining the selected original string.

2 resolved since last review

Review effort: Balanced

Comment on lines +65 to +66
try:
_, payload = client.download_dataset(self.vin, identifier, name)
Comment on lines +95 to +96
if self._result is None:
raise ApiError(f"SOCERR-02: {error_message}") from error
@LKuemmel
LKuemmel force-pushed the feature_vw_eua_refactoring branch from 28d9ae6 to f96a1e3 Compare November 11, 2026 14:03
@LKuemmel
LKuemmel merged commit f6f2f68 into master Nov 12, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in openWB Roadmap Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants