@eiannone/tesla-api 1.15.4 → 1.17.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 +6 -9
- package/package.json +1 -1
package/TeslaApi.js
CHANGED
|
@@ -12,6 +12,7 @@ class ApiError extends Error {
|
|
|
12
12
|
static TIMEOUT = 'Timeout';
|
|
13
13
|
static NETWORK = 'Network unavailable';
|
|
14
14
|
static SERVER = 'Internal server error';
|
|
15
|
+
static FORBIDDEN = 'Forbidden';
|
|
15
16
|
|
|
16
17
|
constructor(error, reason = null) {
|
|
17
18
|
super((error instanceof Error)? error.message : error);
|
|
@@ -35,6 +36,7 @@ class TeslaApi {
|
|
|
35
36
|
#decodeStatus(statusCode) {
|
|
36
37
|
switch(statusCode) {
|
|
37
38
|
case 401: return ApiError.UNAUTHORIZED;
|
|
39
|
+
case 403: return ApiError.FORBIDDEN;
|
|
38
40
|
case 404: return ApiError.NO_VEHICLE;
|
|
39
41
|
case 405: return ApiError.IN_SERVICE;
|
|
40
42
|
case 406: return ApiError.NETWORK; // Not Acceptable
|
|
@@ -44,7 +46,7 @@ class TeslaApi {
|
|
|
44
46
|
case 503: return ApiError.NETWORK; // Service unavailable
|
|
45
47
|
case 504: return ApiError.TIMEOUT;
|
|
46
48
|
case 540: return ApiError.UNAVAILABLE; // TODO: check. Should be system booting
|
|
47
|
-
default:
|
|
49
|
+
default: return ApiError.UNKNOWN;
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -81,8 +83,8 @@ class TeslaApi {
|
|
|
81
83
|
// Tries to refresh the tokens
|
|
82
84
|
this.refreshToken(this.refresh_token)
|
|
83
85
|
.then(_ => this.#apiCall(path, method, params))
|
|
84
|
-
.then(
|
|
85
|
-
.catch(
|
|
86
|
+
.then(resolve)
|
|
87
|
+
.catch(reject);
|
|
86
88
|
return;
|
|
87
89
|
}
|
|
88
90
|
let errMsg = res.statusMessage + " ("+res.statusCode+")";
|
|
@@ -115,11 +117,6 @@ class TeslaApi {
|
|
|
115
117
|
return this.#apiCall(vid + "/vehicle_data");
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
async getChargeState(id = null) {
|
|
119
|
-
const vid = (id == null)? this.vid : id;
|
|
120
|
-
return this.#apiCall(vid + "/data_request/charge_state");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
120
|
async wakeUp(id = null) {
|
|
124
121
|
const vid = (id == null)? this.vid : id;
|
|
125
122
|
return this.#apiCall(vid + "/wake_up", "POST");
|
|
@@ -171,7 +168,7 @@ class TeslaApi {
|
|
|
171
168
|
});
|
|
172
169
|
}
|
|
173
170
|
|
|
174
|
-
|
|
171
|
+
onTokenRefresh(callback) {
|
|
175
172
|
this.cb_refreshToken = callback;
|
|
176
173
|
}
|
|
177
174
|
|