Skip to content

Cardata: status detection for "New Class" vehicles#30938

Open
mfuchs1984 wants to merge 12 commits into
evcc-io:masterfrom
mfuchs1984:feat/cardata_new_class_status
Open

Cardata: status detection for "New Class" vehicles#30938
mfuchs1984 wants to merge 12 commits into
evcc-io:masterfrom
mfuchs1984:feat/cardata_new_class_status

Conversation

@mfuchs1984

@mfuchs1984 mfuchs1984 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

See #29446

vehicle.body.chargingPort.status is always null on new class vehicles, thus added vehicle.body.chargingPort.combinedStatus which gives values. Since this datapoint is telematics only (thus, not added to the template), I added more values for vehicle.drivetrain.electricEngine.charging.status and vehicle.drivetrain.electricEngine.charging.hvStatus that should allow to detect StatusB. Especially INITIALIZATION has been seen in all logs after connecting, so it should allow to reliably detect the status.

Since for "New Class" vehicles, no mqtt charging port status is available, this PR changes the order of evaluation of charging status and port status.

Previously, the port status was checked first, when not available, the status function returned api.StatusNone and api.ErrNotAvailable. Since port status is currently not available through mqtt on "New Class" vehicles, this made vehicle detection impossible
Now, it evaluates the charging status first. This is available through mqtt for all vehicles. Since "Neue Klasse" vehicles go through INITIALIZATION after connecting, this should allow to detect api.StatusB. In case this does not work reliably, "New Class" vehicle owners might enable welcomecharge, so "CHARGINGACTIVE" -> api.StatusC can be used for vehicle detection.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The BMW cardata package gains support for a new vehicle catalogue field, vehicle.body.chargingPort.combinedStatus. In api.go, this field is added to requiredKeys and requiredVersion is bumped from v5 to v6. In provider.go, a shared isNilOrEmpty helper is introduced and used by Provider.String(), Provider.Int(), and Provider.Float() for consistent nil and empty-string availability checks. Additionally, Provider.Status() is updated to fall back to reading combinedStatus when the primary chargingPort.status key lookup fails, returning api.StatusNone on error, and a new membership check maps several charging states (initialization, paused, ended, not-charging, waiting, finished) directly to api.StatusB, expanding the previously narrower state-handling logic.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation and implementation details of the status fallback mechanism.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title directly and clearly reflects the main purpose of the PR—adding status detection for New Class vehicles, which is the primary objective documented in the PR summary.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@vehicle/bmw/cardata/api.go`:
- Line 20: The string "vehicle.body.chargingPort.combinedStatus" in the
requiredKeys slice literal is missing a trailing comma after it. Add a comma
immediately after this string entry to fix the compilation error in the slice
literal.

In `@vehicle/bmw/cardata/provider.go`:
- Around line 210-220: The code contains a typo in the function call on line 210
where sices.Contains is used, but sices is undefined. Replace sices with slices
to use the Go standard library slices package which provides the Contains
function. This will resolve the compile error in the Status() method.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 03b6523a-d450-4109-8a6d-f55a451feafc

📥 Commits

Reviewing files that changed from the base of the PR and between 11f7ef5 and a328560.

📒 Files selected for processing (2)
  • vehicle/bmw/cardata/api.go
  • vehicle/bmw/cardata/provider.go

Comment thread vehicle/bmw/cardata/api.go Outdated
Comment thread vehicle/bmw/cardata/provider.go Outdated

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@vehicle/bmw/cardata/api.go`:
- Line 20: Remove the `"vehicle.body.chargingPort.combinedStatus"` entry from
the `requiredKeys` collection in the BMW cardata API configuration. Since the
template documentation treats `combinedStatus` as optional and varies by vehicle
model, and the `Status()` method already contains fallback logic to handle its
absence, this key should not be enforced as mandatory for container creation.
This aligns the implementation with the documented design that allows optional
data points per vehicle model.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4acc5d3f-0a0f-4ee8-836b-50e08c20de13

📥 Commits

Reviewing files that changed from the base of the PR and between a328560 and 4cb5710.

📒 Files selected for processing (2)
  • vehicle/bmw/cardata/api.go
  • vehicle/bmw/cardata/provider.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • vehicle/bmw/cardata/provider.go

Comment thread vehicle/bmw/cardata/api.go
@mfuchs1984 mfuchs1984 changed the title Cardata: status fallbacks for "New Class" vehicles Cardata: status detection for "New Class" vehicles Jun 16, 2026
@mfuchs1984
mfuchs1984 marked this pull request as draft June 17, 2026 07:57
@andig

andig commented Jun 18, 2026

Copy link
Copy Markdown
Member

Fehlt hier noch was?

@mfuchs1984

mfuchs1984 commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

Ja, es hier eine Herausforderung: es gibt keinen connected status, der über mqtt kommt. vehicle.body.chargingPort.combinedStatus kommt nur über telematics. Da per default beim Start von evcc soweit ich bei mir in den logs sehe kein telematics call stattfindet, funktioniert das erst, nachdem einmal die config page geöffnet wurde oder eine Weile keine mqtt Daten eingingen.

