@eiannone/tesla-api 1.17.0 → 1.19.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.
- package/TeslaApi.js +19 -6
- package/examples/get-vehicle.js +7 -0
- package/package.json +5 -2
package/TeslaApi.js
CHANGED
|
@@ -34,7 +34,7 @@ class TeslaApi {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
#decodeStatus(statusCode) {
|
|
37
|
-
switch(statusCode) {
|
|
37
|
+
switch(statusCode) { // https://developer.tesla.com/docs/fleet-api#response-codes
|
|
38
38
|
case 401: return ApiError.UNAUTHORIZED;
|
|
39
39
|
case 403: return ApiError.FORBIDDEN;
|
|
40
40
|
case 404: return ApiError.NO_VEHICLE;
|
|
@@ -62,7 +62,9 @@ class TeslaApi {
|
|
|
62
62
|
const req = request(BASE_URL + "/api/1/vehicles/" + path, {
|
|
63
63
|
headers: headers,
|
|
64
64
|
timeout: this.timeout,
|
|
65
|
-
method: method
|
|
65
|
+
method: method,
|
|
66
|
+
minVersion: 'TLSv1.3',
|
|
67
|
+
maxVersion: 'TLSv1.3'
|
|
66
68
|
}, res => {
|
|
67
69
|
if (res.statusCode > 199 && res.statusCode < 300) {
|
|
68
70
|
res.setEncoding('utf8');
|
|
@@ -112,9 +114,18 @@ class TeslaApi {
|
|
|
112
114
|
return this.#apiCall((id == null)? this.vid : id);
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
/**
|
|
118
|
+
* https://developer.tesla.com/docs/fleet-api#vehicle_data
|
|
119
|
+
* Starting from firmware update 2023.38+, if you don't specify any endopint, the following ones are returned:
|
|
120
|
+
* charge_state, climate_state, drive_state (without location), gui_settings, vehicle_config, vehicle_state
|
|
121
|
+
* You can ask for the following specific endpoints:
|
|
122
|
+
* charge_state, climate_state, closures_state, drive_state, gui_settings, location_data, vehicle_config, vehicle_state,
|
|
123
|
+
* vehicle_data_combo
|
|
124
|
+
*/
|
|
125
|
+
async getVehicleData(endpoints = [], id = null) {
|
|
126
|
+
let path = ((id == null)? this.vid : id) + "/vehicle_data";
|
|
127
|
+
if (endpoints.length > 0) path += "?endpoints="+endpoints.join('%3B');
|
|
128
|
+
return this.#apiCall(path);
|
|
118
129
|
}
|
|
119
130
|
|
|
120
131
|
async wakeUp(id = null) {
|
|
@@ -137,7 +148,9 @@ class TeslaApi {
|
|
|
137
148
|
'Content-Length': postData.length
|
|
138
149
|
},
|
|
139
150
|
timeout: 30000,
|
|
140
|
-
method: 'POST'
|
|
151
|
+
method: 'POST',
|
|
152
|
+
minVersion: 'TLSv1.3',
|
|
153
|
+
maxVersion: 'TLSv1.3'
|
|
141
154
|
}, res => {
|
|
142
155
|
if (res.statusCode > 199 && res.statusCode < 300) {
|
|
143
156
|
res.setEncoding('utf8');
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {TeslaApi} from '../TeslaApi.js';
|
|
2
|
+
|
|
3
|
+
const ACCESS_TOKEN = '123456789abcdef'; // Replace with your actual access token
|
|
4
|
+
const VEHICLE_ID = '1234567890'; // Replace with your actual vehicle ID
|
|
5
|
+
|
|
6
|
+
const api = new TeslaApi(ACCESS_TOKEN, VEHICLE_ID);
|
|
7
|
+
api.getVehicle().then(console.log);
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eiannone/tesla-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Nodejs Tesla API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": "Emanuele Iannone",
|
|
8
8
|
"license": "MIT",
|
|
9
|
-
"repository":
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/eiannone/tesla-api.git"
|
|
12
|
+
},
|
|
10
13
|
"dependencies": {
|
|
11
14
|
"ws": "^8.2.3"
|
|
12
15
|
}
|