@eiannone/tesla-api 1.9.1 → 1.10.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 CHANGED
@@ -47,10 +47,17 @@ class TeslaApi {
47
47
  }
48
48
  }
49
49
 
50
- async #apiCall(path, method = 'GET') {
51
- return new Promise((resolve, reject) => {
50
+ async #apiCall(path, method = 'GET', params = undefined) {
51
+ return new Promise((resolve, reject) => {
52
+ const postData = (typeof params != 'undefined')? JSON.stringify(params) : '';
53
+ let headers = { 'user-agent': "TeslaEma", 'Authorization': "Bearer " + this.token };
54
+ if (postData.length > 0) {
55
+ headers['Content-Type'] = 'application/json';
56
+ headers['Content-Length'] = postData.length;
57
+ }
58
+
52
59
  const req = request(BASE_URL + "/api/1/vehicles/" + path, {
53
- headers: { 'user-agent': "TeslaEma", 'Authorization': "Bearer " + this.token },
60
+ headers: headers,
54
61
  timeout: this.timeout,
55
62
  method: method
56
63
  }, res => {
@@ -89,6 +96,7 @@ class TeslaApi {
89
96
  // - ENOTFOUND
90
97
  reject(new ApiError(e.message + " ("+e.code+")", ApiError.NETWORK));
91
98
  });
99
+ if (postData.length > 0) req.write(postData);
92
100
  req.end();
93
101
  });
94
102
  }
@@ -116,19 +124,19 @@ class TeslaApi {
116
124
  return this.#apiCall(vid + "/wake_up", "POST");
117
125
  }
118
126
 
119
- async command(command, vehicle_id = null) {
127
+ async command(command, params = undefined, vehicle_id = null) {
120
128
  const vid = (vehicle_id == null)? this.vid : vehicle_id;
121
- return this.#apiCall(vid + "/command/" + command, "POST");
129
+ return this.#apiCall(vid + "/command/" + command, "POST", params);
122
130
  }
123
131
 
124
132
  async #oauthCall(params) {
125
- const post_data = JSON.stringify(params);
126
133
  return new Promise((resolve, reject) => {
134
+ const postData = JSON.stringify(params);
127
135
  const req = request(BASE_URL + '/oauth/token', {
128
136
  headers: {
129
137
  'user-agent': "TeslaEma",
130
138
  'Content-Type': 'application/json',
131
- 'Content-Length': post_data.length
139
+ 'Content-Length': postData.length
132
140
  },
133
141
  timeout: 30000,
134
142
  method: 'POST'
@@ -157,7 +165,7 @@ class TeslaApi {
157
165
  // - ENOTFOUND
158
166
  reject(new ApiError(e.message + " ("+e.code+")", ApiError.NETWORK));
159
167
  });
160
- req.write(post_data);
168
+ req.write(postData);
161
169
  req.end();
162
170
  });s
163
171
  }
package/TeslaStream.js CHANGED
@@ -164,7 +164,7 @@ export default class TeslaStream extends EventEmitter {
164
164
  case "client_error":
165
165
  this.log("Client error: " + d.value, "error");
166
166
  this.emit('error', d.value);
167
- this.#reconnect();
167
+ if (d.value != "Can't validate token. ") this.#reconnect();
168
168
  break;
169
169
  default:
170
170
  this.log("Stream API error ["+d.error_type+"]: " + data, "error");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eiannone/tesla-api",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Nodejs Tesla API",
5
5
  "type": "module",
6
6
  "main": "index.js",