@eiannone/tesla-api 1.13.0 → 1.15.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 +12 -7
- package/TeslaStream.js +1 -1
- package/package.json +1 -1
package/TeslaApi.js
CHANGED
|
@@ -216,6 +216,7 @@ class TeslaApi {
|
|
|
216
216
|
this.cb_refreshToken = callback;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
// https://tesla-api.timdorr.com/api-basics/authentication
|
|
219
220
|
async refreshToken(refresh_token) {
|
|
220
221
|
const payLoad = {
|
|
221
222
|
grant_type: 'refresh_token',
|
|
@@ -226,12 +227,13 @@ class TeslaApi {
|
|
|
226
227
|
try {
|
|
227
228
|
let resp = await this.#oauthCall2(payLoad);
|
|
228
229
|
this.refresh_token = resp.refresh_token;
|
|
229
|
-
let oauth = await this.#oauthCall({
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}, resp.access_token);
|
|
234
|
-
this.token = oauth.access_token;
|
|
230
|
+
// let oauth = await this.#oauthCall({
|
|
231
|
+
// grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
232
|
+
// client_id: '81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384',
|
|
233
|
+
// client_secret: 'c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3'
|
|
234
|
+
// }, resp.access_token);
|
|
235
|
+
// this.token = oauth.access_token;
|
|
236
|
+
this.token = resp.access_token;
|
|
235
237
|
if (typeof this.cb_refreshToken == 'function') {
|
|
236
238
|
this.cb_refreshToken(this.token, this.refresh_token);
|
|
237
239
|
}
|
|
@@ -247,7 +249,10 @@ class TeslaApi {
|
|
|
247
249
|
return this.#apiCall().then(vehicles => {
|
|
248
250
|
for (let v = 0; v < vehicles.length; v++) {
|
|
249
251
|
if (!vehicles[v].hasOwnProperty('vehicle_id') || !vehicles[v].hasOwnProperty('id_s')) continue;
|
|
250
|
-
if (vehicles[v].vehicle_id == vehicle_id)
|
|
252
|
+
if (vehicles[v].vehicle_id == vehicle_id) {
|
|
253
|
+
this.vid = vehicles[v].id_s;
|
|
254
|
+
return this.vid;
|
|
255
|
+
}
|
|
251
256
|
}
|
|
252
257
|
throw new ApiError("Vehicle not found");
|
|
253
258
|
});
|
package/TeslaStream.js
CHANGED
|
@@ -58,7 +58,7 @@ export default class TeslaStream extends EventEmitter {
|
|
|
58
58
|
}
|
|
59
59
|
if (this.ws.readyState == WebSocket.CONNECTING) {
|
|
60
60
|
this.ws.removeAllListeners('open');
|
|
61
|
-
this.ws.on('open', _ =>
|
|
61
|
+
this.ws.on('open', _ => this.disconnect(reconnect, unsubscribe));
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
this.state = CLOSING;
|