Skip to content

fix(teslamate_vehicle): read the location topic as well (0.2.2) - #280

Merged
frahlg merged 1 commit into
mainfrom
teslamate-location
Nov 25, 2026
Merged

frahlg merged 1 commit into
mainfrom
teslamate-location

Conversation

@frahlg

@frahlg frahlg commented Nov 25, 2026

Copy link
Copy Markdown
Member

Why

TeslaMate's MQTT page now marks teslamate/cars/{id}/latitude and .../longitude as deprecated in favour of .../location, a JSON object with latitude and longitude. The page also says location is never published empty. When no geofence is set, teslamate_vehicle uses the car's position to work out site_distance_m. Once TeslaMate stops sending the old topics, that distance goes away.

Refs #278

What

  • The driver reads location with host.json_decode, wrapped in pcall as the repo's structure tests require. It fills the same plug.lat / plug.lon state.
  • It still reads latitude and longitude, so older TeslaMate versions keep working.
  • Messages are applied in arrival order, so the newest one sets the position, whichever topic it came on.
  • A location is taken only when both keys hold finite numbers in range (±90, ±180). Anything else leaves the last position as it was: text that is not JSON, JSON cut short, null, a list, a missing key, a string or boolean value, NaN, 1e999, or a payload that is not text. Both coordinates change together or neither does, so a bad message never pairs a new latitude with an old longitude and never puts the car at 0,0.
  • Same rules as before: a position does not make the charge level fresh, the coordinates are not emitted, and a set geofence still decides at_site. An explicit 0 is still read as a real coordinate on both paths.
  • The old-topic check now shares one range helper with location. It behaves the same as before for every string tonumber can parse.
  • Version 0.2.2 via make bump-driver, with the generated catalog files and a CHANGELOG entry.

FTW's bundled recovery snapshot keeps 0.2.1 until someone moves the pin in srcfl/ftw.

Tests

New harness file drivers/tests/lua_harness/test_teslamate_vehicle_location.lua, run from drivers/tests/test_teslamate_vehicle.py:

  • location alone gives the distance, moves the car, and keeps the level not fresh.
  • Key order, spaces and extra keys do not matter.
  • The old topics still work.
  • Newest wins when old and new arrive in either order, in one poll or across polls.
  • 17 malformed or out-of-range payloads, plus a table payload, leave the exact earlier distance unchanged.
  • A bad location before any position gives no distance, not 0,0.
  • 0,0 is read the same way on both paths. NaN on the old topics is ignored.
  • The geofence still decides, and cleanup forgets the position.

I checked that the tests catch real faults by breaking the driver on purpose four ways: ignoring the topic, skipping the range check, allowing half updates or 0 defaults, and dropping pcall. Each one fails the new test.

Local runs:

  • make test-driver ID=teslamate_vehicle: 43 passed, 13 skipped
  • make check: 5435 passed, 927 skipped

This has not been run against a real TeslaMate broker. The manifest already says the driver has not been run against a car.

🤖 Generated with Claude Code

TeslaMate's MQTT page now marks latitude and longitude deprecated in
favour of location, JSON {"latitude": <float>, "longitude": <float>}.
Without a geofence the driver uses the car's position for its distance
from the site.

Read location with host.json_decode under pcall and keep reading the old
topics for older TeslaMate versions. The newest message sets the
position. A location that is not JSON, lacks a key, or holds a value that
is not a finite number in range leaves the last position untouched. The
position still does not make the charge level fresh.

Refs #278

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T07:29:28.221956Z 2356abb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit b07a409 into main Nov 25, 2026
5 checks passed
@frahlg
frahlg deleted the teslamate-location branch November 25, 2026 07:30
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.

1 participant