fix(teslemetry): accept clients key in authorized-clients response#80
Merged
Conversation
added 2 commits
July 14, 2026 13:32
Tesla's live endpoint (Release 953) carries the authorized-client list under `clients`, not `authorized_clients` as originally documented - confirmed via a live capture of a Powerwall 3 site with five populated entries. `_authorized_clients_list()` now checks both key variants, symmetric to the existing public_key/publicKey handling, so a perfectly valid response no longer parses to an empty/failed result.
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
Fix TeslemetryEnergySite.find_authorized_clients() to accept Tesla's real response key: the authorized-clients list arrives under 'clients', not 'authorized_clients' as originally documented in PR #76/#79. Evidence: a live capture (2026-07-14) from a Powerwall 3 site showed Tesla's Release-953 endpoint returning a fully-populated 5-entry list under the 'clients' key, which the existing parser didn't recognize, causing it to raise/collapse to empty on a perfectly valid response. Fix: _authorized_clients_list() now checks both 'authorized_clients' and 'clients' key names (using the existing key-presence-check _field() helper, symmetric to the public_key/publicKey handling), preserving all PR #79 behavior (null body and unrecognized shapes still raise InvalidResponse; empty list under either key still parses to []). Added regression tests covering the real captured 5-client sample (structure verbatim, identifiers anonymized to synthetic values) plus both key variants and the empty-list case. This unblocks the Home Assistant energy local-control config flow (core PR #176328 is pinned waiting on this fix), so a library release (version bump + git tag per this repo's release process in AGENTS.md) is needed promptly after merge.
What Changed
TeslemetryEnergySite._authorized_clients_list()now unwraps the authorized-clients envelope under eitherauthorized_clientsorclients- a live capture from Tesla's Release-953 endpoint showed the real response uses theclientskey, which the previous parser rejected withInvalidResponseon a valid populated response. All existing strictness is preserved: null bodies and unrecognized shapes still raiseInvalidResponse, and an empty list under either key still parses toclients == [].tests/test_teslemetry_authorized_clients.pycovering the captured 5-client Release-953 payload (identifiers anonymized), both key variants, and the empty-list case; full suite passes (347 tests) and an E2E before/after demo confirmed the base commit raises while this branch parses all 5 clients.docs/teslemetry.mdand the AGENTS.md entry to document both accepted response keys (the docs previously described only theauthorized_clientsenvelope shape).Risk Assessment
✅ Low: A one-line parser fix using an existing presence-checking helper, backed by a live-captured sample, comprehensive regression tests covering both key variants and all prior invariants (null body, unrecognized shape, empty list), with docs and AGENTS.md updated to match.
Testing
Ran the new regression tests and full suite (347 passed), then demonstrated the fix end-to-end: the same real-world Release-953 response shape (clients list under the
clientskey) that made the base commit raise InvalidResponse now parses into 5 typed AuthorizedClient entries through the full HTTP request/parse path; null-body and unrecognized-shape responses still raise as before. No UI surface is involved (async library), so evidence is a CLI transcript.Evidence: Before/after CLI transcript (base rejects, fix parses 5 clients)
[BASE 704281f] GET .../command/authorized_clients -> Release-953 body (list under 'clients' key, 5 entries) [BASE 704281f] find_authorized_clients() RAISED InvalidResponse: valid populated response rejected [FIXED efbd4f6] GET .../command/authorized_clients -> Release-953 body (list under 'clients' key, 5 entries) [FIXED efbd4f6] find_authorized_clients() parsed 5 clients: public_key=SYNTHETIC_PUBLIC_KEY_1 state=VERIFIED public_key=SYNTHETIC_PUBLIC_KEY_2 state=PENDING_VERIFICATION public_key=SYNTHETIC_PUBLIC_KEY_3 state=PENDING_VERIFICATION public_key=SYNTHETIC_PUBLIC_KEY_4 state=VERIFIED public_key=SYNTHETIC_PUBLIC_KEY_5 state=PENDING_VERIFICATIONEvidence: E2E demo script (mocked-session Teslemetry client, real parse path)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
docs/teslemetry.md:551- User-facing docs are stale after the parser change: docs/teslemetry.md still says the typed helper "only unwraps the one envelope shape" and that "Only an explicitly emptyauthorized_clientslist parses toclients == []", but _authorized_clients_list() now also accepts theclientskey (which is what Tesla's live Release-953 endpoint actually returns). Update the paragraph to mention both accepted keys, mirroring the AGENTS.md entry that was updated in this commit.🔧 Fix: document both accepted authorized-clients response keys
1 info still open:
tesla_fleet_api.egg-info/PKG-INFO:140- The docs-only commit efbd4f6 also commits regenerated tesla_fleet_api.egg-info/ build artifacts (PKG-INFO, SOURCES.txt) whose content changes come from earlier unrelated commits (BLE broadcast listeners, router docs). These files are auto-generated by setuptools; they were already tracked at the base commit so this matches existing repo practice, but the unrelated churn inflates the diff. Consider untracking/gitignoring egg-info in a follow-up.✅ **Test** - passed
✅ No issues found.
uv run pytest tests/test_teslemetry_authorized_clients.py -v (16 tests incl. new ClientsKeyVariantTests with the anonymized 5-client Release-953 capture)uv run pytest tests (full suite, 347 passed)E2E before/after demo: fed the Release-953-shaped payload (list underclients, 5 entries) through a real Teslemetry client with only the aiohttp session mocked, viaenergySites.create(12345).find_authorized_clients()- base commit 704281f raises InvalidResponse, target efbd4f6 parses 5 clients with VERIFIED/PENDING_VERIFICATION states (demo_clients_key.pyrun against both trees)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.