@teslemetry/api 0.3.0 → 0.5.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/dist/index.cjs +157 -199
- package/dist/index.d.cts +7243 -4808
- package/dist/index.d.mts +7243 -4808
- package/dist/index.mjs +158 -199
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
let events = require("events");
|
|
1
2
|
|
|
2
3
|
//#region src/client/core/bodySerializer.gen.ts
|
|
3
4
|
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
@@ -791,23 +792,6 @@ const getApiRefreshByVin = (options) => (options.client ?? client).get({
|
|
|
791
792
|
...options
|
|
792
793
|
});
|
|
793
794
|
/**
|
|
794
|
-
* Vehicle Image
|
|
795
|
-
*
|
|
796
|
-
* Redirect to the Tesla Design Studio image of a vehicle
|
|
797
|
-
*/
|
|
798
|
-
const getApiImageByVin = (options) => (options.client ?? client).get({
|
|
799
|
-
security: [{
|
|
800
|
-
scheme: "bearer",
|
|
801
|
-
type: "http"
|
|
802
|
-
}, {
|
|
803
|
-
in: "query",
|
|
804
|
-
name: "token",
|
|
805
|
-
type: "apiKey"
|
|
806
|
-
}],
|
|
807
|
-
url: "/api/image/{vin}",
|
|
808
|
-
...options
|
|
809
|
-
});
|
|
810
|
-
/**
|
|
811
795
|
* Vehicle Data
|
|
812
796
|
*
|
|
813
797
|
* Returns the cached vehicle data for this vehicle. location_data will only be present if you have provided the location_data scope.
|
|
@@ -3005,23 +2989,27 @@ const getSseByVin_ = (options) => (options.client ?? client).sse.get({
|
|
|
3005
2989
|
|
|
3006
2990
|
//#endregion
|
|
3007
2991
|
//#region src/TeslemetryVehicleStream.ts
|
|
3008
|
-
var TeslemetryVehicleStream = class {
|
|
2992
|
+
var TeslemetryVehicleStream = class extends events.EventEmitter {
|
|
3009
2993
|
root;
|
|
3010
|
-
stream;
|
|
3011
2994
|
vin;
|
|
3012
2995
|
fields = {};
|
|
3013
2996
|
_pendingFields = {};
|
|
3014
2997
|
_debounceTimeout = null;
|
|
3015
2998
|
logger;
|
|
3016
|
-
|
|
2999
|
+
data;
|
|
3000
|
+
constructor(root, vin) {
|
|
3001
|
+
if (root.sse.vehicles.has(vin)) throw new Error("Vehicle already exists");
|
|
3002
|
+
super();
|
|
3017
3003
|
this.root = root;
|
|
3018
|
-
this.stream = stream;
|
|
3019
3004
|
this.vin = vin;
|
|
3020
|
-
this.logger =
|
|
3021
|
-
|
|
3005
|
+
this.logger = root.sse.logger;
|
|
3006
|
+
this.data = new events.EventEmitter();
|
|
3007
|
+
root.sse.vehicles.set(vin, this);
|
|
3008
|
+
this.on("config", (event) => {
|
|
3022
3009
|
this.fields = event.config.fields;
|
|
3023
|
-
}
|
|
3010
|
+
});
|
|
3024
3011
|
}
|
|
3012
|
+
/** Get the current configuration for the vehicle */
|
|
3025
3013
|
async getConfig() {
|
|
3026
3014
|
const { data, response } = await getApiConfigByVin({ path: { vin: this.vin } });
|
|
3027
3015
|
if (response.status === 200 && data) this.fields = data.fields || {};
|
|
@@ -3030,7 +3018,8 @@ var TeslemetryVehicleStream = class {
|
|
|
3030
3018
|
return;
|
|
3031
3019
|
} else throw new Error(`Failed to get config: ${response.statusText}`);
|
|
3032
3020
|
}
|
|
3033
|
-
|
|
3021
|
+
/** Safely add field configuration to the vehicle */
|
|
3022
|
+
async updateFields(fields) {
|
|
3034
3023
|
this._pendingFields = {
|
|
3035
3024
|
...this._pendingFields,
|
|
3036
3025
|
...fields
|
|
@@ -3049,6 +3038,7 @@ var TeslemetryVehicleStream = class {
|
|
|
3049
3038
|
this._debounceTimeout = null;
|
|
3050
3039
|
}, 100);
|
|
3051
3040
|
}
|
|
3041
|
+
/** Modify the field configuration of the vehicle */
|
|
3052
3042
|
async patchConfig(fields) {
|
|
3053
3043
|
const { data } = await patchApiConfigByVin({
|
|
3054
3044
|
client: this.root.client,
|
|
@@ -3057,6 +3047,7 @@ var TeslemetryVehicleStream = class {
|
|
|
3057
3047
|
});
|
|
3058
3048
|
return data;
|
|
3059
3049
|
}
|
|
3050
|
+
/** Replace the field configuration of the vehicle */
|
|
3060
3051
|
async postConfig(fields) {
|
|
3061
3052
|
const { data } = await postApiConfigByVin({
|
|
3062
3053
|
client: this.root.client,
|
|
@@ -3065,6 +3056,12 @@ var TeslemetryVehicleStream = class {
|
|
|
3065
3056
|
});
|
|
3066
3057
|
return data;
|
|
3067
3058
|
}
|
|
3059
|
+
/**
|
|
3060
|
+
* Add a field to the vehicles streaming configuration
|
|
3061
|
+
* @param field Vehicle Signal
|
|
3062
|
+
* @param interval
|
|
3063
|
+
* @returns
|
|
3064
|
+
*/
|
|
3068
3065
|
async addField(field, interval) {
|
|
3069
3066
|
if (this.fields && this.fields[field] && (interval === void 0 || this.fields[field].interval_seconds === interval)) {
|
|
3070
3067
|
this.logger.debug(`Streaming field ${field} already enabled @ ${this.fields[field]?.interval_seconds || "default"}s`);
|
|
@@ -3073,59 +3070,37 @@ var TeslemetryVehicleStream = class {
|
|
|
3073
3070
|
const value = interval !== void 0 ? { interval_seconds: interval } : null;
|
|
3074
3071
|
this.updateFields({ [field]: value });
|
|
3075
3072
|
}
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
onErrors(callback) {
|
|
3083
|
-
return this.stream.onErrors(callback, { vin: this.vin });
|
|
3084
|
-
}
|
|
3085
|
-
onAlerts(callback) {
|
|
3086
|
-
return this.stream.onAlerts(callback, { vin: this.vin });
|
|
3087
|
-
}
|
|
3088
|
-
onConnectivity(callback) {
|
|
3089
|
-
return this.stream.onConnectivity(callback, { vin: this.vin });
|
|
3090
|
-
}
|
|
3091
|
-
onVehicleData(callback) {
|
|
3092
|
-
return this.stream.onVehicleData(callback, { vin: this.vin });
|
|
3093
|
-
}
|
|
3094
|
-
onConfig(callback) {
|
|
3095
|
-
return this.stream.onConfig(callback, { vin: this.vin });
|
|
3096
|
-
}
|
|
3097
|
-
on(callback) {
|
|
3098
|
-
return this.stream.on((event) => {
|
|
3099
|
-
callback(event);
|
|
3100
|
-
}, { vin: this.vin });
|
|
3101
|
-
}
|
|
3073
|
+
/**
|
|
3074
|
+
* Helper to enable and listen for specific field signals
|
|
3075
|
+
* @param field Vehicle field to listen for
|
|
3076
|
+
* @param callback Callback function to handle signals
|
|
3077
|
+
* @returns Off function to stop the listener
|
|
3078
|
+
*/
|
|
3102
3079
|
onSignal(field, callback) {
|
|
3103
3080
|
this.addField(field).catch((error) => {
|
|
3104
3081
|
this.logger.error(`Failed to add field ${field}:`, error);
|
|
3105
3082
|
});
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
});
|
|
3083
|
+
this.data.on(field, callback);
|
|
3084
|
+
return () => this.data.off(field, callback);
|
|
3085
|
+
}
|
|
3086
|
+
stop() {
|
|
3087
|
+
this.removeAllListeners();
|
|
3088
|
+
this.data.removeAllListeners();
|
|
3113
3089
|
}
|
|
3114
3090
|
};
|
|
3115
3091
|
|
|
3116
3092
|
//#endregion
|
|
3117
3093
|
//#region src/TeslemetryStream.ts
|
|
3118
|
-
var TeslemetryStream = class {
|
|
3094
|
+
var TeslemetryStream = class extends events.EventEmitter {
|
|
3119
3095
|
root;
|
|
3120
3096
|
active = false;
|
|
3121
3097
|
connected = false;
|
|
3122
3098
|
vin;
|
|
3123
3099
|
cache;
|
|
3124
3100
|
logger;
|
|
3125
|
-
listeners = /* @__PURE__ */ new Map();
|
|
3126
|
-
_connectionListeners = /* @__PURE__ */ new Map();
|
|
3127
3101
|
vehicles = /* @__PURE__ */ new Map();
|
|
3128
3102
|
constructor(root, options) {
|
|
3103
|
+
super();
|
|
3129
3104
|
this.root = root;
|
|
3130
3105
|
this.vin = options?.vin;
|
|
3131
3106
|
this.cache = options?.cache;
|
|
@@ -3133,7 +3108,7 @@ var TeslemetryStream = class {
|
|
|
3133
3108
|
if (this.vin) this.getVehicle(this.vin);
|
|
3134
3109
|
}
|
|
3135
3110
|
getVehicle(vin) {
|
|
3136
|
-
if (!this.vehicles.has(vin))
|
|
3111
|
+
if (!this.vehicles.has(vin)) new TeslemetryVehicleStream(this.root, vin);
|
|
3137
3112
|
return this.vehicles.get(vin);
|
|
3138
3113
|
}
|
|
3139
3114
|
async connect() {
|
|
@@ -3152,7 +3127,7 @@ var TeslemetryStream = class {
|
|
|
3152
3127
|
this.logger.info(`Connected to stream`);
|
|
3153
3128
|
retries = 0;
|
|
3154
3129
|
this.connected = true;
|
|
3155
|
-
this.
|
|
3130
|
+
this.emit("connect");
|
|
3156
3131
|
if (sse.stream) for await (const event of sse.stream) {
|
|
3157
3132
|
if (!this.active) break;
|
|
3158
3133
|
this._dispatch(event);
|
|
@@ -3161,13 +3136,13 @@ var TeslemetryStream = class {
|
|
|
3161
3136
|
if (!this.active) break;
|
|
3162
3137
|
this.logger.error("SSE error:", error);
|
|
3163
3138
|
this.connected = false;
|
|
3164
|
-
this.
|
|
3139
|
+
this.emit("disconnect");
|
|
3165
3140
|
retries++;
|
|
3166
3141
|
const delay = Math.min(2 ** retries, 600) * 1e3;
|
|
3167
3142
|
this.logger.info(`Reconnecting in ${delay / 1e3} seconds...`);
|
|
3168
3143
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
3169
3144
|
}
|
|
3170
|
-
this.
|
|
3145
|
+
this.emit("disconnect");
|
|
3171
3146
|
}
|
|
3172
3147
|
disconnect() {
|
|
3173
3148
|
this.active = false;
|
|
@@ -3176,99 +3151,37 @@ var TeslemetryStream = class {
|
|
|
3176
3151
|
close() {
|
|
3177
3152
|
this.active = false;
|
|
3178
3153
|
this.logger.info(`Disconnecting from stream`);
|
|
3179
|
-
this._updateConnectionListeners(false);
|
|
3180
|
-
}
|
|
3181
|
-
onConnection(callback) {
|
|
3182
|
-
const removeListener = () => {
|
|
3183
|
-
this._connectionListeners.delete(removeListener);
|
|
3184
|
-
};
|
|
3185
|
-
this._connectionListeners.set(removeListener, callback);
|
|
3186
|
-
return removeListener;
|
|
3187
|
-
}
|
|
3188
|
-
onState(callback, filters) {
|
|
3189
|
-
return this._createListener("state", callback, filters);
|
|
3190
|
-
}
|
|
3191
|
-
onData(callback, filters) {
|
|
3192
|
-
return this._createListener("data", callback, filters);
|
|
3193
|
-
}
|
|
3194
|
-
onErrors(callback, filters) {
|
|
3195
|
-
return this._createListener("errors", callback, filters);
|
|
3196
|
-
}
|
|
3197
|
-
onAlerts(callback, filters) {
|
|
3198
|
-
return this._createListener("alerts", callback, filters);
|
|
3199
|
-
}
|
|
3200
|
-
onConnectivity(callback, filters) {
|
|
3201
|
-
return this._createListener("connectivity", callback, filters);
|
|
3202
|
-
}
|
|
3203
|
-
onCredits(callback, filters) {
|
|
3204
|
-
return this._createListener("credits", callback, filters);
|
|
3205
|
-
}
|
|
3206
|
-
onVehicleData(callback, filters) {
|
|
3207
|
-
return this._createListener("vehicle_data", callback, filters);
|
|
3208
3154
|
}
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
return this._createListener("all", callback, filters);
|
|
3214
|
-
}
|
|
3215
|
-
_updateConnectionListeners(value) {
|
|
3216
|
-
for (const listener of this._connectionListeners.values()) listener(value);
|
|
3217
|
-
}
|
|
3218
|
-
_createListener(eventType, callback, filters) {
|
|
3219
|
-
const entry = {
|
|
3220
|
-
callback,
|
|
3221
|
-
filters
|
|
3222
|
-
};
|
|
3223
|
-
if (!this.listeners.has(eventType)) this.listeners.set(eventType, /* @__PURE__ */ new Set());
|
|
3224
|
-
this.listeners.get(eventType).add(entry);
|
|
3225
|
-
return () => {
|
|
3226
|
-
const set = this.listeners.get(eventType);
|
|
3227
|
-
if (set) {
|
|
3228
|
-
set.delete(entry);
|
|
3229
|
-
if (set.size === 0) this.listeners.delete(eventType);
|
|
3230
|
-
}
|
|
3231
|
-
};
|
|
3155
|
+
parseCreatedAt(event) {
|
|
3156
|
+
const [main, ns] = event.createdAt.split(".");
|
|
3157
|
+
const date = /* @__PURE__ */ new Date(main + "Z");
|
|
3158
|
+
return new Date(date.getTime() + parseInt((ns || "000").substring(0, 3)));
|
|
3232
3159
|
}
|
|
3233
3160
|
_dispatch(event) {
|
|
3234
|
-
if (event.
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
if (
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
if (
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
if (
|
|
3254
|
-
|
|
3255
|
-
}
|
|
3161
|
+
if ("state" in event) this.emit("state", event);
|
|
3162
|
+
else if ("data" in event) this.emit("data", event);
|
|
3163
|
+
else if ("errors" in event) this.emit("errors", event);
|
|
3164
|
+
else if ("alerts" in event) this.emit("alerts", event);
|
|
3165
|
+
else if ("networkInterface" in event) this.emit("connectivity", event);
|
|
3166
|
+
else if ("credits" in event) this.emit("credits", event);
|
|
3167
|
+
else if ("vehicle_data" in event) this.emit("vehicle_data", event);
|
|
3168
|
+
else if ("config" in event) this.emit("config", event);
|
|
3169
|
+
const vehicle = this.vehicles.get(event.vin);
|
|
3170
|
+
if (vehicle) {
|
|
3171
|
+
if ("state" in event) vehicle.emit("state", event);
|
|
3172
|
+
else if ("data" in event) {
|
|
3173
|
+
vehicle.emit("data", event);
|
|
3174
|
+
Object.keys(event.data).forEach((key) => {
|
|
3175
|
+
if (event.data[key] !== void 0) vehicle.data.emit(key, event.data[key]);
|
|
3176
|
+
});
|
|
3177
|
+
} else if ("errors" in event) vehicle.emit("errors", event);
|
|
3178
|
+
else if ("alerts" in event) vehicle.emit("alerts", event);
|
|
3179
|
+
else if ("networkInterface" in event) vehicle.emit("connectivity", event);
|
|
3180
|
+
else if ("vehicle_data" in event) vehicle.emit("vehicle_data", event);
|
|
3181
|
+
else if ("config" in event) vehicle.emit("config", event);
|
|
3256
3182
|
}
|
|
3257
3183
|
}
|
|
3258
3184
|
};
|
|
3259
|
-
function recursiveMatch(filter, event) {
|
|
3260
|
-
if (filter === null || filter === void 0) return true;
|
|
3261
|
-
if (typeof filter !== "object" || filter === null || typeof event !== "object" || event === null) return filter === event;
|
|
3262
|
-
if (Array.isArray(filter)) {
|
|
3263
|
-
if (!Array.isArray(event)) return false;
|
|
3264
|
-
return filter.some((fItem) => event.some((eItem) => recursiveMatch(fItem, eItem)));
|
|
3265
|
-
}
|
|
3266
|
-
for (const key in filter) {
|
|
3267
|
-
if (!(key in event)) return false;
|
|
3268
|
-
if (!recursiveMatch(filter[key], event[key])) return false;
|
|
3269
|
-
}
|
|
3270
|
-
return true;
|
|
3271
|
-
}
|
|
3272
3185
|
|
|
3273
3186
|
//#endregion
|
|
3274
3187
|
//#region src/TeslemetryChargingApi.ts
|
|
@@ -3329,12 +3242,24 @@ var TeslemetryChargingApi = class {
|
|
|
3329
3242
|
|
|
3330
3243
|
//#endregion
|
|
3331
3244
|
//#region src/TeslemetryEnergyApi.ts
|
|
3332
|
-
var TeslemetryEnergyApi = class {
|
|
3245
|
+
var TeslemetryEnergyApi = class extends events.EventEmitter {
|
|
3333
3246
|
root;
|
|
3334
3247
|
siteId;
|
|
3248
|
+
refreshDelay = 3e4;
|
|
3249
|
+
refreshInterval = {
|
|
3250
|
+
siteInfo: null,
|
|
3251
|
+
liveStatus: null
|
|
3252
|
+
};
|
|
3253
|
+
refreshClients = {
|
|
3254
|
+
siteInfo: /* @__PURE__ */ new Set(),
|
|
3255
|
+
liveStatus: /* @__PURE__ */ new Set()
|
|
3256
|
+
};
|
|
3335
3257
|
constructor(root, siteId) {
|
|
3258
|
+
if (root.api.energySites.has(siteId)) throw new Error("Energy site already exists");
|
|
3259
|
+
super();
|
|
3336
3260
|
this.root = root;
|
|
3337
3261
|
this.siteId = siteId;
|
|
3262
|
+
root.api.energySites.set(siteId, this);
|
|
3338
3263
|
}
|
|
3339
3264
|
/**
|
|
3340
3265
|
* Adjust the site's backup reserve.
|
|
@@ -3396,6 +3321,7 @@ var TeslemetryEnergyApi = class {
|
|
|
3396
3321
|
path: { id: this.siteId },
|
|
3397
3322
|
client: this.root.client
|
|
3398
3323
|
});
|
|
3324
|
+
this.emit("liveStatus", data);
|
|
3399
3325
|
return data;
|
|
3400
3326
|
}
|
|
3401
3327
|
/**
|
|
@@ -3407,6 +3333,7 @@ var TeslemetryEnergyApi = class {
|
|
|
3407
3333
|
path: { id: this.siteId },
|
|
3408
3334
|
client: this.root.client
|
|
3409
3335
|
});
|
|
3336
|
+
this.emit("siteInfo", data);
|
|
3410
3337
|
return data;
|
|
3411
3338
|
}
|
|
3412
3339
|
/**
|
|
@@ -3468,6 +3395,34 @@ var TeslemetryEnergyApi = class {
|
|
|
3468
3395
|
});
|
|
3469
3396
|
return data;
|
|
3470
3397
|
}
|
|
3398
|
+
requestPolling(endpoint) {
|
|
3399
|
+
if (!this.refreshInterval[endpoint]) switch (endpoint) {
|
|
3400
|
+
case "siteInfo":
|
|
3401
|
+
this.refreshInterval[endpoint] = setInterval(() => {
|
|
3402
|
+
this.getSiteInfo();
|
|
3403
|
+
}, this.refreshDelay);
|
|
3404
|
+
this.getSiteInfo();
|
|
3405
|
+
break;
|
|
3406
|
+
case "liveStatus":
|
|
3407
|
+
this.refreshInterval[endpoint] = setInterval(() => {
|
|
3408
|
+
this.getLiveStatus();
|
|
3409
|
+
}, this.refreshDelay);
|
|
3410
|
+
this.getLiveStatus();
|
|
3411
|
+
break;
|
|
3412
|
+
default: throw new Error(`Invalid endpoint: ${endpoint}`);
|
|
3413
|
+
}
|
|
3414
|
+
const symbol = Symbol("refreshClient");
|
|
3415
|
+
this.refreshClients[endpoint].add(symbol);
|
|
3416
|
+
return () => {
|
|
3417
|
+
this.refreshClients[endpoint].delete(symbol);
|
|
3418
|
+
if (this.refreshClients[endpoint].size === 0) {
|
|
3419
|
+
if (this.refreshInterval[endpoint]) {
|
|
3420
|
+
clearInterval(this.refreshInterval[endpoint]);
|
|
3421
|
+
this.refreshInterval[endpoint] = null;
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
};
|
|
3425
|
+
}
|
|
3471
3426
|
};
|
|
3472
3427
|
|
|
3473
3428
|
//#endregion
|
|
@@ -3539,12 +3494,15 @@ const ALL_SEATS = {
|
|
|
3539
3494
|
7: 7,
|
|
3540
3495
|
8: 8
|
|
3541
3496
|
};
|
|
3542
|
-
var TeslemetryVehicleApi = class {
|
|
3497
|
+
var TeslemetryVehicleApi = class extends events.EventEmitter {
|
|
3543
3498
|
root;
|
|
3544
3499
|
vin;
|
|
3545
3500
|
constructor(root, vin) {
|
|
3501
|
+
if (root.api.vehicles.has(vin)) throw new Error("Vehicle already exists");
|
|
3502
|
+
super();
|
|
3546
3503
|
this.root = root;
|
|
3547
3504
|
this.vin = vin;
|
|
3505
|
+
root.api.vehicles.set(vin, this);
|
|
3548
3506
|
}
|
|
3549
3507
|
/**
|
|
3550
3508
|
* Data about the vehicle.
|
|
@@ -3555,6 +3513,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3555
3513
|
path: { vin: this.vin },
|
|
3556
3514
|
client: this.root.client
|
|
3557
3515
|
});
|
|
3516
|
+
this.emit("state", data);
|
|
3558
3517
|
return data;
|
|
3559
3518
|
}
|
|
3560
3519
|
/**
|
|
@@ -3572,6 +3531,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3572
3531
|
path: { vin: this.vin },
|
|
3573
3532
|
client: this.root.client
|
|
3574
3533
|
});
|
|
3534
|
+
this.emit("vehicleData", data);
|
|
3575
3535
|
return data;
|
|
3576
3536
|
}
|
|
3577
3537
|
/**
|
|
@@ -3586,17 +3546,6 @@ var TeslemetryVehicleApi = class {
|
|
|
3586
3546
|
return data;
|
|
3587
3547
|
}
|
|
3588
3548
|
/**
|
|
3589
|
-
* Redirect to the Tesla Design Studio image of a vehicle
|
|
3590
|
-
* @return Promise to an object with response containing redirect information
|
|
3591
|
-
*/
|
|
3592
|
-
async getImage() {
|
|
3593
|
-
const { data } = await getApiImageByVin({
|
|
3594
|
-
path: { vin: this.vin },
|
|
3595
|
-
client: this.root.client
|
|
3596
|
-
});
|
|
3597
|
-
return data;
|
|
3598
|
-
}
|
|
3599
|
-
/**
|
|
3600
3549
|
* Get the saved vehicle config.
|
|
3601
3550
|
* @return Promise to an object with response containing the vehicle configuration
|
|
3602
3551
|
*/
|
|
@@ -3605,6 +3554,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3605
3554
|
path: { vin: this.vin },
|
|
3606
3555
|
client: this.root.client
|
|
3607
3556
|
});
|
|
3557
|
+
this.emit("vehicleConfig", data);
|
|
3608
3558
|
return data;
|
|
3609
3559
|
}
|
|
3610
3560
|
/**
|
|
@@ -3616,6 +3566,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3616
3566
|
path: { vin: this.vin },
|
|
3617
3567
|
client: this.root.client
|
|
3618
3568
|
});
|
|
3569
|
+
this.emit("config", data);
|
|
3619
3570
|
return data;
|
|
3620
3571
|
}
|
|
3621
3572
|
/**
|
|
@@ -3664,6 +3615,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3664
3615
|
path: { vin: this.vin },
|
|
3665
3616
|
client: this.root.client
|
|
3666
3617
|
});
|
|
3618
|
+
this.emit("mobileEnabled", data);
|
|
3667
3619
|
return data;
|
|
3668
3620
|
}
|
|
3669
3621
|
/**
|
|
@@ -3675,6 +3627,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3675
3627
|
path: { vin: this.vin },
|
|
3676
3628
|
client: this.root.client
|
|
3677
3629
|
});
|
|
3630
|
+
this.emit("nearbyChargingSites", data);
|
|
3678
3631
|
return data;
|
|
3679
3632
|
}
|
|
3680
3633
|
/**
|
|
@@ -3686,6 +3639,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3686
3639
|
path: { vin: this.vin },
|
|
3687
3640
|
client: this.root.client
|
|
3688
3641
|
});
|
|
3642
|
+
this.emit("recentAlerts", data);
|
|
3689
3643
|
return data;
|
|
3690
3644
|
}
|
|
3691
3645
|
/**
|
|
@@ -3697,6 +3651,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3697
3651
|
path: { vin: this.vin },
|
|
3698
3652
|
client: this.root.client
|
|
3699
3653
|
});
|
|
3654
|
+
this.emit("releaseNotes", data);
|
|
3700
3655
|
return data;
|
|
3701
3656
|
}
|
|
3702
3657
|
/**
|
|
@@ -3708,6 +3663,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3708
3663
|
path: { vin: this.vin },
|
|
3709
3664
|
client: this.root.client
|
|
3710
3665
|
});
|
|
3666
|
+
this.emit("serviceData", data);
|
|
3711
3667
|
return data;
|
|
3712
3668
|
}
|
|
3713
3669
|
/**
|
|
@@ -3741,6 +3697,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3741
3697
|
path: { vin: this.vin },
|
|
3742
3698
|
client: this.root.client
|
|
3743
3699
|
});
|
|
3700
|
+
this.emit("fleetTelemetryConfig", data);
|
|
3744
3701
|
return data;
|
|
3745
3702
|
}
|
|
3746
3703
|
/**
|
|
@@ -3763,6 +3720,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3763
3720
|
path: { vin: this.vin },
|
|
3764
3721
|
client: this.root.client
|
|
3765
3722
|
});
|
|
3723
|
+
this.emit("fleetTelemetryErrors", data);
|
|
3766
3724
|
return data;
|
|
3767
3725
|
}
|
|
3768
3726
|
/**
|
|
@@ -4627,6 +4585,7 @@ var TeslemetryVehicleApi = class {
|
|
|
4627
4585
|
path: { vin: this.vin },
|
|
4628
4586
|
client: this.root.client
|
|
4629
4587
|
});
|
|
4588
|
+
this.emit("drivers", data);
|
|
4630
4589
|
return data;
|
|
4631
4590
|
}
|
|
4632
4591
|
/**
|
|
@@ -4651,6 +4610,7 @@ var TeslemetryVehicleApi = class {
|
|
|
4651
4610
|
path: { vin: this.vin },
|
|
4652
4611
|
client: this.root.client
|
|
4653
4612
|
});
|
|
4613
|
+
this.emit("invitations", data);
|
|
4654
4614
|
return data;
|
|
4655
4615
|
}
|
|
4656
4616
|
/**
|
|
@@ -4865,8 +4825,8 @@ var TeslemetryVehicleApi = class {
|
|
|
4865
4825
|
//#region src/TeslemetryApi.ts
|
|
4866
4826
|
var TeslemetryApi = class {
|
|
4867
4827
|
root;
|
|
4868
|
-
|
|
4869
|
-
|
|
4828
|
+
vehicles = /* @__PURE__ */ new Map();
|
|
4829
|
+
energySites = /* @__PURE__ */ new Map();
|
|
4870
4830
|
user;
|
|
4871
4831
|
charging;
|
|
4872
4832
|
constructor(root) {
|
|
@@ -4880,8 +4840,8 @@ var TeslemetryApi = class {
|
|
|
4880
4840
|
* @returns The vehicle API instance for the specified VIN.
|
|
4881
4841
|
*/
|
|
4882
4842
|
getVehicle(vin) {
|
|
4883
|
-
if (!this.
|
|
4884
|
-
return this.
|
|
4843
|
+
if (!this.vehicles.has(vin)) new TeslemetryVehicleApi(this.root, vin);
|
|
4844
|
+
return this.vehicles.get(vin);
|
|
4885
4845
|
}
|
|
4886
4846
|
/**
|
|
4887
4847
|
* Gets or creates an energy site API instance for the specified ID.
|
|
@@ -4889,8 +4849,8 @@ var TeslemetryApi = class {
|
|
|
4889
4849
|
* @returns The energy site API instance for the specified ID.
|
|
4890
4850
|
*/
|
|
4891
4851
|
getEnergySite(id) {
|
|
4892
|
-
if (!this.
|
|
4893
|
-
return this.
|
|
4852
|
+
if (!this.energySites.has(id)) new TeslemetryEnergyApi(this.root, id);
|
|
4853
|
+
return this.energySites.get(id);
|
|
4894
4854
|
}
|
|
4895
4855
|
/**
|
|
4896
4856
|
* Creates API instances for all products (vehicles and energy sites) associated with the account.
|
|
@@ -4903,11 +4863,11 @@ var TeslemetryApi = class {
|
|
|
4903
4863
|
if (product.device_type === "energy") this.getEnergySite(product.energy_site_id);
|
|
4904
4864
|
});
|
|
4905
4865
|
return {
|
|
4906
|
-
vehicles: this.
|
|
4907
|
-
energySites: this.
|
|
4866
|
+
vehicles: this.vehicles,
|
|
4867
|
+
energySites: this.energySites
|
|
4908
4868
|
};
|
|
4909
4869
|
}
|
|
4910
|
-
async
|
|
4870
|
+
async getFields() {
|
|
4911
4871
|
const { data } = await getFieldsJson({ client: this.root.client });
|
|
4912
4872
|
return data;
|
|
4913
4873
|
}
|
|
@@ -4916,7 +4876,7 @@ var TeslemetryApi = class {
|
|
|
4916
4876
|
* @returns A promise that resolves to an object containing a `response` array and count.
|
|
4917
4877
|
* Each item in the array is a product, which can be a vehicle or an energy site, and a `count` of the products.
|
|
4918
4878
|
*/
|
|
4919
|
-
async
|
|
4879
|
+
async getProducts() {
|
|
4920
4880
|
const { data } = await getApi1Products({ client: this.root.client });
|
|
4921
4881
|
return data;
|
|
4922
4882
|
}
|
|
@@ -4933,7 +4893,7 @@ var TeslemetryApi = class {
|
|
|
4933
4893
|
* @returns Promise to an object containing metadata about the account,
|
|
4934
4894
|
* including user UID, region, scopes, and lists of vehicles and energy sites.
|
|
4935
4895
|
*/
|
|
4936
|
-
async
|
|
4896
|
+
async getMetadata() {
|
|
4937
4897
|
const { data } = await getApiMetadata({ client: this.root.client });
|
|
4938
4898
|
return data;
|
|
4939
4899
|
}
|
|
@@ -4943,7 +4903,7 @@ var TeslemetryApi = class {
|
|
|
4943
4903
|
* @returns Promise to an object containing lists of paired and unpaired VINs,
|
|
4944
4904
|
* and detailed info for each vehicle.
|
|
4945
4905
|
*/
|
|
4946
|
-
async
|
|
4906
|
+
async getFleetStatus(vins) {
|
|
4947
4907
|
const { data } = await postApi1VehiclesFleetStatus({
|
|
4948
4908
|
body: { vins },
|
|
4949
4909
|
client: this.root.client
|
|
@@ -4955,7 +4915,7 @@ var TeslemetryApi = class {
|
|
|
4955
4915
|
* @returns Promise to an object containing a list of vehicles,
|
|
4956
4916
|
* pagination details, and a total count.
|
|
4957
4917
|
*/
|
|
4958
|
-
async
|
|
4918
|
+
async getVehicles() {
|
|
4959
4919
|
const { data } = await getApi1Vehicles({ client: this.root.client });
|
|
4960
4920
|
return data;
|
|
4961
4921
|
}
|
|
@@ -4984,7 +4944,7 @@ const consoleLogger = {
|
|
|
4984
4944
|
|
|
4985
4945
|
//#endregion
|
|
4986
4946
|
//#region package.json
|
|
4987
|
-
var version = "0.
|
|
4947
|
+
var version = "0.5.0";
|
|
4988
4948
|
|
|
4989
4949
|
//#endregion
|
|
4990
4950
|
//#region src/Teslemetry.ts
|
|
@@ -5045,27 +5005,25 @@ var Teslemetry = class {
|
|
|
5045
5005
|
* @returns A promise that resolves to an object containing vehicle and energy site names, API, and SSE instances.
|
|
5046
5006
|
*/
|
|
5047
5007
|
async createProducts() {
|
|
5048
|
-
const { data } = await
|
|
5049
|
-
|
|
5050
|
-
vehicles: {
|
|
5051
|
-
|
|
5008
|
+
const { data } = await getApiMetadata({ client: this.client });
|
|
5009
|
+
return {
|
|
5010
|
+
vehicles: Object.fromEntries(Object.entries(data.vehicles).map(([vin, metadata]) => [vin, {
|
|
5011
|
+
name: metadata.name ?? useTeslaModel(vin),
|
|
5012
|
+
vin,
|
|
5013
|
+
api: this.api.getVehicle(vin),
|
|
5014
|
+
sse: this.sse.getVehicle(vin),
|
|
5015
|
+
metadata
|
|
5016
|
+
}])),
|
|
5017
|
+
energySites: Object.fromEntries(Object.entries(data.energy_sites ?? {}).map(([id, metadata]) => {
|
|
5018
|
+
const siteId = Number(id);
|
|
5019
|
+
return [id, {
|
|
5020
|
+
name: metadata.name ?? "Unnamed",
|
|
5021
|
+
id: siteId,
|
|
5022
|
+
api: this.api.getEnergySite(siteId),
|
|
5023
|
+
metadata
|
|
5024
|
+
}];
|
|
5025
|
+
}))
|
|
5052
5026
|
};
|
|
5053
|
-
data.response?.forEach((product) => {
|
|
5054
|
-
if (product.device_type === "vehicle") result.vehicles[product.vin] = {
|
|
5055
|
-
name: product.display_name ?? useTeslaModel(product.vin),
|
|
5056
|
-
vin: product.vin,
|
|
5057
|
-
api: this.api.getVehicle(product.vin),
|
|
5058
|
-
sse: this.sse.getVehicle(product.vin),
|
|
5059
|
-
product
|
|
5060
|
-
};
|
|
5061
|
-
if (product.device_type === "energy") result.energySites[product.energy_site_id] = {
|
|
5062
|
-
name: product.site_name ?? "Unnamed",
|
|
5063
|
-
site: product.energy_site_id,
|
|
5064
|
-
api: this.api.getEnergySite(product.energy_site_id),
|
|
5065
|
-
product
|
|
5066
|
-
};
|
|
5067
|
-
});
|
|
5068
|
-
return result;
|
|
5069
5027
|
}
|
|
5070
5028
|
/**
|
|
5071
5029
|
* Get a vehicle API instance for the specified VIN.
|