feat(energy): add typed live_status/site_info listeners for energy sites - #13
Conversation
Mirrors the vehicle listener idiom: get_energysite(site_id) returns a TeslemetryStreamEnergySite with listen_LiveStatus/listen_SiteInfo, unwrapping the flat live_status/site_info envelope (full documents, not field deltas) and delivering snapshot-then-live the same way vehicle State does.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3fbad17ae8
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ```python | ||
| async def main(): | ||
| async with aiohttp.ClientSession() as session: | ||
| async with TeslemetryStream( |
There was a problem hiding this comment.
Instantiate the stream without
async with
When a user runs this newly added energy-site example, execution stops here with TypeError because TeslemetryStream implements neither the synchronous nor asynchronous context-manager protocol. Instantiate it normally and explicitly call its synchronous close() method so the documented listener flow can run.
Useful? React with 👍 / 👎.
…attern TeslemetryStream has no __aenter__/__aexit__, so `async with TeslemetryStream(...)` raises a TypeError - switch to direct instantiation with an explicit close(), matching the working custom-listener example already in the README.
|
Confirmed - |
Intent
Adds typed listener support for Teslemetry's new energy site SSE events,
live_statusandsite_info, mirroring the existing vehicle listener idiom.Unlike vehicle telemetry signals, these events arrive as flat envelopes (
{createdAt, site_id, isCache?, live_status|site_info}) rather than nested underdata, and the payload is a full opaque document per event rather than a field delta - there's no per-field config to enable, since the server auto-polls subscribed sites.stream.get_energysite(site_id)returns aTeslemetryStreamEnergySitewithlisten_LiveStatus/listen_SiteInfo, each unwrapping the matching document. Snapshot-on-connect (an initial event withisCache: true) is delivered through the same listener, matching how vehicleStateis delivered on connect.Contract taken from Teslemetry/api PR 310 (
src/routes/sse/index.ts,liveStatusSchema.ts,siteInfoSchema.ts) at its current HEAD. That server feature is flag-gated and still open - this change is forward-compatible and inert (the listeners simply never fire) until it ships.tests/test_energysite_events.pycovers document unwrapping, site-id and topic filtering, listener removal, andget_energysiteid normalization/caching, using fixtures shaped from PR 310's schemas.