Skip to content

feat(api): bundle getTariffPeriods from tesla-fleet-api - #82

Merged
Bre77 merged 1 commit into
mainfrom
fm/tsapi-bundle-gettariffperiods
Aug 1, 2026
Merged

feat(api): bundle getTariffPeriods from tesla-fleet-api#82
Bre77 merged 1 commit into
mainfrom
fm/tsapi-bundle-gettariffperiods

Conversation

@Bre77

@Bre77 Bre77 commented Aug 1, 2026

Copy link
Copy Markdown
Member

Intent

  • The Homey app (and other consumers) currently pulls tariff-rate resolution from a github:Teslemetry/node-tesla-fleet-api source dependency with its own fragile build step, just to get getTariffPeriods. It already depends on @teslemetry/api - re-exporting the helper from there lets it drop the github dependency entirely.
    • Landed in a new src/tariff.ts, co-located with the existing tariff_content_v2 SSE handling (TeslemetryStream.ts / SseTariffContentV2 in const.ts), and re-exported from the package root alongside getTariffPeriods's TariffContentV2/TariffRate/TariffPeriod/TariffResolution types.
    • Sourced from published tesla-fleet-api@^0.2.2 (confirmed the tariff code is present on npm; earlier 0.2.1 was never published) as a devDependency, not a runtime one - tsdown externalizes dependencies/peerDependencies by default but bundles devDependencies, so it gets inlined into dist/ instead. tsdown.config.ts's deps.onlyBundle: ["tesla-fleet-api"] marks that bundling intentional.
    • src/tariff.ts deep-imports tesla-fleet-api/dist/tariff.js + .../types/site_info.js directly rather than the package root, so the bundle only pulls in that helper's own closure (no vehicle/signing/commands code). Verified: rebuilding added ~12.5 KB to dist/index.{cjs,mjs} (168.8 KB -> 181.6 KB), and grepping the output for TeslaFleetApi/Session/SignedCommandError/etc. class names comes back empty - confirmed via the raw dist/index.mjs, not just tsdown's own report.
    • Type reconciliation: the OpenAPI-generated SseTariffContentV2/TariffInfo types carry tariff_content_v2 as untyped { [key: string]: unknown } | null (the server spec doesn't describe its shape), so a consumer narrows/casts that payload to the newly-exported TariffContentV2 before calling getTariffPeriods - documented with an example in the README. Confirmed a standalone consumer importing both getTariffPeriods and TariffContentV2 from the built dist/index.d.mts type-checks cleanly.
    • No runtime dependency added: package.json still has no dependencies/peerDependencies entries.
  • Follow-up (not in this PR): a version bump + npm publish of @teslemetry/api is needed before Homey can switch away from its github dependency.

Adds getTariffPeriods and TariffContentV2 to @teslemetry/api's public
surface, co-located with the existing tariff_content_v2 SSE handling.
The implementation is inlined from tesla-fleet-api at build time (a
devDependency, bundled by tsdown, not a runtime dependency) so
consumers like the Homey app can drop their fragile github-source
dependency on tesla-fleet-api and import this from @teslemetry/api,
which they already depend on.
@Bre77 Bre77 added the fm Opened by a Firstmate crewmate label Aug 1, 2026
@Bre77
Bre77 merged commit 288440b into main Aug 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fm Opened by a Firstmate crewmate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant