Skip to content

feat(energy): add typed live_status/site_info listeners for energy sites - #13

Merged
Bre77 merged 2 commits into
mainfrom
fm/pts-energy-events
Jul 29, 2026
Merged

feat(energy): add typed live_status/site_info listeners for energy sites#13
Bre77 merged 2 commits into
mainfrom
fm/pts-energy-events

Conversation

@Bre77

@Bre77 Bre77 commented Jul 29, 2026

Copy link
Copy Markdown
Member

Intent

Adds typed listener support for Teslemetry's new energy site SSE events, live_status and site_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 under data, 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 a TeslemetryStreamEnergySite with listen_LiveStatus/listen_SiteInfo, each unwrapping the matching document. Snapshot-on-connect (an initial event with isCache: true) is delivered through the same listener, matching how vehicle State is 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.py covers document unwrapping, site-id and topic filtering, listener removal, and get_energysite id normalization/caching, using fixtures shaped from PR 310's schemas.

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread README.md Outdated
```python
async def main():
async with aiohttp.ClientSession() as session:
async with TeslemetryStream(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
@Bre77

Bre77 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Confirmed - TeslemetryStream has no __aenter__/__aexit__ anywhere in the library, so async with TeslemetryStream(...) was never valid. Fixed in 2790c39: the example now instantiates directly and closes explicitly with stream.close(), matching the working "Writing Your Own Listener" example already in the README. (Also caught that close() is sync, not async, while fixing it.) Verified locally that the corrected pattern runs without the TypeError, and mypy/tests are green.

@Bre77
Bre77 merged commit 64ff862 into main Jul 29, 2026
15 checks passed
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