feat: accept externally sourced events via TeslemetryStream.ingest - #41
Merged
Conversation
An observation the library did not read off its own SSE connection - a Bluetooth broadcast, today - can now be handed in as a stream-shaped dict and reaches the same listeners a native event does, with no translation and no second subscription. Events carry an open-ended metadata dict (source, raw) that is recorded but never acted on: dispatch stays arrival-ordered with no per-field state, no deduplication, and no source ranking.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
listen_*callbacks and merge the two itself.TeslemetryStream.ingest(data, vin, metadata, created_at), plusTeslemetryStreamVehicle.ingestas the same call with the VIN filled in. It builds the event in the wire format the connection already sends (vin/data/createdAt) and fans it out through the same dispatch, so existinglisten_*callbacks receive it untranslated. It holds no client and opens no connection: an observation is delivered whether or not the stream is connected, which is the point when the other source is a local radio.metadatais a plain dict carried on the event and never acted on -sourcekeeps provenance visible,rawkeeps the untranslated wire value a boolean collapse discards (any unlocked state reads as unlocked, but which one is still worth having).Metadatainconst.pynames both, and the dict stays open ended so a source can add keys without a format break.metadata.listen()'s per-event dispatch moved unchanged into_dispatch()so both paths share it. Native events are otherwise untouched, which is the first thingtests/test_external_ingest.pyasserts, along with a BLE-shaped and a stream-shaped event for the same field being indistinguishable to a consumer apart from metadata.tesla-fleet-api, in either direction. The shim that shapes a VCSEC broadcast into this format belongs there, and the consumer wires the two together - the same duck-typed compositionEnergySiteRouteralready uses foraiopowerwall.Worth noting for later, not encoded here: a real-vehicle run has Bluetooth leading the stream on every lock transition by ~1s, because the stream emits on a ~1Hz aligned tick rather than because of network latency. That is an argument a precedence rule could be justified one day; it is a separate decision, and this surface takes no position on it.
Ran
uv run --with ruff ruff check teslemetry_streamanduv run --with mypy mypy teslemetry_streamclean, and everytests/test_*.pyscript directly.