@teslemetry/api 0.0.1

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.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Teslemetry TypeScript API
2
+
3
+ The official TypeScript/JavaScript client for the [Teslemetry](https://teslemetry.com) API.
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).
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).
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.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @teslemetry/api
21
+ # or
22
+ pnpm add @teslemetry/api
23
+ # or
24
+ yarn add @teslemetry/api
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { Teslemetry } from "@teslemetry/api";
31
+
32
+ const token = process.env.TESLEMETRY_ACCESS_TOKEN;
33
+ const vin = process.env.TESLEMETRY_VIN;
34
+
35
+ const teslemetry = new Teslemetry(token);
36
+
37
+ // Get a vehicle instance
38
+ const vehicle = teslemetry.getVehicle(vin);
39
+
40
+ // API: Get vehicle state
41
+ const state = await vehicle.api.state();
42
+ console.log("Battery Level:", state.charge_state.battery_level);
43
+
44
+ // API: Send a command
45
+ await vehicle.api.flashLights();
46
+
47
+ // Stream: Listen for real-time data
48
+ vehicle.sse.onSignal("Speed", (speed) => {
49
+ console.log(`Current Speed: ${speed}`);
50
+ });
51
+
52
+ await teslemetry.sse.connect();
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ ### Initialization
58
+
59
+ Initialize the `Teslemetry` client with your access token. You can optionally specify a region ("na" or "eu"), otherwise it will be automatically detected.
60
+
61
+ ```typescript
62
+ import { Teslemetry } from "@teslemetry/api";
63
+
64
+ const teslemetry = new Teslemetry("YOUR_ACCESS_TOKEN");
65
+ // or with specific region
66
+ const teslemetryEu = new Teslemetry("YOUR_ACCESS_TOKEN", "eu");
67
+ ```
68
+
69
+ ### Vehicle Control
70
+
71
+ The `getVehicle(vin)` method returns an object containing both `api` and `sse` handlers for a specific vehicle.
72
+
73
+ ```typescript
74
+ const myCar = teslemetry.getVehicle("VIN123456789");
75
+
76
+ // Get detailed vehicle data
77
+ const vehicleData = await myCar.api.vehicleData();
78
+
79
+ // Commands
80
+ await myCar.api.doorLock();
81
+ await myCar.api.autoConditioningStart();
82
+ await myCar.api.chargeStart();
83
+ ```
84
+
85
+ ### Real-time Streaming (SSE)
86
+
87
+ Teslemetry supports streaming vehicle data updates via Server-Sent Events.
88
+
89
+ ```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));
95
+
96
+ // Handle connection status
97
+ teslemetry.sse.onConnection((isConnected) => {
98
+ console.log(isConnected ? "Connected!" : "Disconnected");
99
+ });
100
+
101
+ // Start the stream
102
+ await teslemetry.sse.connect();
103
+
104
+ // Stop streaming
105
+ teslemetry.sse.disconnect();
106
+ ```
107
+
108
+ ### Energy Sites
109
+
110
+ Interact with Tesla Energy products.
111
+
112
+ ```typescript
113
+ const site = teslemetry.energySite(12345);
114
+ const data = await site.getSiteInfo();
115
+ ```
116
+
117
+ ## Development
118
+
119
+ To build the package locally:
120
+
121
+ ```bash
122
+ pnpm install
123
+ pnpm build
124
+ ```
125
+
126
+ ## License
127
+
128
+ Apache-2.0