Skip to content

tesla: add odometer#3684

Merged
benderl merged 2 commits into
openWB:masterfrom
benderl:tesla
Jul 19, 2026
Merged

tesla: add odometer#3684
benderl merged 2 commits into
openWB:masterfrom
benderl:tesla

Conversation

@benderl

@benderl benderl commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@benderl benderl added the enhancement New feature or request label Jul 19, 2026
@benderl
benderl requested a review from Copilot July 19, 2026 10:48

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

Adds odometer support to the Tesla vehicle SoC module by extending the Tesla API data fetch and wiring the new value into the shared CarState.

Changes:

  • Switch Tesla SoC fetch to use a new API call that also returns odometer and stores it in CarState.
  • Adjust Tesla configuration type hints to use Optional[...] for nullable parameters.
  • Store Tesla token created_at as an int timestamp.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/modules/vehicles/tesla/soc.py Fetches odometer alongside SoC/range and returns it via CarState.
packages/modules/vehicles/tesla/config.py Tightens nullability typing for token/configuration parameters.
packages/modules/vehicles/tesla/api.py Adds odometer extraction from vehicle_data response; normalizes created_at type.
Comments suppressed due to low confidence (1)

packages/modules/vehicles/tesla/api.py:103

  • This PR removed/renamed api.request_soc_range, but there is still a unit test (packages/modules/vehicles/tesla/soc_test.py) monkeypatching api.request_soc_range. Since soc.fetch() now calls api.request_data(), the test will hit the real network unless the test is updated. To keep backwards compatibility (and keep existing tests/mocks working), consider restoring a request_soc_range() wrapper and implementing request_data() in terms of it, while tolerating legacy mocks that return only 3 values (soc/range/timestamp).
def request_data(vehicle: int, token: TeslaSocToken) -> Tuple[float, int, float, int]:
    vehicle_id = __get_vehicle_id(vehicle, token)
    data_part = f"vehicles/{vehicle_id}/vehicle_data"
    response = __request_data(data_part, token)
    response = json.loads(response)

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

@benderl
benderl merged commit 8ca8b7d into openWB:master Jul 19, 2026
1 check passed
@benderl
benderl deleted the tesla branch July 19, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants