Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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/remove-esphome-export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tesla-fleet-api": minor
---

Remove the `./bluetooth/esphome` export (`EsphomeBleTransport`) and the optional `@2colors/esphome-native-api` peer dependency. Use `./bluetooth/noble` or `./bluetooth/homey` instead.
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This file is the project's committed home for project-intrinsic agent knowledge:
- A reply is checked against its request first (`isForeignReply`). An empty uuid can only ack or answer a read, because real VCSEC leaves it empty.
- `pair` writes through `_send` exactly once, and resolves only on an explicit success or an authenticated handshake with this key. An abort is checked in `writeFrame`, the last point before the radio.
- Attempts on one peripheral share one radio link, so an abandoned attempt must never close or resubscribe a link a newer one owns (`LinkClaims`, `test/bluetooth/adapters/late-connect.test.ts`).
- Adapters are one file each, with no top-level import of a backend, and `autoInstallPeers: false` keeps native builds out of this repository. Homey's constants follow the BLE-00 probe app, not document 06, and nothing has run on one. ESPHome's reply matching is by type alone, so every call goes through the per-proxy queue; a GATT error there must stay a plain error.
- Adapters are one file each, with no top-level import of a backend, and `autoInstallPeers: false` keeps native builds out of this repository. Homey's constants follow the BLE-00 probe app, not document 06, and nothing has run on one.
- `test/bluetooth/coverage.test.ts` locks what falls through to REST. `test/helpers/fakeblelink.ts` keeps its own framing, and `FakeBleLink.vcsecWrites` is how to prove "exactly one".
- `scripts/ble-live/` is the live harness. `STEPS` is a closed list, and the CLI takes step names, never a command name. Never add a pass-through, a destructive command or a re-send after a timeout.

Expand Down
5 changes: 0 additions & 5 deletions OBSERVATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Stages still to run, from design document 06, section 4:
| -- | -- |
| HW-0 (BLE-00) | What Homey's BLE does, with the probe app. Decides the Homey adapter's constants. |
| HW-1 | The library on noble. |
| HW-2 | The library on an ESPHome proxy, including that the CCCD write is needed. |
| HW-3 | Rare paths: image paging, readers only Python's mocks cover. |
| HW-4 | Pairing, with the captain at the car. |
| HW-5 | Homey end to end, and a 24 h soak. |
Expand Down Expand Up @@ -49,10 +48,6 @@ Stages still to run, from design document 06, section 4:

**Setup:** the published packages, read and run on a development machine, with no radio, proxy or car. These check our reading of each package, and say nothing about hardware.

- **`@2colors/esphome-native-api` 1.3.6, with `google-protobuf` 4.0.3:**
- A `BluetoothGATTGetServicesResponse` hand-encoded as ESPHome sends it, with unpacked `uuid` fields, decoded to the dashed UUIDs for the Tesla service, the write and notify characteristics, and the CCCD, with no precision lost on the 64-bit halves. Packed `uuid` fields throw inside the package, since `reader.readPackedUint64` is gone from `google-protobuf` 4, so a stub that packs them cannot stand in for a proxy.
- `read` and notification `data` come back base64 encoded, not as bytes, though the package's types call them only `string`.
- A `Buffer` passed as a write's value round-trips byte for byte, including `0xff` and `0x80`.
- **`@stoprocent/noble` 2.8.0:**
- The package's main entry builds a default noble as it loads. `lib/resolve-bindings.js` does not, and loads with no native build present.
- `disconnectAsync()` waits for a `disconnect` event, so calling it on a dead link would never settle.
Expand Down
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ It needs Node 22 or later, ships ESM and CommonJS, and has one runtime dependenc
| `tesla-fleet-api/bluetooth` | `TeslaBluetooth`, `VehicleBluetooth`, the `BleTransport` contract, stream glue |
| `tesla-fleet-api/bluetooth/homey` | Bluetooth through a Homey app |
| `tesla-fleet-api/bluetooth/noble` | Bluetooth through `@stoprocent/noble` |
| `tesla-fleet-api/bluetooth/esphome` | Bluetooth through an ESPHome proxy |
| `tesla-fleet-api/tariff` | `getTariffPeriods`, `unwrapTariffV2`, with no protobuf code |
| `tesla-fleet-api/const` | Enums, `Models`, `Region`, `SERVERS` |
| `tesla-fleet-api/types` | Response types |
Expand Down Expand Up @@ -135,7 +134,6 @@ Install the backend you want, and pass its transport to `createBluetooth`. Each
| -- | -- | -- | -- |
| `./bluetooth/homey` | `HomeyBleTransport` | Nothing. It takes `this.homey.ble`. | A Homey app |
| `./bluetooth/noble` | `NobleBleTransport` | `@stoprocent/noble`, which is native | Linux, macOS, Windows |
| `./bluetooth/esphome` | `EsphomeBleTransport` | `@2colors/esphome-native-api` | Anything with a TCP route to a dedicated proxy |

