@eiannone/tesla-api 1.16.0 → 1.18.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.
Files changed (2) hide show
  1. package/TeslaApi.js +15 -4
  2. 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);
@@ -33,8 +34,9 @@ class TeslaApi {
33
34
  }
34
35
 
35
36
  #decodeStatus(statusCode) {
36
- switch(statusCode) {
37
+ switch(statusCode) { // https://developer.tesla.com/docs/fleet-api#response-codes
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
@@ -110,9 +112,18 @@ class TeslaApi {
110
112
  return this.#apiCall((id == null)? this.vid : id);
111
113
  }
112
114
 
113
- async getVehicleData(id = null) {
114
- const vid = (id == null)? this.vid : id;
115
- return this.#apiCall(vid + "/vehicle_data");
115
+ /**
116
+ * https://developer.tesla.com/docs/fleet-api#vehicle_data
117
+ * Starting from firmware update 2023.38+, if you don't specify any endopint, the following ones are returned:
118
+ * charge_state, climate_state, drive_state (without location), gui_settings, vehicle_config, vehicle_state
119
+ * You can ask for the following specific endpoints:
120
+ * charge_state, climate_state, closures_state, drive_state, gui_settings, location_data, vehicle_config, vehicle_state,
121
+ * vehicle_data_combo
122
+ */
123
+ async getVehicleData(endpoints = [], id = null) {
124
+ let path = ((id == null)? this.vid : id) + "/vehicle_data";
125
+ if (endpoints.length > 0) path += "?endpoints="+endpoints.join('%3B');
126
+ return this.#apiCall(path);
116
127
  }
117
128
 
118
129
  async wakeUp(id = null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eiannone/tesla-api",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "description": "Nodejs Tesla API",
5
5
  "type": "module",
6
6
  "main": "index.js",