Die Fahrzeugdetektion könnte dennoch über vehicle.drivetrain.electricEngine.charging.status "initalizing" laufen, aber man darf dann nicht mehr mit StatusNone raus gehen, wenn die chargingPort Daten noch fehlen oder muss die Reihenfolge umdrehen.

Dann bleibt aber immer noch die korrekte Detektion nach evcc Neustart mit angestecktem, aber nicht ladendem Auto übrig, zudem ist unklar, ob die Statusdetektion beim Anstecken 100% funktioniert.

Aus meiner Sicht:

  1. Telematics update beim evcc start und / oder Status Funktion überarbeiten, dass fehlende vehicle.body.chargingPort.combinedStatus` und vehicle.body.chargingPort.status` nicht zu einem Fehler führen, sondern der Rest der Funktion auch noch ausgeführt wird.
  2. Wenn die Detektion von Neue Klasse Fahrzeugen dann noch nicht funktioniert, wäre wohl ein telematics Update beim Anstecken im Rahmen der Fahrzeugerkennung notwendig.

Kanns leider wegen Urlaub gerade nicht machen...

@andig

andig commented Jun 18, 2026

Copy link
Copy Markdown
Member

… oder mal BMW support anpingen

@mfuchs1984

Copy link
Copy Markdown
Collaborator Author

Hast du da einen Kontakt? Sonst müsste das wohl einer oder am besten mehrere der Neue Klasse iX3 Besitzer @HMSC2019 @werner2000x-svg @LukasM42 @olivarel @Oliver26316 @Bernd2211 @granini22 machen.

@andig

andig commented Jun 18, 2026

Copy link
Copy Markdown
Member

Contact info@evcc.io

@granini22

Copy link
Copy Markdown

Ich habe hier einen IX3 NA5 stehen. Wenn Ihr mir sagt, was Ihr braucht oder wo ich schauen soll, dann gebt bescheid. Aktuell habe ich

Version
v0.309.1 (1056e85)
Release nightly
Website [evcc.io](https://evcc.io/

installiert.

@github-actions github-actions Bot added the stale Outdated and ready to close label Jun 25, 2026
@github-actions github-actions Bot closed this Jun 30, 2026
@mfuchs1984 mfuchs1984 reopened this Jun 30, 2026
@github-actions github-actions Bot removed the stale Outdated and ready to close label Jun 30, 2026
@github-actions github-actions Bot added the stale Outdated and ready to close label Jul 7, 2026
@mfuchs1984

Copy link
Copy Markdown
Collaborator Author

BMW cardata support hat prompt geantwortet. Ich gehe aber davon aus, dass es eine Weile dauern wird, bis sich das technisch etwas tut. Werde den PR also fertig machen. Notfalls wäre dann halt welcomecharge für die Detektion des Fahrzeugs notwendig.

@github-actions github-actions Bot removed the stale Outdated and ready to close label Jul 9, 2026
@mfuchs1984
mfuchs1984 force-pushed the feat/cardata_new_class_status branch from c733d64 to 0d76948 Compare July 16, 2026 11:39
@mfuchs1984

Copy link
Copy Markdown
Collaborator Author

I changed the order of evaluation of charging status and port status.

  • Previously, the port status was checked first, when not available, the status function returned api.StatusNone and api.ErrNotAvailable. Since port status is currently not available through mqtt on "New Class" vehicles, this made vehicle detection impossible
  • Now, it evaluates the charging status first. This is available through mqtt for all vehicles. Since "Neue Klasse" vehicles go through INITIALIZATION after connecting, this should allow to detect api.StatusB. In case this does not work reliably, "New Class" vehicle owners might enable welcomecharge, so "CHARGINGACTIVE" -> api.StatusC can be used for vehicle detection.

Tested this extensively with my i5 to make sure not to introduce regressions for CLAR platform vehicles.

@mfuchs1984

Copy link
Copy Markdown
Collaborator Author

Added a general hint concerning welcomecharge to the template for cases where vehicle detection is unreliable. This already helped some i3 owners in the past, so it should be useful independent from the not yet known necessity to activate it for New Class vehicles.

@mfuchs1984
mfuchs1984 marked this pull request as ready for review July 16, 2026 12:48
@mfuchs1984
mfuchs1984 requested a review from andig July 16, 2026 12:49

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • In Status(), the error from reading vehicle.drivetrain.electricEngine.charging.hvStatus is ignored (cs, _); if this is intentional, consider adding a brief comment to clarify that a missing hvStatus is expected and falls back to port-based detection.
  • The repeated literal slices passed to slices.Contains for charge status evaluation could be refactored into named package-level variables or maps to avoid duplication and make it easier to maintain or extend the set of recognized states.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `Status()`, the error from reading `vehicle.drivetrain.electricEngine.charging.hvStatus` is ignored (`cs, _`); if this is intentional, consider adding a brief comment to clarify that a missing hvStatus is expected and falls back to port-based detection.
- The repeated literal slices passed to `slices.Contains` for charge status evaluation could be refactored into named package-level variables or maps to avoid duplication and make it easier to maintain or extend the set of recognized states.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread vehicle/bmw/cardata/provider.go
Comment thread vehicle/bmw/cardata/provider.go
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