On a computer:

Expand All @@ -152,19 +150,6 @@ await vehicle.charge_state();
await vehicle.disconnect();
```

Through an ESPHome proxy:

```ts
import { TeslaBluetooth } from "tesla-fleet-api/bluetooth";
import { EsphomeBleTransport } from "tesla-fleet-api/bluetooth/esphome";

const transport = new EsphomeBleTransport({ host: proxyHost, encryptionKey });
const vehicle = new TeslaBluetooth({ privateKey }).vehicles.createBluetooth(vin, { transport });
await vehicle.door_lock();
await vehicle.disconnect();
transport.close();
```

In a Homey app, which needs the `homey:wireless:ble` permission:

```ts
Expand Down
26 changes: 2 additions & 24 deletions docs/bluetooth_vehicles.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Each adapter is its own entry point, and importing one loads no backend. `npm in
| -- | -- | -- | -- |
| `./bluetooth/homey` | `HomeyBleTransport` | `this.homey.ble`, by structural types. No package. | A Homey app |
| `./bluetooth/noble` | `NobleBleTransport` | `@stoprocent/noble` (native) | Linux, macOS, Windows |
| `./bluetooth/esphome` | `EsphomeBleTransport` | `@2colors/esphome-native-api` (JS and WASM) | Anywhere with a TCP route to a proxy |

Web Bluetooth is not provided: the core uses Node `crypto` and `Buffer`, so it does not run in a browser.

Expand Down Expand Up @@ -74,25 +73,6 @@ Limits:
- Generic Access (`1800`) may be hidden on BlueZ and CoreBluetooth paths. `query_display_name` and `query_appearance` then return `null`.
- Connecting to a device no scan has seen first runs a scan.

### ESPHome proxy

```ts
new EsphomeBleTransport({ host, port, encryptionKey, password }); // loads the package on first use
new EsphomeBleTransport({ connection }); // a Connection you own
```

Call `transport.close()` to end an API connection the transport opened. It never closes one you passed in.

Limits:

- **Use a dedicated proxy.** A proxy serves advertisements to one client. If Home Assistant holds it, a scan sees nothing and reports no error.
- The proxy must scan actively, as the vehicle's name is in the scan response.
- A proxy has few connection slots, and this adapter does not wait for a free one. If connect fails while scans see the car, free a slot first.
- Everything shares one queue per proxy, so two vehicles on a proxy slow each other down.
- A GATT error surfaces as a timeout, and a command then reads as unconfirmed. That is the safe reading.
- A connect needs an address type, which only an advertisement carries, so a device no scan has seen runs a scan first.
- One ESP32-S3 board scanned perfectly and could not connect, in Python's trials. A scan proves nothing about the radio's transmit path.

### Writing your own

Implement `BleTransport` from `tesla-fleet-api/bluetooth`. `src/bluetooth/transport.ts` lists the rules, and `test/bluetooth/adapters/contract.test.ts` tests them.
Expand Down Expand Up @@ -204,7 +184,6 @@ A held link receives unsigned `VehicleStatus` broadcasts. Each `listen_*` return
| -- | -- | -- |
| Homey | **Never** | Never |
| noble | **Never** | Direct adapters, through `bleak` |
| ESPHome proxy | **Never** | Yes, including the charge port trials |
| `pair` | **Never** | One real key card tap |
| Signing, framing and sessions | Fake vehicle only, against golden vectors | Yes |

Expand All @@ -216,11 +195,10 @@ The adapters' decisions come from reading each backend's code and types, and fro

```bash
BLE_LIVE_VIN=<vin> BLE_LIVE_KEY_PATH=<file> pnpm ble:live --transport noble
BLE_LIVE_VIN=<vin> BLE_LIVE_KEY_PATH=<file> BLE_LIVE_PROXY_HOST=<host> \
pnpm ble:live --transport esphome --steps charge_limit
BLE_LIVE_VIN=<vin> BLE_LIVE_KEY_PATH=<file> pnpm ble:live --transport noble --steps charge_limit
```

`--list` shows the steps. With no `--steps` it runs the plain reads. `BLE_LIVE_PROXY_PORT`, `BLE_LIVE_PROXY_KEY` and `BLE_LIVE_PROXY_PASSWORD` are optional. Homey has no command line, as it needs a test app.
`--list` shows the steps. With no `--steps` it runs the plain reads. Homey has no command line, as it needs a test app.

- A setting is snapshotted, changed once, verified by a fresh read, restored by an absolute command, and read again.
- **A command that times out is never sent again.** The next read decides, and the run stops at the first step that did not end cleanly.
Expand Down
14 changes: 0 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,6 @@
"default": "./dist/bluetooth/noble.cjs"
}
},
"./bluetooth/esphome": {
"import": {
"types": "./dist/bluetooth/esphome.d.mts",
"default": "./dist/bluetooth/esphome.mjs"
},
"require": {
"types": "./dist/bluetooth/esphome.d.cts",
"default": "./dist/bluetooth/esphome.cjs"
}
},
"./powerwall": {
"import": {
"types": "./dist/powerwall.d.mts",
Expand All @@ -167,13 +157,9 @@
"@teslemetry/tesla-protocol": "~6.1.0"
},
"peerDependencies": {
"@2colors/esphome-native-api": "^1.3.6",
"@stoprocent/noble": "^2.8.0"
},
"peerDependenciesMeta": {
"@2colors/esphome-native-api": {
"optional": true
},
"@stoprocent/noble": {
"optional": true
}
Expand Down
22 changes: 2 additions & 20 deletions scripts/ble-live/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
// on a fake link.
//
// BLE_LIVE_VIN=<vin> BLE_LIVE_KEY_PATH=<file> pnpm ble:live --transport noble
// BLE_LIVE_VIN=<vin> BLE_LIVE_KEY_PATH=<file> BLE_LIVE_PROXY_HOST=<host> \
// [BLE_LIVE_PROXY_PORT=<port>] [BLE_LIVE_PROXY_KEY=<base64>] [BLE_LIVE_PROXY_PASSWORD=<password>] \
// pnpm ble:live --transport esphome --steps charge_limit
//
// Options:
// --transport <name> noble or esphome. Homey has no CLI: it needs a test app.
// --transport <name> noble. Homey has no CLI: it needs a test app.
// --steps <a,b,c> Steps to run. Defaults to every plain read.
// --captain-present Allow steps with a physical effect. Only say so if it is true.
// --list Print the steps, and touch nothing.
Expand All @@ -20,7 +17,6 @@
// Exits 0 when every step ended cleanly, 1 when one did not, 2 on bad setup.
import { existsSync, realpathSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { EsphomeBleTransport } from "../../src/bluetooth/adapters/esphome.js";
import { NobleBleTransport } from "../../src/bluetooth/adapters/noble.js";
import { get_name } from "../../src/bluetooth/names.js";
import TeslaBluetooth from "../../src/bluetooth/teslabluetooth.js";
Expand All @@ -33,17 +29,6 @@ type TransportFactory = (env: Env) => BleTransport;

const TRANSPORTS: Record<string, TransportFactory> = {
noble: () => new NobleBleTransport(),
esphome: (env) => {
if (!env.BLE_LIVE_PROXY_HOST) {
throw new Error("Set BLE_LIVE_PROXY_HOST.");
}
return new EsphomeBleTransport({
host: env.BLE_LIVE_PROXY_HOST,
port: env.BLE_LIVE_PROXY_PORT ? Number(env.BLE_LIVE_PROXY_PORT) : undefined,
encryptionKey: env.BLE_LIVE_PROXY_KEY,
password: env.BLE_LIVE_PROXY_PASSWORD,
});
},
};

interface Arguments {
Expand Down Expand Up @@ -140,7 +125,7 @@ export async function main(argv: readonly string[], env: Env, { print = console.
return 2;
}

const output = redactor([vin, get_name(vin).slice(0, -1), keyPath, env.BLE_LIVE_PROXY_HOST, env.BLE_LIVE_PROXY_KEY, env.BLE_LIVE_PROXY_PASSWORD], print);
const output = redactor([vin, get_name(vin).slice(0, -1), keyPath], print);
let transport: BleTransport;
try {
transport = factory(env);
Expand All @@ -165,9 +150,6 @@ export async function main(argv: readonly string[], env: Env, { print = console.
return results.length === steps.length && results.every(({ outcome }) => outcome === "ok") ? 0 : 1;
} finally {
await vehicle.disconnect();
if (transport instanceof EsphomeBleTransport) {
transport.close();
}
}
}

Expand Down
1 change: 0 additions & 1 deletion scripts/parity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const ENTRIES: Readonly<Record<string, string>> = {
"./bluetooth": "src/bluetooth/index.ts",
"./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",
};

Expand Down
Loading
Loading