Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/powerwall-publish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tesla-fleet-api": minor
---

Publish the local Powerwall client as `tesla-fleet-api/powerwall` (PW-17): `PowerwallClient`, the gateway merge classes and the `Powerwall*` errors. The read-only check ran on a real Powerwall 3 gateway. No write has run from Node on real hardware, so treat each write as not yet verified.
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ A funnel, not a selector: no source health, availability, grace windows or prior

## Local Powerwall (`src/powerwall/`)

- **Publish gate:** `./powerwall` stays out of `tsdown.config.ts` and `exports` until PW-17, after a read-only run on a real gateway. Writes have only ever run against `test/helpers/fakegateway.ts`, and no autonomous session sends one to a real gateway.
- `./powerwall` is published (PW-17), after a read-only run on a real gateway. Writes have only ever run against `test/helpers/fakegateway.ts`, and no autonomous session sends one to a real gateway.
- TLS verification is off on `V1rTransport`'s own `https.Agent` only: `NODE_TLS_REJECT_UNAUTHORIZED` would also disable the cloud's checks.
- A v1r POST is sent once and never retried. Only REST GETs retry, once, after a re-login. LAN envelopes differ from the cloud's, which is why `EnergyDeviceSigner.envelope` is cloud-only.
- **Rules that differ from Python on purpose, so do not "fix" them back:** `cancel_max_backup` and `remove_authorized_client` tolerate only an empty reply, plus code 5 on a cancel. An island reply that does not decode raises. `connect_gateway` sends nothing to an address outside `is_lan_address`, and refuses another DIN. `write_config` rejects non-finite numbers and runs one at a time. Doc 08 section 6 has the rest.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ The Homey adapter's defaults are conservative guesses until the BLE-00 probe has

## Local Powerwall

**Not exported yet.** A client for a Powerwall gateway on your LAN is built and tested in this repository, but `tesla-fleet-api/powerwall` is not in the `exports` map, so it cannot be imported from npm. It ships after a read-only check has passed on a real gateway, and no write has run from Node on real hardware. [docs/powerwall.md](docs/powerwall.md) describes the planned API.
A client for a Powerwall gateway on your LAN is exported as `tesla-fleet-api/powerwall`. A read-only check has passed on a real gateway, but no write has run from Node on real hardware. [docs/powerwall.md](docs/powerwall.md) describes the API.

## OAuth

Expand Down
2 changes: 1 addition & 1 deletion docs/powerwall.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Control a Powerwall gateway over your LAN, with the cloud as a fallback.

**Status: not published.** `tesla-fleet-api/powerwall` is not in the package's `exports` map yet, so it cannot be imported from npm. It ships after the read-only check below has passed on a real gateway. The examples show the import it will have.
**Status: published** as `tesla-fleet-api/powerwall`, after the read-only check below passed on a real gateway.

**No write has run from Node on real hardware.** Each write below has only run against a fake gateway in this repository's tests. Python has run the same commands on a Powerwall 3, but that does not prove Node's bytes reach a gateway the same way. Treat every write as not yet verified, and read the state back after using one.

Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@
"default": "./dist/bluetooth/esphome.cjs"
}
},
"./powerwall": {
"import": {
"types": "./dist/powerwall.d.mts",
"default": "./dist/powerwall.mjs"
},
"require": {
"types": "./dist/powerwall.d.cts",
"default": "./dist/powerwall.cjs"
}
},
"./package.json": "./package.json"
},
"sideEffects": false,
Expand Down
14 changes: 2 additions & 12 deletions scripts/parity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@
"./bluetooth/homey": "src/bluetooth/adapters/homey.ts",
"./bluetooth/noble": "src/bluetooth/adapters/noble.ts",
"./bluetooth/esphome": "src/bluetooth/adapters/esphome.ts",
"./powerwall": "src/powerwall/index.ts",
};
/** Built and tested, not in `exports` until PW-17. */
const GATED_ENTRY = "src/powerwall/index.ts";
const GATED_REASON = "built, but ./powerwall is not exported until PW-17";
const GATED_SOURCE = "src/powerwall/";

/** Python class to the Node class that plays its part. */
const CLASS_MAP: Readonly<Record<string, string>> = {
Expand Down Expand Up @@ -283,7 +280,6 @@
/** Top-level declarations: functions with parameters, object literals with members. */
decls: Map<string, { file: string; params: NodeParam[] | null; members: Record<string, string | number | null> | null; value: string | number | null; kind: string }>;
exported: Map<string, string>;
gated: Set<string>;
};

function nodeLiteral(e: ts.Expression | undefined): string | number | null {
Expand Down Expand Up @@ -428,8 +424,6 @@
if (!exported.has(n)) exported.set(n, path);
});
}
const gated = new Set<string>();
exportsOf(GATED_ENTRY, "", (n) => gated.add(n));

