@teslemetry/api 0.3.0 → 0.4.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 +102 -179
- package/dist/index.d.cts +7061 -4709
- package/dist/index.d.mts +7061 -4709
- package/dist/index.mjs +103 -179
- 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
3154
|
}
|
|
3181
|
-
|
|
3182
|
-
const
|
|
3183
|
-
|
|
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
|
-
}
|
|
3209
|
-
onConfig(callback, filters) {
|
|
3210
|
-
return this._createListener("config", callback, filters);
|
|
3211
|
-
}
|
|
3212
|
-
on(callback, filters) {
|
|
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,15 @@ 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;
|
|
3335
3248
|
constructor(root, siteId) {
|
|
3249
|
+
if (root.api.energySites.has(siteId)) throw new Error("Energy site already exists");
|
|
3250
|
+
super();
|
|
3336
3251
|
this.root = root;
|
|
3337
3252
|
this.siteId = siteId;
|
|
3253
|
+
root.api.energySites.set(siteId, this);
|
|
3338
3254
|
}
|
|
3339
3255
|
/**
|
|
3340
3256
|
* Adjust the site's backup reserve.
|
|
@@ -3396,6 +3312,7 @@ var TeslemetryEnergyApi = class {
|
|
|
3396
3312
|
path: { id: this.siteId },
|
|
3397
3313
|
client: this.root.client
|
|
3398
3314
|
});
|
|
3315
|
+
this.emit("liveStatus", data);
|
|
3399
3316
|
return data;
|
|
3400
3317
|
}
|
|
3401
3318
|
/**
|
|
@@ -3407,6 +3324,7 @@ var TeslemetryEnergyApi = class {
|
|
|
3407
3324
|
path: { id: this.siteId },
|
|
3408
3325
|
client: this.root.client
|
|
3409
3326
|
});
|
|
3327
|
+
this.emit("siteInfo", data);
|
|
3410
3328
|
return data;
|
|
3411
3329
|
}
|
|
3412
3330
|
/**
|
|
@@ -3539,12 +3457,15 @@ const ALL_SEATS = {
|
|
|
3539
3457
|
7: 7,
|
|
3540
3458
|
8: 8
|
|
3541
3459
|
};
|
|
3542
|
-
var TeslemetryVehicleApi = class {
|
|
3460
|
+
var TeslemetryVehicleApi = class extends events.EventEmitter {
|
|
3543
3461
|
root;
|
|
3544
3462
|
vin;
|
|
3545
3463
|
constructor(root, vin) {
|
|
3464
|
+
if (root.api.vehicles.has(vin)) throw new Error("Vehicle already exists");
|
|
3465
|
+
super();
|
|
3546
3466
|
this.root = root;
|
|
3547
3467
|
this.vin = vin;
|
|
3468
|
+
root.api.vehicles.set(vin, this);
|
|
3548
3469
|
}
|
|
3549
3470
|
/**
|
|
3550
3471
|
* Data about the vehicle.
|
|
@@ -3555,6 +3476,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3555
3476
|
path: { vin: this.vin },
|
|
3556
3477
|
client: this.root.client
|
|
3557
3478
|
});
|
|
3479
|
+
this.emit("state", data);
|
|
3558
3480
|
return data;
|
|
3559
3481
|
}
|
|
3560
3482
|
/**
|
|
@@ -3572,6 +3494,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3572
3494
|
path: { vin: this.vin },
|
|
3573
3495
|
client: this.root.client
|
|
3574
3496
|
});
|
|
3497
|
+
this.emit("vehicleData", data);
|
|
3575
3498
|
return data;
|
|
3576
3499
|
}
|
|
3577
3500
|
/**
|
|
@@ -3586,17 +3509,6 @@ var TeslemetryVehicleApi = class {
|
|
|
3586
3509
|
return data;
|
|
3587
3510
|
}
|
|
3588
3511
|
/**
|
|
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
3512
|
* Get the saved vehicle config.
|
|
3601
3513
|
* @return Promise to an object with response containing the vehicle configuration
|
|
3602
3514
|
*/
|
|
@@ -3605,6 +3517,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3605
3517
|
path: { vin: this.vin },
|
|
3606
3518
|
client: this.root.client
|
|
3607
3519
|
});
|
|
3520
|
+
this.emit("vehicleConfig", data);
|
|
3608
3521
|
return data;
|
|
3609
3522
|
}
|
|
3610
3523
|
/**
|
|
@@ -3616,6 +3529,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3616
3529
|
path: { vin: this.vin },
|
|
3617
3530
|
client: this.root.client
|
|
3618
3531
|
});
|
|
3532
|
+
this.emit("config", data);
|
|
3619
3533
|
return data;
|
|
3620
3534
|
}
|
|
3621
3535
|
/**
|
|
@@ -3664,6 +3578,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3664
3578
|
path: { vin: this.vin },
|
|
3665
3579
|
client: this.root.client
|
|
3666
3580
|
});
|
|
3581
|
+
this.emit("mobileEnabled", data);
|
|
3667
3582
|
return data;
|
|
3668
3583
|
}
|
|
3669
3584
|
/**
|
|
@@ -3675,6 +3590,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3675
3590
|
path: { vin: this.vin },
|
|
3676
3591
|
client: this.root.client
|
|
3677
3592
|
});
|
|
3593
|
+
this.emit("nearbyChargingSites", data);
|
|
3678
3594
|
return data;
|
|
3679
3595
|
}
|
|
3680
3596
|
/**
|
|
@@ -3686,6 +3602,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3686
3602
|
path: { vin: this.vin },
|
|
3687
3603
|
client: this.root.client
|
|
3688
3604
|
});
|
|
3605
|
+
this.emit("recentAlerts", data);
|
|
3689
3606
|
return data;
|
|
3690
3607
|
}
|
|
3691
3608
|
/**
|
|
@@ -3697,6 +3614,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3697
3614
|
path: { vin: this.vin },
|
|
3698
3615
|
client: this.root.client
|
|
3699
3616
|
});
|
|
3617
|
+
this.emit("releaseNotes", data);
|
|
3700
3618
|
return data;
|
|
3701
3619
|
}
|
|
3702
3620
|
/**
|
|
@@ -3708,6 +3626,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3708
3626
|
path: { vin: this.vin },
|
|
3709
3627
|
client: this.root.client
|
|
3710
3628
|
});
|
|
3629
|
+
this.emit("serviceData", data);
|
|
3711
3630
|
return data;
|
|
3712
3631
|
}
|
|
3713
3632
|
/**
|
|
@@ -3741,6 +3660,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3741
3660
|
path: { vin: this.vin },
|
|
3742
3661
|
client: this.root.client
|
|
3743
3662
|
});
|
|
3663
|
+
this.emit("fleetTelemetryConfig", data);
|
|
3744
3664
|
return data;
|
|
3745
3665
|
}
|
|
3746
3666
|
/**
|
|
@@ -3763,6 +3683,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3763
3683
|
path: { vin: this.vin },
|
|
3764
3684
|
client: this.root.client
|
|
3765
3685
|
});
|
|
3686
|
+
this.emit("fleetTelemetryErrors", data);
|
|
3766
3687
|
return data;
|
|
3767
3688
|
}
|
|
3768
3689
|
/**
|
|
@@ -4627,6 +4548,7 @@ var TeslemetryVehicleApi = class {
|
|
|
4627
4548
|
path: { vin: this.vin },
|
|
4628
4549
|
client: this.root.client
|
|
4629
4550
|
});
|
|
4551
|
+
this.emit("drivers", data);
|
|
4630
4552
|
return data;
|
|
4631
4553
|
}
|
|
4632
4554
|
/**
|
|
@@ -4651,6 +4573,7 @@ var TeslemetryVehicleApi = class {
|
|
|
4651
4573
|
path: { vin: this.vin },
|
|
4652
4574
|
client: this.root.client
|
|
4653
4575
|
});
|
|
4576
|
+
this.emit("invitations", data);
|
|
4654
4577
|
return data;
|
|
4655
4578
|
}
|
|
4656
4579
|
/**
|
|
@@ -4865,8 +4788,8 @@ var TeslemetryVehicleApi = class {
|
|
|
4865
4788
|
//#region src/TeslemetryApi.ts
|
|
4866
4789
|
var TeslemetryApi = class {
|
|
4867
4790
|
root;
|
|
4868
|
-
|
|
4869
|
-
|
|
4791
|
+
vehicles = /* @__PURE__ */ new Map();
|
|
4792
|
+
energySites = /* @__PURE__ */ new Map();
|
|
4870
4793
|
user;
|
|
4871
4794
|
charging;
|
|
4872
4795
|
constructor(root) {
|
|
@@ -4880,8 +4803,8 @@ var TeslemetryApi = class {
|
|
|
4880
4803
|
* @returns The vehicle API instance for the specified VIN.
|
|
4881
4804
|
*/
|
|
4882
4805
|
getVehicle(vin) {
|
|
4883
|
-
if (!this.
|
|
4884
|
-
return this.
|
|
4806
|
+
if (!this.vehicles.has(vin)) new TeslemetryVehicleApi(this.root, vin);
|
|
4807
|
+
return this.vehicles.get(vin);
|
|
4885
4808
|
}
|
|
4886
4809
|
/**
|
|
4887
4810
|
* Gets or creates an energy site API instance for the specified ID.
|
|
@@ -4889,8 +4812,8 @@ var TeslemetryApi = class {
|
|
|
4889
4812
|
* @returns The energy site API instance for the specified ID.
|
|
4890
4813
|
*/
|
|
4891
4814
|
getEnergySite(id) {
|
|
4892
|
-
if (!this.
|
|
4893
|
-
return this.
|
|
4815
|
+
if (!this.energySites.has(id)) new TeslemetryEnergyApi(this.root, id);
|
|
4816
|
+
return this.energySites.get(id);
|
|
4894
4817
|
}
|
|
4895
4818
|
/**
|
|
4896
4819
|
* Creates API instances for all products (vehicles and energy sites) associated with the account.
|
|
@@ -4903,11 +4826,11 @@ var TeslemetryApi = class {
|
|
|
4903
4826
|
if (product.device_type === "energy") this.getEnergySite(product.energy_site_id);
|
|
4904
4827
|
});
|
|
4905
4828
|
return {
|
|
4906
|
-
vehicles: this.
|
|
4907
|
-
energySites: this.
|
|
4829
|
+
vehicles: this.vehicles,
|
|
4830
|
+
energySites: this.energySites
|
|
4908
4831
|
};
|
|
4909
4832
|
}
|
|
4910
|
-
async
|
|
4833
|
+
async getFields() {
|
|
4911
4834
|
const { data } = await getFieldsJson({ client: this.root.client });
|
|
4912
4835
|
return data;
|
|
4913
4836
|
}
|
|
@@ -4916,7 +4839,7 @@ var TeslemetryApi = class {
|
|
|
4916
4839
|
* @returns A promise that resolves to an object containing a `response` array and count.
|
|
4917
4840
|
* Each item in the array is a product, which can be a vehicle or an energy site, and a `count` of the products.
|
|
4918
4841
|
*/
|
|
4919
|
-
async
|
|
4842
|
+
async getProducts() {
|
|
4920
4843
|
const { data } = await getApi1Products({ client: this.root.client });
|
|
4921
4844
|
return data;
|
|
4922
4845
|
}
|
|
@@ -4933,7 +4856,7 @@ var TeslemetryApi = class {
|
|
|
4933
4856
|
* @returns Promise to an object containing metadata about the account,
|
|
4934
4857
|
* including user UID, region, scopes, and lists of vehicles and energy sites.
|
|
4935
4858
|
*/
|
|
4936
|
-
async
|
|
4859
|
+
async getMetadata() {
|
|
4937
4860
|
const { data } = await getApiMetadata({ client: this.root.client });
|
|
4938
4861
|
return data;
|
|
4939
4862
|
}
|
|
@@ -4943,7 +4866,7 @@ var TeslemetryApi = class {
|
|
|
4943
4866
|
* @returns Promise to an object containing lists of paired and unpaired VINs,
|
|
4944
4867
|
* and detailed info for each vehicle.
|
|
4945
4868
|
*/
|
|
4946
|
-
async
|
|
4869
|
+
async getFleetStatus(vins) {
|
|
4947
4870
|
const { data } = await postApi1VehiclesFleetStatus({
|
|
4948
4871
|
body: { vins },
|
|
4949
4872
|
client: this.root.client
|
|
@@ -4955,7 +4878,7 @@ var TeslemetryApi = class {
|
|
|
4955
4878
|
* @returns Promise to an object containing a list of vehicles,
|
|
4956
4879
|
* pagination details, and a total count.
|
|
4957
4880
|
*/
|
|
4958
|
-
async
|
|
4881
|
+
async getVehicles() {
|
|
4959
4882
|
const { data } = await getApi1Vehicles({ client: this.root.client });
|
|
4960
4883
|
return data;
|
|
4961
4884
|
}
|
|
@@ -4984,7 +4907,7 @@ const consoleLogger = {
|
|
|
4984
4907
|
|
|
4985
4908
|
//#endregion
|
|
4986
4909
|
//#region package.json
|
|
4987
|
-
var version = "0.
|
|
4910
|
+
var version = "0.4.0";
|
|
4988
4911
|
|
|
4989
4912
|
//#endregion
|
|
4990
4913
|
//#region src/Teslemetry.ts
|