You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 83a584c
Browse filesBrowse the repository at this point in the historyBrowse files
feat!: treat energy site ids as int, signal number support via X-Library (#49)
Tesla returns energy site ids as JSON numbers; this library previously
forced them to strings throughout. site_id is now int end to end:
get_energysite(str | int) normalises via int(...), energysites is keyed
by int, and event matching casts the incoming site_id/id to int so it
matches whether the api sends a string or a number.
The api tells clients apart by the X-Library header: the legacy value
"python teslemetry-stream" keeps getting strings, anything with a
"/<version>" suffix (read from installed package metadata) opts into
numbers.
BREAKING CHANGE: TeslemetryStreamEnergySite.site_id is now int, not str.
Consumers comparing it against a string will need to update.
Copy file name to clipboardExpand all lines: AGENTS.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ Project-intrinsic knowledge that should travel with the code: build, test, relea
43
43
-`site_info` does **not** carry `tariff_content`/`tariff_content_v2`. The V2 tariff is its own event/listener (`listen_TariffContentV2`), same envelope shape, with a `None` body meaning explicit server-side removal rather than "not received yet".
44
44
- All of these share a silence-means-no-change contract: the server sends a connect-time snapshot and then fires only on change. Freshness lives in REST, never in event cadence.
45
45
- There is deliberately no helper recombining `site_info` and `tariff_content_v2` - it would only ever cover V2 (legacy V1 `tariff_content` has no SSE topic and stays REST-only). A consumer wanting both tariffs uses the REST site_info endpoint.
46
+
- Site ids are `int` throughout, matching Tesla's own JSON-number representation: `get_energysite(site_id: str | int)` normalises via `int(...)` (raising `ValueError` on a non-numeric id), `TeslemetryStream.energysites` is keyed by int, `TeslemetryStreamEnergySite.site_id` is an int, and every site-id/`Key.ID` comparison in `energysite.py` casts the incoming event value with `int(...)` before comparing - so an event carrying either a string or a number matches. The `X-Library` header's `/<version>` suffix (`stream.py`, read from installed package metadata) is the api's signal that this client accepts numeric ids; the bare legacy value means string-only.
46
47
47
48
## Test map
48
49
@@ -58,8 +59,9 @@ Project-intrinsic knowledge that should travel with the code: build, test, relea
58
59
|`str` payload coercion against real telemetry |`test_field_type_coercion.py`|
Create an energy site object to create listeners for `live_status` and `site_info`.
263
+
Create an energy site object to create listeners for `live_status` and `site_info`. Accepts a str or int; the returned object's `site_id` is always normalized to `int`.
264
264
265
265
### `connected -> bool`
266
266
Return if connected.
@@ -346,7 +346,7 @@ A full list of fields and metadata can be found at [api.teslemetry.com/fields.js
346
346
347
347
## Public Methods in TeslemetryStreamEnergySite Class
0 commit comments