Skip to content

Feature/bmw cardata - #3322

Merged
LKuemmel merged 48 commits into
openWB:masterfrom
GERDerDennis:feature/bmw-cardata
Apr 29, 2026
Merged

LKuemmel merged 48 commits into
openWB:masterfrom
GERDerDennis:feature/bmw-cardata

Conversation

@GERDerDennis

Copy link
Copy Markdown
Contributor

BMW CarData – Bugfixes und Erweiterungen

Folgende fixes nach dem initialen Merge:

Token-Synchronisation bei mehreren Fahrzeugen

Bei zwei BMW Fahrzeugen auf demselben Account (gleiche Client ID) wurde beim Token-Refresh der alte Token invalidiert. Nach einem erfolgreichen Token-Refresh werden die neuen Tokens jetzt automatisch an alle anderen BMW CarData Fahrzeuge mit derselben Client ID weitergegeben.

Reichweite für ältere BMW Modelle (i3)

Der BMW i3 liefert kombiRemainingElectricRange statt remainingElectricRange. Dieses Feld wird jetzt als Fallback unterstützt.

Hinweis für Nutzer mit zwei Fahrzeugen

Nur Fahrzeug 1 muss gekoppelt werden. Fahrzeug 2 erhält die Tokens automatisch beim nächsten Token-Refresh von Fahrzeug 1.

Dennis and others added 30 commits March 28, 2026 15:42
Add BMW CarData SoC module - auth wrapper scripts

Add auth_start.py and auth_status.py as wrapper scripts
for the BMW CarData authentication flow.
Fix auth UI: show user_code regardless of connection state, simplify auth button
Add odometer support via vehicle.vehicle.travelledDistance
Remove status file, return all auth data to UI for broker storage
Remove status file, return all auth data to UI for broker storage

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.

Pull request overview

This PR addresses BMW CarData edge cases after the initial merge, mainly improving multi-vehicle token handling and adding compatibility for older BMW models’ range reporting.

Changes:

  • Synchronizes refreshed BMW OAuth tokens to other BMW CarData vehicles sharing the same client_id by publishing updated configs via MQTT.
  • Adds a fallback for vehicle range using kombiRemainingElectricRange when remainingElectricRange is missing.
  • Threads the vehicle id through create_vehicle() → fetch_soc() → get_valid_token() (though it’s currently unused in get_valid_token).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 246 to +248
range_raw = _extract_value(td, FIELD_RANGE)
if range_raw is None:
range_raw = _extract_value(td, FIELD_RANGE_ALT)

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

FIELD_RANGE_ALT is used as a fallback when parsing telematics data, but the container is created with CONTAINER_DESCRIPTORS that currently does not include vehicle.drivetrain.electricEngine.kombiRemainingElectricRange. For vehicles that only expose the kombi field, the API may never return it, leaving range_raw as None. Add the alt descriptor to CONTAINER_DESCRIPTORS (and consider forcing a container re-create when range is missing and the container was created without this descriptor).

Copilot uses AI. Check for mistakes.

@LKuemmel LKuemmel 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.

Bitte noch die Copilot-Kommentare durchschauen, die Unit-Tests würde ich als optional ansehen.

Move control import to module level, add kombiRemainingElectricRange to container descriptors, auto-recreate container when range is missing
Add test for kombiRemainingElectricRange range fallback
@LKuemmel
LKuemmel merged commit b49049a into openWB:master Apr 29, 2026
1 check passed
ndrsnhs pushed a commit to ndrsnhs/core that referenced this pull request Aug 24, 2026
* Add initial BMW CarData vehicle module with UI

* Add files via upload

Add BMW CarData SoC module - auth wrapper scripts

Add auth_start.py and auth_status.py as wrapper scripts
for the BMW CarData authentication flow.

* Add files via upload

* Add files via upload

* Create bmw_cardata

* Delete web/bmw_cardata

* Create bmw_cardata_auth_start.php

* Add files via upload

* Add files via upload

* Delete packages/modules/vehicles/bmw_cardata/auth.py

* Delete packages/modules/vehicles/bmw_cardata/auth_start.py

* Delete packages/modules/vehicles/bmw_cardata/auth_status.py

* Add files via upload

Fix auth UI: show user_code regardless of connection state, simplify auth button

* Add files via upload

Add odometer support via vehicle.vehicle.travelledDistance

* Add files via upload

* Add unit tests for BMW CarData SoC module

* Remove test mode, add auth status fields for broker integration

* Replace urllib with req.get_http_session(), remove test mode

* Remove test mode UI, simplify settings, update API limit hints

* Store auth data in broker via updateConfiguration, send to PHP on poll

* Update

Remove status file, return all auth data to UI for broker storage
Remove status file, return all auth data to UI for broker storage

* Fix unit tests: use requests mock, add container_id to test config

* Improve auth status error handling, add explicit error cases

* Refactor soc.py: extract helper functions, improve error handling

* Update soc_test.py

* Update soc_test.py

* Remove legacy CLI path, improve container recovery with HTTPError.response.status_code

* Add tests for token refresh, container auto-create and retry flow

* Add CURLOPT_SSL_VERIFYHOST=2 for TLS hostname validation

* Add CURLOPT_SSL_VERIFYHOST=2 for TLS hostname validation

* Return HTTP 400 on missing client_id

* Remove vehicle.vue - moved to openwb-ui-settings repo

* Move PHP auth files to public/modules/vehicles/bmw_cardata/

* Move PHP auth files to public/modules/vehicles/bmw_cardata/

* Fix W292: add newline at end of file

* Fix W292: add newline at end of file

* Fix W292: add newline at end of file

* Fix W292: add newline at end of file

* Add files via upload

* Update soc_test.py

* Remove unused imports HTTPError and store

* ix W292/W391 whitespace issues

* Add default request intervals to prevent API rate limit

* Add kombiRemainingElectricRange as fallback for range field (BMW i3 compatibility)

* Update soc.py

Remove ineffective general_config defaults, add kombiRemainingElectricRange fallback, sync token to all BMW CarData vehicles on refresh

* Update soc.py

Move control import to module level, add kombiRemainingElectricRange to container descriptors, auto-recreate container when range is missing

* Update soc_test.py

Add test for kombiRemainingElectricRange range fallback

---------

Co-authored-by: Dennis <[email protected]>
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.

3 participants