// Pull inherited members down, so a lookup sees the whole chain.
const resolved = new Set<string>();
Expand All @@ -443,7 +437,7 @@
};
for (const c of classes.values()) fill(c);

return { classes, decls, exported, gated };
return { classes, decls, exported };
}

type Status = "present" | "partial" | "missing";
Expand Down Expand Up @@ -577,8 +571,7 @@

function reach(shape: NodeShape, name: string): { ok: boolean; note: string | null } {
if (shape.exported.has(name)) return { ok: true, note: null };
const file = shape.classes.get(name)?.file ?? shape.decls.get(name)?.file ?? "";

Check failure on line 574 in scripts/parity.ts

View workflow job for this annotation

GitHub Actions / Build, Lint & Test / Node 24

'file' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 574 in scripts/parity.ts

View workflow job for this annotation

GitHub Actions / Build, Lint & Test / Node 22

'file' is assigned a value but never used. Allowed unused vars must match /^_/u
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if (shape.gated.has(name) || file.startsWith(GATED_SOURCE)) return { ok: false, note: GATED_REASON };
return { ok: false, note: "declared, but not exported from any entry" };
}

Expand Down Expand Up @@ -723,9 +716,6 @@
console.log(line([area, rs.length, count(rs, "present"), count(rs, "partial"), count(rs, "missing")]));
}
console.log(line(["Total", results.length, count(results, "present"), count(results, "partial"), count(results, "missing")]));
const gated = results.filter((r) => r.note.includes(GATED_REASON));
const unblocked = gated.filter((r) => r.note === GATED_REASON).length;
console.log(`\nLocal Powerwall: ${gated.length} partial rows are gated on PW-17, and ${unblocked} of them have no other difference.`);
const unresolved = results.filter((r) => r.status === "missing" && r.note.startsWith("unresolved")).length;
const listed = results.filter((r) => r.status === "missing" && r.note.startsWith("doc 01")).length;
console.log(`Missing: ${listed} listed in doc 01, ${count(results, "missing") - listed - unresolved} named here, ${unresolved} unresolved.`);
Expand Down
1 change: 1 addition & 0 deletions test/consumers/cjs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ assert.equal(typeof router.is_failover_safe, "function");
const { HomeyBleTransport, HOMEY_MAX_WRITE_SIZE } = require("tesla-fleet-api/bluetooth/homey");
const { NobleBleTransport } = require("tesla-fleet-api/bluetooth/noble");
const { EsphomeBleTransport } = require("tesla-fleet-api/bluetooth/esphome");
assert.equal(typeof require("tesla-fleet-api/powerwall").PowerwallClient, "function");
assert.equal(typeof HomeyBleTransport, "function");
assert.equal(HOMEY_MAX_WRITE_SIZE, 20);
(async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/consumers/esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { BleNotSubmittedError, BroadcastListeners, ReassemblingBuffer, SERVICE_U
import { HOMEY_MAX_WRITE_SIZE, HomeyBleTransport } from "tesla-fleet-api/bluetooth/homey";
import { NobleBleTransport } from "tesla-fleet-api/bluetooth/noble";
import { EsphomeBleTransport } from "tesla-fleet-api/bluetooth/esphome";
import { PowerwallClient } from "tesla-fleet-api/powerwall";

// Each adapter must load with no backend installed, and only fail once it is used.
assert.equal(typeof PowerwallClient, "function");
assert.equal(typeof HomeyBleTransport, "function");
assert.equal(HOMEY_MAX_WRITE_SIZE, 20);
await assert.rejects(new NobleBleTransport().scan({ timeoutMs: 1000 }), /@stoprocent\/noble/);
Expand Down
4 changes: 2 additions & 2 deletions test/docs-samples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ describe("documentation samples", () => {
expect(compile(samples)).toEqual([]);
});

it("would notice a wrong method and the unexported Powerwall entry", { timeout: 120_000 }, () => {
it("would notice a wrong method and an unexported entry", { timeout: 120_000 }, () => {
const failures = compile([
{ name: "wrong.mts", text: 'import { TeslaFleetApi } from "tesla-fleet-api";\nnew TeslaFleetApi({ accessToken, region: "na" }).no_such_method();\n' },
{ name: "gated.mts", text: 'import { PowerwallClient } from "tesla-fleet-api/powerwall";\nconsole.log(PowerwallClient);\n' },
{ name: "gated.mts", text: 'import { nothing } from "tesla-fleet-api/not-exported";\nconsole.log(nothing);\n' },
]);
expect(failures).toHaveLength(2);
});
Expand Down
1 change: 1 addition & 0 deletions tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineConfig({
"bluetooth/homey": "src/bluetooth/adapters/homey.ts",
"bluetooth/noble": "src/bluetooth/adapters/noble.ts",
"bluetooth/esphome": "src/bluetooth/adapters/esphome.ts",
powerwall: "src/powerwall/index.ts",
},
format: ["esm", "cjs"],
dts: true,
Expand Down
Loading