@teslemetry/api 0.2.2 → 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 +7062 -4710
- package/dist/index.d.mts +7062 -4710
- package/dist/index.mjs +103 -179
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
|
|
1
3
|
//#region src/client/core/bodySerializer.gen.ts
|
|
2
4
|
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
3
5
|
|
|
@@ -790,23 +792,6 @@ const getApiRefreshByVin = (options) => (options.client ?? client).get({
|
|
|
790
792
|
...options
|
|
791
793
|
});
|
|
792
794
|
/**
|
|
793
|
-
* Vehicle Image
|
|
794
|
-
*
|
|
795
|
-
* Redirect to the Tesla Design Studio image of a vehicle
|
|
796
|
-
*/
|
|
797
|
-
const getApiImageByVin = (options) => (options.client ?? client).get({
|
|
798
|
-
security: [{
|
|
799
|
-
scheme: "bearer",
|
|
800
|
-
type: "http"
|
|
801
|
-
}, {
|
|
802
|
-
in: "query",
|
|
803
|
-
name: "token",
|
|
804
|
-
type: "apiKey"
|
|
805
|
-
}],
|
|
806
|
-
url: "/api/image/{vin}",
|
|
807
|
-
...options
|
|
808
|
-
});
|
|
809
|
-
/**
|
|
810
795
|
* Vehicle Data
|
|
811
796
|
*
|
|
812
797
|
* Returns the cached vehicle data for this vehicle. location_data will only be present if you have provided the location_data scope.
|
|
@@ -3004,23 +2989,27 @@ const getSseByVin_ = (options) => (options.client ?? client).sse.get({
|
|
|
3004
2989
|
|
|
3005
2990
|
//#endregion
|
|
3006
2991
|
//#region src/TeslemetryVehicleStream.ts
|
|
3007
|
-
var TeslemetryVehicleStream = class {
|
|
2992
|
+
var TeslemetryVehicleStream = class extends EventEmitter {
|
|
3008
2993
|
root;
|
|
3009
|
-
stream;
|
|
3010
2994
|
vin;
|
|
3011
2995
|
fields = {};
|
|
3012
2996
|
_pendingFields = {};
|
|
3013
2997
|
_debounceTimeout = null;
|
|
3014
2998
|
logger;
|
|
3015
|
-
|
|
2999
|
+
data;
|
|
3000
|
+
constructor(root, vin) {
|
|
3001
|
+
if (root.sse.vehicles.has(vin)) throw new Error("Vehicle already exists");
|
|
3002
|
+
super();
|
|
3016
3003
|
this.root = root;
|
|
3017
|
-
this.stream = stream;
|
|
3018
3004
|
this.vin = vin;
|
|
3019
|
-
this.logger =
|
|
3020
|
-
|
|
3005
|
+
this.logger = root.sse.logger;
|
|
3006
|
+
this.data = new EventEmitter();
|
|
3007
|
+
root.sse.vehicles.set(vin, this);
|
|
3008
|
+
this.on("config", (event) => {
|
|
3021
3009
|
this.fields = event.config.fields;
|
|
3022
|
-
}
|
|
3010
|
+
});
|
|
3023
3011
|
}
|
|
3012
|
+
/** Get the current configuration for the vehicle */
|
|
3024
3013
|
async getConfig() {
|
|
3025
3014
|
const { data, response } = await getApiConfigByVin({ path: { vin: this.vin } });
|
|
3026
3015
|
if (response.status === 200 && data) this.fields = data.fields || {};
|
|
@@ -3029,7 +3018,8 @@ var TeslemetryVehicleStream = class {
|
|
|
3029
3018
|
return;
|
|
3030
3019
|
} else throw new Error(`Failed to get config: ${response.statusText}`);
|
|
3031
3020
|
}
|
|
3032
|
-
|
|
3021
|
+
/** Safely add field configuration to the vehicle */
|
|
3022
|
+
async updateFields(fields) {
|
|
3033
3023
|
this._pendingFields = {
|
|
3034
3024
|
...this._pendingFields,
|
|
3035
3025
|
...fields
|
|
@@ -3048,6 +3038,7 @@ var TeslemetryVehicleStream = class {
|
|
|
3048
3038
|
this._debounceTimeout = null;
|
|
3049
3039
|
}, 100);
|
|
3050
3040
|
}
|
|
3041
|
+
/** Modify the field configuration of the vehicle */
|
|
3051
3042
|
async patchConfig(fields) {
|
|
3052
3043
|
const { data } = await patchApiConfigByVin({
|
|
3053
3044
|
client: this.root.client,
|
|
@@ -3056,6 +3047,7 @@ var TeslemetryVehicleStream = class {
|
|
|
3056
3047
|
});
|
|
3057
3048
|
return data;
|
|
3058
3049
|
}
|
|
3050
|
+
/** Replace the field configuration of the vehicle */
|
|
3059
3051
|
async postConfig(fields) {
|
|
3060
3052
|
const { data } = await postApiConfigByVin({
|
|
3061
3053
|
client: this.root.client,
|
|
@@ -3064,6 +3056,12 @@ var TeslemetryVehicleStream = class {
|
|
|
3064
3056
|
});
|
|
3065
3057
|
return data;
|
|
3066
3058
|
}
|
|
3059
|
+
/**
|
|
3060
|
+
* Add a field to the vehicles streaming configuration
|
|
3061
|
+
* @param field Vehicle Signal
|
|
3062
|
+
* @param interval
|
|
3063
|
+
* @returns
|
|
3064
|
+
*/
|
|
3067
3065
|
async addField(field, interval) {
|
|
3068
3066
|
if (this.fields && this.fields[field] && (interval === void 0 || this.fields[field].interval_seconds === interval)) {
|
|
3069
3067
|
this.logger.debug(`Streaming field ${field} already enabled @ ${this.fields[field]?.interval_seconds || "default"}s`);
|
|
@@ -3072,59 +3070,37 @@ var TeslemetryVehicleStream = class {
|
|
|
3072
3070
|
const value = interval !== void 0 ? { interval_seconds: interval } : null;
|
|
3073
3071
|
this.updateFields({ [field]: value });
|
|
3074
3072
|
}
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
onErrors(callback) {
|
|
3082
|
-
return this.stream.onErrors(callback, { vin: this.vin });
|
|
3083
|
-
}
|
|
3084
|
-
onAlerts(callback) {
|
|
3085
|
-
return this.stream.onAlerts(callback, { vin: this.vin });
|
|
3086
|
-
}
|
|
3087
|
-
onConnectivity(callback) {
|
|
3088
|
-
return this.stream.onConnectivity(callback, { vin: this.vin });
|
|
3089
|
-
}
|
|
3090
|
-
onVehicleData(callback) {
|
|
3091
|
-
return this.stream.onVehicleData(callback, { vin: this.vin });
|
|
3092
|
-
}
|
|
3093
|
-
onConfig(callback) {
|
|
3094
|
-
return this.stream.onConfig(callback, { vin: this.vin });
|
|
3095
|
-
}
|
|
3096
|
-
on(callback) {
|
|
3097
|
-
return this.stream.on((event) => {
|
|
3098
|
-
callback(event);
|
|
3099
|
-
}, { vin: this.vin });
|
|
3100
|
-
}
|
|
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
|
+
*/
|
|
3101
3079
|
onSignal(field, callback) {
|
|
3102
3080
|
this.addField(field).catch((error) => {
|
|
3103
3081
|
this.logger.error(`Failed to add field ${field}:`, error);
|
|
3104
3082
|
});
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
});
|
|
3083
|
+
this.data.on(field, callback);
|
|
3084
|
+
return () => this.data.off(field, callback);
|
|
3085
|
+
}
|
|
3086
|
+
stop() {
|
|
3087
|
+
this.removeAllListeners();
|
|
3088
|
+
this.data.removeAllListeners();
|
|
3112
3089
|
}
|
|
3113
3090
|
};
|
|
3114
3091
|
|
|
3115
3092
|
//#endregion
|
|
3116
3093
|
//#region src/TeslemetryStream.ts
|
|
3117
|
-
var TeslemetryStream = class {
|
|
3094
|
+
var TeslemetryStream = class extends EventEmitter {
|
|
3118
3095
|
root;
|
|
3119
3096
|
active = false;
|
|
3120
3097
|
connected = false;
|
|
3121
3098
|
vin;
|
|
3122
3099
|
cache;
|
|
3123
3100
|
logger;
|
|
3124
|
-
listeners = /* @__PURE__ */ new Map();
|
|
3125
|
-
_connectionListeners = /* @__PURE__ */ new Map();
|
|
3126
3101
|
vehicles = /* @__PURE__ */ new Map();
|
|
3127
3102
|
constructor(root, options) {
|
|
3103
|
+
super();
|
|
3128
3104
|
this.root = root;
|
|
3129
3105
|
this.vin = options?.vin;
|
|
3130
3106
|
this.cache = options?.cache;
|
|
@@ -3132,7 +3108,7 @@ var TeslemetryStream = class {
|
|
|
3132
3108
|
if (this.vin) this.getVehicle(this.vin);
|
|
3133
3109
|
}
|
|
3134
3110
|
getVehicle(vin) {
|
|
3135
|
-
if (!this.vehicles.has(vin))
|
|
3111
|
+
if (!this.vehicles.has(vin)) new TeslemetryVehicleStream(this.root, vin);
|
|
3136
3112
|
return this.vehicles.get(vin);
|
|
3137
3113
|
}
|
|
3138
3114
|
async connect() {
|
|
@@ -3151,7 +3127,7 @@ var TeslemetryStream = class {
|
|
|
3151
3127
|
this.logger.info(`Connected to stream`);
|
|
3152
3128
|
retries = 0;
|
|
3153
3129
|
this.connected = true;
|
|
3154
|
-
this.
|
|
3130
|
+
this.emit("connect");
|
|
3155
3131
|
if (sse.stream) for await (const event of sse.stream) {
|
|
3156
3132
|
if (!this.active) break;
|
|
3157
3133
|
this._dispatch(event);
|
|
@@ -3160,13 +3136,13 @@ var TeslemetryStream = class {
|
|
|
3160
3136
|
if (!this.active) break;
|
|
3161
3137
|
this.logger.error("SSE error:", error);
|
|
3162
3138
|
this.connected = false;
|
|
3163
|
-
this.
|
|
3139
|
+
this.emit("disconnect");
|
|
3164
3140
|
retries++;
|
|
3165
3141
|
const delay = Math.min(2 ** retries, 600) * 1e3;
|
|
3166
3142
|
this.logger.info(`Reconnecting in ${delay / 1e3} seconds...`);
|
|
3167
3143
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
3168
3144
|
}
|
|
3169
|
-
this.
|
|
3145
|
+
this.emit("disconnect");
|
|
3170
3146
|
}
|
|
3171
3147
|
disconnect() {
|
|
3172
3148
|
this.active = false;
|
|
@@ -3175,99 +3151,37 @@ var TeslemetryStream = class {
|
|
|
3175
3151
|
close() {
|
|
3176
3152
|
this.active = false;
|
|
3177
3153
|
this.logger.info(`Disconnecting from stream`);
|
|
3178
|
-
this._updateConnectionListeners(false);
|
|
3179
3154
|
}
|
|
3180
|
-
|
|
3181
|
-
const
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
this._connectionListeners.set(removeListener, callback);
|
|
3185
|
-
return removeListener;
|
|
3186
|
-
}
|
|
3187
|
-
onState(callback, filters) {
|
|
3188
|
-
return this._createListener("state", callback, filters);
|
|
3189
|
-
}
|
|
3190
|
-
onData(callback, filters) {
|
|
3191
|
-
return this._createListener("data", callback, filters);
|
|
3192
|
-
}
|
|
3193
|
-
onErrors(callback, filters) {
|
|
3194
|
-
return this._createListener("errors", callback, filters);
|
|
3195
|
-
}
|
|
3196
|
-
onAlerts(callback, filters) {
|
|
3197
|
-
return this._createListener("alerts", callback, filters);
|
|
3198
|
-
}
|
|
3199
|
-
onConnectivity(callback, filters) {
|
|
3200
|
-
return this._createListener("connectivity", callback, filters);
|
|
3201
|
-
}
|
|
3202
|
-
onCredits(callback, filters) {
|
|
3203
|
-
return this._createListener("credits", callback, filters);
|
|
3204
|
-
}
|
|
3205
|
-
onVehicleData(callback, filters) {
|
|
3206
|
-
return this._createListener("vehicle_data", callback, filters);
|
|
3207
|
-
}
|
|
3208
|
-
onConfig(callback, filters) {
|
|
3209
|
-
return this._createListener("config", callback, filters);
|
|
3210
|
-
}
|
|
3211
|
-
on(callback, filters) {
|
|
3212
|
-
return this._createListener("all", callback, filters);
|
|
3213
|
-
}
|
|
3214
|
-
_updateConnectionListeners(value) {
|
|
3215
|
-
for (const listener of this._connectionListeners.values()) listener(value);
|
|
3216
|
-
}
|
|
3217
|
-
_createListener(eventType, callback, filters) {
|
|
3218
|
-
const entry = {
|
|
3219
|
-
callback,
|
|
3220
|
-
filters
|
|
3221
|
-
};
|
|
3222
|
-
if (!this.listeners.has(eventType)) this.listeners.set(eventType, /* @__PURE__ */ new Set());
|
|
3223
|
-
this.listeners.get(eventType).add(entry);
|
|
3224
|
-
return () => {
|
|
3225
|
-
const set = this.listeners.get(eventType);
|
|
3226
|
-
if (set) {
|
|
3227
|
-
set.delete(entry);
|
|
3228
|
-
if (set.size === 0) this.listeners.delete(eventType);
|
|
3229
|
-
}
|
|
3230
|
-
};
|
|
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)));
|
|
3231
3159
|
}
|
|
3232
3160
|
_dispatch(event) {
|
|
3233
|
-
if (event.
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
if (
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
if (
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
if (
|
|
3253
|
-
|
|
3254
|
-
}
|
|
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);
|
|
3255
3182
|
}
|
|
3256
3183
|
}
|
|
3257
3184
|
};
|
|
3258
|
-
function recursiveMatch(filter, event) {
|
|
3259
|
-
if (filter === null || filter === void 0) return true;
|
|
3260
|
-
if (typeof filter !== "object" || filter === null || typeof event !== "object" || event === null) return filter === event;
|
|
3261
|
-
if (Array.isArray(filter)) {
|
|
3262
|
-
if (!Array.isArray(event)) return false;
|
|
3263
|
-
return filter.some((fItem) => event.some((eItem) => recursiveMatch(fItem, eItem)));
|
|
3264
|
-
}
|
|
3265
|
-
for (const key in filter) {
|
|
3266
|
-
if (!(key in event)) return false;
|
|
3267
|
-
if (!recursiveMatch(filter[key], event[key])) return false;
|
|
3268
|
-
}
|
|
3269
|
-
return true;
|
|
3270
|
-
}
|
|
3271
3185
|
|
|
3272
3186
|
//#endregion
|
|
3273
3187
|
//#region src/TeslemetryChargingApi.ts
|
|
@@ -3328,12 +3242,15 @@ var TeslemetryChargingApi = class {
|
|
|
3328
3242
|
|
|
3329
3243
|
//#endregion
|
|
3330
3244
|
//#region src/TeslemetryEnergyApi.ts
|
|
3331
|
-
var TeslemetryEnergyApi = class {
|
|
3245
|
+
var TeslemetryEnergyApi = class extends EventEmitter {
|
|
3332
3246
|
root;
|
|
3333
3247
|
siteId;
|
|
3334
3248
|
constructor(root, siteId) {
|
|
3249
|
+
if (root.api.energySites.has(siteId)) throw new Error("Energy site already exists");
|
|
3250
|
+
super();
|
|
3335
3251
|
this.root = root;
|
|
3336
3252
|
this.siteId = siteId;
|
|
3253
|
+
root.api.energySites.set(siteId, this);
|
|
3337
3254
|
}
|
|
3338
3255
|
/**
|
|
3339
3256
|
* Adjust the site's backup reserve.
|
|
@@ -3395,6 +3312,7 @@ var TeslemetryEnergyApi = class {
|
|
|
3395
3312
|
path: { id: this.siteId },
|
|
3396
3313
|
client: this.root.client
|
|
3397
3314
|
});
|
|
3315
|
+
this.emit("liveStatus", data);
|
|
3398
3316
|
return data;
|
|
3399
3317
|
}
|
|
3400
3318
|
/**
|
|
@@ -3406,6 +3324,7 @@ var TeslemetryEnergyApi = class {
|
|
|
3406
3324
|
path: { id: this.siteId },
|
|
3407
3325
|
client: this.root.client
|
|
3408
3326
|
});
|
|
3327
|
+
this.emit("siteInfo", data);
|
|
3409
3328
|
return data;
|
|
3410
3329
|
}
|
|
3411
3330
|
/**
|
|
@@ -3538,12 +3457,15 @@ const ALL_SEATS = {
|
|
|
3538
3457
|
7: 7,
|
|
3539
3458
|
8: 8
|
|
3540
3459
|
};
|
|
3541
|
-
var TeslemetryVehicleApi = class {
|
|
3460
|
+
var TeslemetryVehicleApi = class extends EventEmitter {
|
|
3542
3461
|
root;
|
|
3543
3462
|
vin;
|
|
3544
3463
|
constructor(root, vin) {
|
|
3464
|
+
if (root.api.vehicles.has(vin)) throw new Error("Vehicle already exists");
|
|
3465
|
+
super();
|
|
3545
3466
|
this.root = root;
|
|
3546
3467
|
this.vin = vin;
|
|
3468
|
+
root.api.vehicles.set(vin, this);
|
|
3547
3469
|
}
|
|
3548
3470
|
/**
|
|
3549
3471
|
* Data about the vehicle.
|
|
@@ -3554,6 +3476,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3554
3476
|
path: { vin: this.vin },
|
|
3555
3477
|
client: this.root.client
|
|
3556
3478
|
});
|
|
3479
|
+
this.emit("state", data);
|
|
3557
3480
|
return data;
|
|
3558
3481
|
}
|
|
3559
3482
|
/**
|
|
@@ -3571,6 +3494,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3571
3494
|
path: { vin: this.vin },
|
|
3572
3495
|
client: this.root.client
|
|
3573
3496
|
});
|
|
3497
|
+
this.emit("vehicleData", data);
|
|
3574
3498
|
return data;
|
|
3575
3499
|
}
|
|
3576
3500
|
/**
|
|
@@ -3585,17 +3509,6 @@ var TeslemetryVehicleApi = class {
|
|
|
3585
3509
|
return data;
|
|
3586
3510
|
}
|
|
3587
3511
|
/**
|
|
3588
|
-
* Redirect to the Tesla Design Studio image of a vehicle
|
|
3589
|
-
* @return Promise to an object with response containing redirect information
|
|
3590
|
-
*/
|
|
3591
|
-
async getImage() {
|
|
3592
|
-
const { data } = await getApiImageByVin({
|
|
3593
|
-
path: { vin: this.vin },
|
|
3594
|
-
client: this.root.client
|
|
3595
|
-
});
|
|
3596
|
-
return data;
|
|
3597
|
-
}
|
|
3598
|
-
/**
|
|
3599
3512
|
* Get the saved vehicle config.
|
|
3600
3513
|
* @return Promise to an object with response containing the vehicle configuration
|
|
3601
3514
|
*/
|
|
@@ -3604,6 +3517,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3604
3517
|
path: { vin: this.vin },
|
|
3605
3518
|
client: this.root.client
|
|
3606
3519
|
});
|
|
3520
|
+
this.emit("vehicleConfig", data);
|
|
3607
3521
|
return data;
|
|
3608
3522
|
}
|
|
3609
3523
|
/**
|
|
@@ -3615,6 +3529,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3615
3529
|
path: { vin: this.vin },
|
|
3616
3530
|
client: this.root.client
|
|
3617
3531
|
});
|
|
3532
|
+
this.emit("config", data);
|
|
3618
3533
|
return data;
|
|
3619
3534
|
}
|
|
3620
3535
|
/**
|
|
@@ -3663,6 +3578,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3663
3578
|
path: { vin: this.vin },
|
|
3664
3579
|
client: this.root.client
|
|
3665
3580
|
});
|
|
3581
|
+
this.emit("mobileEnabled", data);
|
|
3666
3582
|
return data;
|
|
3667
3583
|
}
|
|
3668
3584
|
/**
|
|
@@ -3674,6 +3590,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3674
3590
|
path: { vin: this.vin },
|
|
3675
3591
|
client: this.root.client
|
|
3676
3592
|
});
|
|
3593
|
+
this.emit("nearbyChargingSites", data);
|
|
3677
3594
|
return data;
|
|
3678
3595
|
}
|
|
3679
3596
|
/**
|
|
@@ -3685,6 +3602,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3685
3602
|
path: { vin: this.vin },
|
|
3686
3603
|
client: this.root.client
|
|
3687
3604
|
});
|
|
3605
|
+
this.emit("recentAlerts", data);
|
|
3688
3606
|
return data;
|
|
3689
3607
|
}
|
|
3690
3608
|
/**
|
|
@@ -3696,6 +3614,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3696
3614
|
path: { vin: this.vin },
|
|
3697
3615
|
client: this.root.client
|
|
3698
3616
|
});
|
|
3617
|
+
this.emit("releaseNotes", data);
|
|
3699
3618
|
return data;
|
|
3700
3619
|
}
|
|
3701
3620
|
/**
|
|
@@ -3707,6 +3626,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3707
3626
|
path: { vin: this.vin },
|
|
3708
3627
|
client: this.root.client
|
|
3709
3628
|
});
|
|
3629
|
+
this.emit("serviceData", data);
|
|
3710
3630
|
return data;
|
|
3711
3631
|
}
|
|
3712
3632
|
/**
|
|
@@ -3740,6 +3660,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3740
3660
|
path: { vin: this.vin },
|
|
3741
3661
|
client: this.root.client
|
|
3742
3662
|
});
|
|
3663
|
+
this.emit("fleetTelemetryConfig", data);
|
|
3743
3664
|
return data;
|
|
3744
3665
|
}
|
|
3745
3666
|
/**
|
|
@@ -3762,6 +3683,7 @@ var TeslemetryVehicleApi = class {
|
|
|
3762
3683
|
path: { vin: this.vin },
|
|
3763
3684
|
client: this.root.client
|
|
3764
3685
|
});
|
|
3686
|
+
this.emit("fleetTelemetryErrors", data);
|
|
3765
3687
|
return data;
|
|
3766
3688
|
}
|
|
3767
3689
|
/**
|
|
@@ -4626,6 +4548,7 @@ var TeslemetryVehicleApi = class {
|
|
|
4626
4548
|
path: { vin: this.vin },
|
|
4627
4549
|
client: this.root.client
|
|
4628
4550
|
});
|
|
4551
|
+
this.emit("drivers", data);
|
|
4629
4552
|
return data;
|
|
4630
4553
|
}
|
|
4631
4554
|
/**
|
|
@@ -4650,6 +4573,7 @@ var TeslemetryVehicleApi = class {
|
|
|
4650
4573
|
path: { vin: this.vin },
|
|
4651
4574
|
client: this.root.client
|
|
4652
4575
|
});
|
|
4576
|
+
this.emit("invitations", data);
|
|
4653
4577
|
return data;
|
|
4654
4578
|
}
|
|
4655
4579
|
/**
|
|
@@ -4864,8 +4788,8 @@ var TeslemetryVehicleApi = class {
|
|
|
4864
4788
|
//#region src/TeslemetryApi.ts
|
|
4865
4789
|
var TeslemetryApi = class {
|
|
4866
4790
|
root;
|
|
4867
|
-
|
|
4868
|
-
|
|
4791
|
+
vehicles = /* @__PURE__ */ new Map();
|
|
4792
|
+
energySites = /* @__PURE__ */ new Map();
|
|
4869
4793
|
user;
|
|
4870
4794
|
charging;
|
|
4871
4795
|
constructor(root) {
|
|
@@ -4879,8 +4803,8 @@ var TeslemetryApi = class {
|
|
|
4879
4803
|
* @returns The vehicle API instance for the specified VIN.
|
|
4880
4804
|
*/
|
|
4881
4805
|
getVehicle(vin) {
|
|
4882
|
-
if (!this.
|
|
4883
|
-
return this.
|
|
4806
|
+
if (!this.vehicles.has(vin)) new TeslemetryVehicleApi(this.root, vin);
|
|
4807
|
+
return this.vehicles.get(vin);
|
|
4884
4808
|
}
|
|
4885
4809
|
/**
|
|
4886
4810
|
* Gets or creates an energy site API instance for the specified ID.
|
|
@@ -4888,8 +4812,8 @@ var TeslemetryApi = class {
|
|
|
4888
4812
|
* @returns The energy site API instance for the specified ID.
|
|
4889
4813
|
*/
|
|
4890
4814
|
getEnergySite(id) {
|
|
4891
|
-
if (!this.
|
|
4892
|
-
return this.
|
|
4815
|
+
if (!this.energySites.has(id)) new TeslemetryEnergyApi(this.root, id);
|
|
4816
|
+
return this.energySites.get(id);
|
|
4893
4817
|
}
|
|
4894
4818
|
/**
|
|
4895
4819
|
* Creates API instances for all products (vehicles and energy sites) associated with the account.
|
|
@@ -4902,11 +4826,11 @@ var TeslemetryApi = class {
|
|
|
4902
4826
|
if (product.device_type === "energy") this.getEnergySite(product.energy_site_id);
|
|
4903
4827
|
});
|
|
4904
4828
|
return {
|
|
4905
|
-
vehicles: this.
|
|
4906
|
-
energySites: this.
|
|
4829
|
+
vehicles: this.vehicles,
|
|
4830
|
+
energySites: this.energySites
|
|
4907
4831
|
};
|
|
4908
4832
|
}
|
|
4909
|
-
async
|
|
4833
|
+
async getFields() {
|
|
4910
4834
|
const { data } = await getFieldsJson({ client: this.root.client });
|
|
4911
4835
|
return data;
|
|
4912
4836
|
}
|
|
@@ -4915,7 +4839,7 @@ var TeslemetryApi = class {
|
|
|
4915
4839
|
* @returns A promise that resolves to an object containing a `response` array and count.
|
|
4916
4840
|
* Each item in the array is a product, which can be a vehicle or an energy site, and a `count` of the products.
|
|
4917
4841
|
*/
|
|
4918
|
-
async
|
|
4842
|
+
async getProducts() {
|
|
4919
4843
|
const { data } = await getApi1Products({ client: this.root.client });
|
|
4920
4844
|
return data;
|
|
4921
4845
|
}
|
|
@@ -4932,7 +4856,7 @@ var TeslemetryApi = class {
|
|
|
4932
4856
|
* @returns Promise to an object containing metadata about the account,
|
|
4933
4857
|
* including user UID, region, scopes, and lists of vehicles and energy sites.
|
|
4934
4858
|
*/
|
|
4935
|
-
async
|
|
4859
|
+
async getMetadata() {
|
|
4936
4860
|
const { data } = await getApiMetadata({ client: this.root.client });
|
|
4937
4861
|
return data;
|
|
4938
4862
|
}
|
|
@@ -4942,7 +4866,7 @@ var TeslemetryApi = class {
|
|
|
4942
4866
|
* @returns Promise to an object containing lists of paired and unpaired VINs,
|
|
4943
4867
|
* and detailed info for each vehicle.
|
|
4944
4868
|
*/
|
|
4945
|
-
async
|
|
4869
|
+
async getFleetStatus(vins) {
|
|
4946
4870
|
const { data } = await postApi1VehiclesFleetStatus({
|
|
4947
4871
|
body: { vins },
|
|
4948
4872
|
client: this.root.client
|
|
@@ -4954,7 +4878,7 @@ var TeslemetryApi = class {
|
|
|
4954
4878
|
* @returns Promise to an object containing a list of vehicles,
|
|
4955
4879
|
* pagination details, and a total count.
|
|
4956
4880
|
*/
|
|
4957
|
-
async
|
|
4881
|
+
async getVehicles() {
|
|
4958
4882
|
const { data } = await getApi1Vehicles({ client: this.root.client });
|
|
4959
4883
|
return data;
|
|
4960
4884
|
}
|
|
@@ -4983,7 +4907,7 @@ const consoleLogger = {
|
|
|
4983
4907
|
|
|
4984
4908
|
//#endregion
|
|
4985
4909
|
//#region package.json
|
|
4986
|
-
var version = "0.
|
|
4910
|
+
var version = "0.4.0";
|
|
4987
4911
|
|
|
4988
4912
|
//#endregion
|
|
4989
4913
|
//#region src/Teslemetry.ts
|