@teslemetry/api 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +94 -50
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,18 +1,13 @@
1
- # Teslemetry TypeScript API
1
+ # Teslemetry TypeScript SDK
2
2
 
3
3
  The official TypeScript/JavaScript client for the [Teslemetry](https://teslemetry.com) API.
4
4
 
5
- This library provides a convenient wrapper for interacting with Tesla vehicles and energy sites via the Teslemetry service, including support for standard API commands and real-time streaming data (Server-Sent Events).
5
+ This library provides a strictly typed, easy-to-use wrapper for interacting with Tesla vehicles and energy sites. It supports standard API commands, state retrieval, and real-time streaming data via Server-Sent Events (SSE).
6
6
 
7
- Further information about each API method can be found in the [Teslemetry API Documentation](https://teslemetry.com/docs/api), and [Tesla Fleet API Documentation](https://developer.tesla.com/docs/fleet-api/endpoints/vehicle-commands).
7
+ ## 📚 Documentation
8
8
 
9
- ## Features
10
-
11
- - 🚗 **Vehicle API**: Full control and state retrieval (lock/unlock, climate, charging, etc.).
12
- - ⚡ **Energy API**: Monitor and control Tesla Energy sites (Solar, Powerwall).
13
- - 📡 **Streaming (SSE)**: Real-time vehicle data streaming with `TeslemetryStream`.
14
- - 🌍 **Region Aware**: Automatic region detection and handling (NA/EU).
15
- - 🔒 **Type-Safe**: Built with TypeScript for full type inference and safety.
9
+ - **[Teslemetry API Reference](https://api.teslemetry.com/docs)**: Detailed documentation for all API endpoints, parameters, and response values.
10
+ - **[Tesla Fleet API](https://developer.tesla.com/docs/fleet-api)**: Official Tesla documentation for underlying vehicle commands and data.
16
11
 
17
12
  ## Installation
18
13
 
@@ -29,26 +24,26 @@ yarn add @teslemetry/api
29
24
  ```typescript
30
25
  import { Teslemetry } from "@teslemetry/api";
31
26
 
32
- const token = process.env.TESLEMETRY_ACCESS_TOKEN;
33
- const vin = process.env.TESLEMETRY_VIN;
34
-
35
- const teslemetry = new Teslemetry(token);
27
+ // Initialize with your access token
28
+ const teslemetry = new Teslemetry(process.env.TESLEMETRY_ACCESS_TOKEN);
36
29
 
37
- // Get a vehicle instance
30
+ // Get a specific vehicle
31
+ const vin = "5YJ...";
38
32
  const vehicle = teslemetry.getVehicle(vin);
39
33
 
40
- // API: Get vehicle state
34
+ // 1. Get Vehicle State
41
35
  const state = await vehicle.api.state();
42
- console.log("Battery Level:", state.charge_state.battery_level);
36
+ console.log("Vehicle State:", state);
43
37
 
44
- // API: Send a command
38
+ // 2. Send a Command (e.g., Flash Lights)
45
39
  await vehicle.api.flashLights();
46
40
 
47
- // Stream: Listen for real-time data
41
+ // 3. Stream Real-time Data
48
42
  vehicle.sse.onSignal("Speed", (speed) => {
49
- console.log(`Current Speed: ${speed}`);
43
+ console.log(`Current Speed: ${speed} mph`);
50
44
  });
51
45
 
46
+ // Connect to the stream
52
47
  await teslemetry.sse.connect();
53
48
  ```
54
49
 
@@ -56,71 +51,120 @@ await teslemetry.sse.connect();
56
51
 
57
52
  ### Initialization
58
53
 
59
- Initialize the `Teslemetry` client with your access token. You can optionally specify a region ("na" or "eu"), otherwise it will be automatically detected.
54
+ The `Teslemetry` class is the main entry point. It automatically handles region detection (NA/EU) upon the first request, or you can specify it manually.
60
55
 
61
56
  ```typescript
62
57
  import { Teslemetry } from "@teslemetry/api";
63
58
 
59
+ // Automatic region detection (recommended)
64
60
  const teslemetry = new Teslemetry("YOUR_ACCESS_TOKEN");
65
- // or with specific region
66
- const teslemetryEu = new Teslemetry("YOUR_ACCESS_TOKEN", "eu");
61
+
62
+ // Manual region specification
63
+ const teslemetryEu = new Teslemetry("YOUR_ACCESS_TOKEN", { region: "eu" });
67
64
  ```
68
65
 
69
- ### Vehicle Control
66
+ ### Vehicle API
70
67
 
71
- The `getVehicle(vin)` method returns an object containing both `api` and `sse` handlers for a specific vehicle.
68
+ Use `getVehicle(vin)` to interact with a vehicle. This returns an object containing two specialized handlers:
69
+ - `api`: for standard REST API calls (commands, state).
70
+ - `sse`: for real-time streaming.
71
+
72
+ #### Commands & State
73
+ The `.api` property contains methods for all supported Tesla commands.
72
74
 
73
75
  ```typescript
74
- const myCar = teslemetry.getVehicle("VIN123456789");
76
+ const vehicle = teslemetry.getVehicle("VIN...");
77
+
78
+ // Get full vehicle data
79
+ const data = await vehicle.api.vehicleData();
75
80
 
76
- // Get detailed vehicle data
77
- const vehicleData = await myCar.api.vehicleData();
81
+ // Climate Control
82
+ await vehicle.api.autoConditioningStart();
83
+ await vehicle.api.setTemps(20, 20); // Driver, Passenger (Celsius)
78
84
 
79
- // Commands
80
- await myCar.api.doorLock();
81
- await myCar.api.autoConditioningStart();
82
- await myCar.api.chargeStart();
85
+ // Charging
86
+ await vehicle.api.chargeStart();
87
+ await vehicle.api.setChargeLimit(80);
88
+
89
+ // Locking
90
+ await vehicle.api.lockDoors();
83
91
  ```
84
92
 
85
- ### Real-time Streaming (SSE)
93
+ > **Note:** For a comprehensive list of all available methods and their parameters, please refer to the [Teslemetry API Docs](https://teslemetry.com/docs/api). The SDK methods map 1:1 with these endpoints.
86
94
 
87
- Teslemetry supports streaming vehicle data updates via Server-Sent Events.
95
+ #### Real-time Streaming (SSE)
96
+ The `.sse` property allows you to subscribe to specific vehicle signals.
88
97
 
89
98
  ```typescript
90
- const myCar = teslemetry.getVehicle("VIN123456789");
91
-
92
- // Subscribe to specific signals
93
- myCar.sse.onSignal("PackCurrent", (val) => console.log("Current:", val));
94
- myCar.sse.onSignal("ChargerVoltage", (val) => console.log("Voltage:", val));
99
+ // Subscribe to signals
100
+ vehicle.sse.onSignal("PackCurrent", (val) => console.log("Current:", val));
101
+ vehicle.sse.onSignal("ChargerVoltage", (val) => console.log("Voltage:", val));
95
102
 
96
- // Handle connection status
103
+ // Monitor connection status
97
104
  teslemetry.sse.onConnection((isConnected) => {
98
- console.log(isConnected ? "Connected!" : "Disconnected");
105
+ console.log(isConnected ? "Stream Connected" : "Stream Disconnected");
99
106
  });
100
107
 
101
- // Start the stream
108
+ // Start streaming (connects to the shared Teslemetry stream)
102
109
  await teslemetry.sse.connect();
103
110
 
104
111
  // Stop streaming
105
112
  teslemetry.sse.disconnect();
106
113
  ```
107
114
 
108
- ### Energy Sites
115
+ ### Energy API
109
116
 
110
- Interact with Tesla Energy products.
117
+ Interact with Tesla Energy sites (Solar, Powerwall, Wall Connector).
111
118
 
112
119
  ```typescript
120
+ // Get an energy site instance by Site ID
113
121
  const site = teslemetry.energySite(12345);
114
- const data = await site.getSiteInfo();
122
+
123
+ // Get site status and info
124
+ const status = await site.getLiveStatus();
125
+ const info = await site.getSiteInfo();
126
+
127
+ // Control operations
128
+ await site.setBackupReserve(20); // Set backup reserve to 20%
129
+ await site.setOperationMode("autonomous");
115
130
  ```
116
131
 
117
- ## Development
132
+ ### Account & Discovery
118
133
 
119
- To build the package locally:
134
+ If you don't know your VINs or Site IDs, you can discover all products on your account.
120
135
 
121
- ```bash
122
- pnpm install
123
- pnpm build
136
+ ```typescript
137
+ // Fetch all vehicles and energy sites
138
+ const products = await teslemetry.createProducts();
139
+
140
+ // Access discovered vehicles
141
+ for (const vin in products.vehicles) {
142
+ const vehicle = products.vehicles[vin];
143
+ console.log(`Found ${vehicle.name} (${vehicle.vin})`);
144
+
145
+ // Use the API immediately
146
+ await vehicle.api.honkHorn();
147
+ }
148
+
149
+ // Access discovered energy sites
150
+ for (const siteId in products.energySites) {
151
+ const site = products.energySites[siteId];
152
+ console.log(`Found Site: ${site.name} (${site.site})`);
153
+ }
154
+ ```
155
+
156
+ ### Error Handling
157
+
158
+ The SDK throws standard Javascript `Error` objects for configuration issues and specific errors for API failures. Streaming errors (like connection drops) are emitted via the stream error handler or specific exception classes.
159
+
160
+ ```typescript
161
+ import { TeslemetryStreamConnectionError } from "@teslemetry/api";
162
+
163
+ try {
164
+ await vehicle.api.wakeUp();
165
+ } catch (error) {
166
+ console.error("Failed to wake up vehicle:", error);
167
+ }
124
168
  ```
125
169
 
126
170
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teslemetry/api",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "API client for Teslemetry",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",