tesla-fleet-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/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/charging.cjs +53 -0
- package/dist/charging.d.cts +31 -0
- package/dist/charging.d.mts +30 -0
- package/dist/charging.mjs +53 -0
- package/dist/commands.cjs +802 -0
- package/dist/commands.d.cts +350 -0
- package/dist/commands.d.mts +349 -0
- package/dist/commands.mjs +800 -0
- package/dist/const.cjs +300 -0
- package/dist/const.d.cts +287 -0
- package/dist/const.d.mts +287 -0
- package/dist/const.mjs +263 -0
- package/dist/energy.cjs +137 -0
- package/dist/energy.d.cts +95 -0
- package/{src/energy.ts → dist/energy.d.mts} +17 -140
- package/dist/energy.mjs +137 -0
- package/dist/energyspecific.cjs +99 -0
- package/dist/energyspecific.d.cts +78 -0
- package/dist/energyspecific.d.mts +77 -0
- package/dist/energyspecific.mjs +99 -0
- package/dist/exceptions.cjs +1487 -0
- package/dist/exceptions.d.cts +1142 -0
- package/dist/exceptions.d.mts +1142 -0
- package/dist/exceptions.mjs +1324 -0
- package/dist/index.cjs +226 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.mjs +14 -0
- package/dist/partner.cjs +32 -0
- package/dist/partner.d.cts +24 -0
- package/dist/partner.d.mts +23 -0
- package/dist/partner.mjs +32 -0
- package/dist/router.cjs +0 -0
- package/dist/router.d.cts +1 -0
- package/dist/router.d.mts +1 -0
- package/dist/router.mjs +1 -0
- package/dist/signing/crypto.cjs +31 -0
- package/dist/signing/crypto.mjs +27 -0
- package/dist/signing/session.cjs +112 -0
- package/dist/signing/session.d.cts +69 -0
- package/dist/signing/session.d.mts +69 -0
- package/dist/signing/session.mjs +110 -0
- package/dist/tariff.cjs +292 -0
- package/dist/{tariff.d.ts → tariff.d.cts} +17 -17
- package/dist/tariff.d.mts +29 -0
- package/dist/tariff.mjs +291 -0
- package/dist/teslafleetapi.cjs +125 -0
- package/dist/teslafleetapi.d.cts +64 -0
- package/dist/teslafleetapi.d.mts +64 -0
- package/dist/teslafleetapi.mjs +125 -0
- package/dist/teslemetry.cjs +36 -0
- package/dist/teslemetry.d.cts +23 -0
- package/dist/teslemetry.d.mts +23 -0
- package/dist/teslemetry.mjs +36 -0
- package/dist/tessie.cjs +34 -0
- package/dist/tessie.d.cts +23 -0
- package/dist/tessie.d.mts +23 -0
- package/dist/tessie.mjs +34 -0
- package/dist/types/commands.d.cts +28 -0
- package/dist/types/commands.d.mts +28 -0
- package/dist/types/live_status.d.cts +30 -0
- package/dist/types/live_status.d.mts +30 -0
- package/dist/types/products.d.cts +58 -0
- package/dist/types/products.d.mts +58 -0
- package/dist/types/responses.d.cts +9 -0
- package/dist/types/responses.d.mts +9 -0
- package/dist/types/site_info.d.cts +154 -0
- package/dist/types/site_info.d.mts +154 -0
- package/dist/types/vehicle.d.cts +27 -0
- package/dist/types/vehicle.d.mts +27 -0
- package/dist/types/vehicle_data.d.cts +278 -0
- package/dist/types/vehicle_data.d.mts +278 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +9 -0
- package/dist/types.d.mts +9 -0
- package/dist/types.mjs +1 -0
- package/dist/user.cjs +28 -0
- package/dist/user.d.cts +17 -0
- package/dist/user.d.mts +16 -0
- package/dist/user.mjs +28 -0
- package/dist/vehicle.cjs +804 -0
- package/dist/vehicle.d.cts +550 -0
- package/dist/vehicle.d.mts +549 -0
- package/dist/vehicle.mjs +804 -0
- package/dist/vehiclesigned.cjs +20 -0
- package/dist/vehiclesigned.d.cts +14 -0
- package/dist/{vehiclesigned.d.ts → vehiclesigned.d.mts} +3 -3
- package/dist/vehiclesigned.mjs +20 -0
- package/dist/vehiclespecific.cjs +604 -0
- package/dist/vehiclespecific.d.cts +433 -0
- package/dist/vehiclespecific.d.mts +432 -0
- package/dist/vehiclespecific.mjs +604 -0
- package/package.json +108 -35
- package/dist/charging.d.ts +0 -30
- package/dist/charging.js +0 -51
- package/dist/charging.js.map +0 -1
- package/dist/commands.d.ts +0 -352
- package/dist/commands.js +0 -875
- package/dist/commands.js.map +0 -1
- package/dist/energy.d.ts +0 -94
- package/dist/energy.js +0 -125
- package/dist/energy.js.map +0 -1
- package/dist/energyspecific.d.ts +0 -77
- package/dist/energyspecific.js +0 -97
- package/dist/energyspecific.js.map +0 -1
- package/dist/helpers.d.ts +0 -2
- package/dist/helpers.js +0 -10
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -14
- package/dist/index.js.map +0 -1
- package/dist/partner.d.ts +0 -23
- package/dist/partner.js +0 -31
- package/dist/partner.js.map +0 -1
- package/dist/signing/crypto.d.ts +0 -10
- package/dist/signing/crypto.js +0 -26
- package/dist/signing/crypto.js.map +0 -1
- package/dist/signing/errors.d.ts +0 -29
- package/dist/signing/errors.js +0 -40
- package/dist/signing/errors.js.map +0 -1
- package/dist/signing/session.d.ts +0 -69
- package/dist/signing/session.js +0 -102
- package/dist/signing/session.js.map +0 -1
- package/dist/tariff.js +0 -302
- package/dist/tariff.js.map +0 -1
- package/dist/teslafleetapi.d.ts +0 -58
- package/dist/teslafleetapi.js +0 -120
- package/dist/teslafleetapi.js.map +0 -1
- package/dist/teslemetry.d.ts +0 -29
- package/dist/teslemetry.js +0 -39
- package/dist/teslemetry.js.map +0 -1
- package/dist/tessie.d.ts +0 -23
- package/dist/tessie.js +0 -28
- package/dist/tessie.js.map +0 -1
- package/dist/types/commands.d.ts +0 -44
- package/dist/types/commands.js +0 -11
- package/dist/types/commands.js.map +0 -1
- package/dist/types/live_status.d.ts +0 -26
- package/dist/types/live_status.js +0 -2
- package/dist/types/live_status.js.map +0 -1
- package/dist/types/products.d.ts +0 -54
- package/dist/types/products.js +0 -2
- package/dist/types/products.js.map +0 -1
- package/dist/types/responses.d.ts +0 -5
- package/dist/types/responses.js +0 -2
- package/dist/types/responses.js.map +0 -1
- package/dist/types/site_info.d.ts +0 -150
- package/dist/types/site_info.js +0 -2
- package/dist/types/site_info.js.map +0 -1
- package/dist/types/vehicle.d.ts +0 -22
- package/dist/types/vehicle.js +0 -2
- package/dist/types/vehicle.js.map +0 -1
- package/dist/types/vehicle_data.d.ts +0 -274
- package/dist/types/vehicle_data.js +0 -2
- package/dist/types/vehicle_data.js.map +0 -1
- package/dist/user.d.ts +0 -16
- package/dist/user.js +0 -26
- package/dist/user.js.map +0 -1
- package/dist/vehicle.d.ts +0 -548
- package/dist/vehicle.js +0 -781
- package/dist/vehicle.js.map +0 -1
- package/dist/vehiclesigned.js +0 -19
- package/dist/vehiclesigned.js.map +0 -1
- package/dist/vehiclespecific.d.ts +0 -432
- package/dist/vehiclespecific.js +0 -601
- package/dist/vehiclespecific.js.map +0 -1
- package/src/charging.ts +0 -66
- package/src/commands.ts +0 -1134
- package/src/energyspecific.ts +0 -116
- package/src/helpers.ts +0 -11
- package/src/index.ts +0 -20
- package/src/partner.ts +0 -37
- package/src/signing/crypto.ts +0 -29
- package/src/signing/errors.ts +0 -50
- package/src/signing/session.ts +0 -132
- package/src/tariff.ts +0 -375
- package/src/teslafleetapi.ts +0 -182
- package/src/teslemetry.ts +0 -54
- package/src/tessie.ts +0 -42
- package/src/types/commands.ts +0 -62
- package/src/types/live_status.ts +0 -27
- package/src/types/products.ts +0 -61
- package/src/types/responses.ts +0 -1
- package/src/types/site_info.ts +0 -159
- package/src/types/vehicle.ts +0 -23
- package/src/types/vehicle_data.ts +0 -286
- package/src/user.ts +0 -35
- package/src/vehicle.ts +0 -895
- package/src/vehiclesigned.ts +0 -20
- package/src/vehiclespecific.ts +0 -818
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import Charging from "./charging.mjs";
|
|
2
|
+
import Energy from "./energy.mjs";
|
|
3
|
+
import Partner from "./partner.mjs";
|
|
4
|
+
import User from "./user.mjs";
|
|
5
|
+
import Vehicle from "./vehicle.mjs";
|
|
6
|
+
import { SERVERS, is_valid_region } from "./const.mjs";
|
|
7
|
+
import { ResponseError, TeslaFleetConnectionError, TeslaFleetError, raise_for_status } from "./exceptions.mjs";
|
|
8
|
+
// src/teslafleetapi.ts
|
|
9
|
+
var TeslaFleetApi = class {
|
|
10
|
+
server = null;
|
|
11
|
+
accessToken;
|
|
12
|
+
charging;
|
|
13
|
+
energy;
|
|
14
|
+
partner;
|
|
15
|
+
user;
|
|
16
|
+
vehicle;
|
|
17
|
+
debug = false;
|
|
18
|
+
/** Abort a request (including reading its body) after this many milliseconds; `null` waits indefinitely. */
|
|
19
|
+
timeout;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.debug = !!options.debug;
|
|
22
|
+
this.timeout = options.timeout ?? null;
|
|
23
|
+
this.accessToken = options.accessToken ?? null;
|
|
24
|
+
if (options.server) this.server = options.server;
|
|
25
|
+
else if (options.region && is_valid_region(options.region)) this.server = SERVERS[options.region];
|
|
26
|
+
else throw new Error("Either server or region must be provided.");
|
|
27
|
+
this.debug && console.debug(`Using server ${this.server}`);
|
|
28
|
+
if (options.chargingScope !== false) this.charging = new Charging(this);
|
|
29
|
+
if (options.energyScope !== false) this.energy = new Energy(this);
|
|
30
|
+
if (options.userScope !== false) this.user = new User(this);
|
|
31
|
+
if (options.partnerScope !== false) this.partner = new Partner(this);
|
|
32
|
+
if (options.vehicleScope !== false) this.vehicle = new Vehicle(this);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Turn a response into its decoded JSON body, throwing the matching
|
|
36
|
+
* `TeslaFleetError` for an error status and `ResponseError` for a
|
|
37
|
+
* successful response whose body is not JSON.
|
|
38
|
+
*/
|
|
39
|
+
async _response(resp) {
|
|
40
|
+
await raise_for_status(resp);
|
|
41
|
+
const text = await resp.text();
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(text);
|
|
44
|
+
} catch {
|
|
45
|
+
throw new ResponseError(text, resp.status);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Make a request to the Tesla Fleet API.
|
|
50
|
+
* @param method
|
|
51
|
+
* @param path
|
|
52
|
+
* @param params
|
|
53
|
+
* @param json
|
|
54
|
+
* @returns The decoded JSON body.
|
|
55
|
+
* @throws A `TeslaFleetError` subclass for an error status, or
|
|
56
|
+
* `TeslaFleetConnectionError` (with the original error as `cause`) when the
|
|
57
|
+
* request could not complete or timed out.
|
|
58
|
+
*/
|
|
59
|
+
async _request(method, path, params = null, json = null) {
|
|
60
|
+
if (!this.server) throw new Error("Server was not set at init. Call findServer() first.");
|
|
61
|
+
if (method === "GET" && json !== null) throw new Error("GET requests cannot have a body.");
|
|
62
|
+
this.debug && console.debug(`Sending request to ${path}`);
|
|
63
|
+
if (params) {
|
|
64
|
+
params = Object.fromEntries(Object.entries(params).filter(([_, v]) => v != null));
|
|
65
|
+
this.debug && console.debug(`Parameters: ${JSON.stringify(params)}`);
|
|
66
|
+
}
|
|
67
|
+
if (json) {
|
|
68
|
+
json = Object.fromEntries(Object.entries(json).filter(([_, v]) => v != null));
|
|
69
|
+
this.debug && console.debug(`Body: ${JSON.stringify(json)}`);
|
|
70
|
+
}
|
|
71
|
+
const headers = {
|
|
72
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
"X-Library": `node tesla_fleet_api`
|
|
75
|
+
};
|
|
76
|
+
const query = params ? "?" + new URLSearchParams(params).toString() : "";
|
|
77
|
+
try {
|
|
78
|
+
const resp = await fetch(`${this.server}/${path}${query}`, {
|
|
79
|
+
method,
|
|
80
|
+
headers,
|
|
81
|
+
body: json ? JSON.stringify(json) : null,
|
|
82
|
+
signal: this.timeout != null ? AbortSignal.timeout(this.timeout) : null
|
|
83
|
+
});
|
|
84
|
+
return await this._response(resp);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof TeslaFleetError) throw error;
|
|
87
|
+
throw new TeslaFleetConnectionError(null, null, { cause: error });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns products mapped to user.
|
|
92
|
+
* @returns An array of products including both vehicles and energy sites.
|
|
93
|
+
*/
|
|
94
|
+
async products() {
|
|
95
|
+
return this._request("GET", "api/1/products").then(({ response }) => response);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Return Tesla products separated into vehicles and energy_sites
|
|
99
|
+
* @returns A dictionary of vehicles and energy sites, each with an array of those products
|
|
100
|
+
*/
|
|
101
|
+
async products_by_type() {
|
|
102
|
+
return this.products().then((products) => ({
|
|
103
|
+
vehicles: products.filter((product) => "vin" in product),
|
|
104
|
+
energy_sites: products.filter((product) => "energy_site_id" in product)
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
async loadPrivateKey(path) {
|
|
108
|
+
return (await import("fs")).promises.readFile(path, "utf8").then((key) => {
|
|
109
|
+
this.accessToken = key;
|
|
110
|
+
}).catch(async () => {
|
|
111
|
+
const { privateKey: _privateKey } = (await import("crypto")).generateKeyPairSync("ec", {
|
|
112
|
+
namedCurve: "secp256r1",
|
|
113
|
+
publicKeyEncoding: {
|
|
114
|
+
type: "spki",
|
|
115
|
+
format: "pem"
|
|
116
|
+
},
|
|
117
|
+
privateKeyEncoding: {
|
|
118
|
+
type: "pkcs8",
|
|
119
|
+
format: "pem"
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
export { TeslaFleetApi as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_teslafleetapi = require("./teslafleetapi.cjs");
|
|
2
|
+
// src/teslemetry.ts
|
|
3
|
+
var Teslemetry = class extends require_teslafleetapi.default {
|
|
4
|
+
constructor(accessToken, region = "api") {
|
|
5
|
+
super({
|
|
6
|
+
accessToken,
|
|
7
|
+
server: `https://${region}.teslemetry.com`,
|
|
8
|
+
partnerScope: false,
|
|
9
|
+
userScope: false
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async _response(resp) {
|
|
13
|
+
if (resp.headers.has("x-region")) {
|
|
14
|
+
const region = resp.headers.get("x-region")?.toLowerCase();
|
|
15
|
+
if (region) this.server = `https://${region}.teslemetry.com`;
|
|
16
|
+
}
|
|
17
|
+
return super._response(resp);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Test the connection to Teslemetry
|
|
21
|
+
*/
|
|
22
|
+
async test() {
|
|
23
|
+
return this._request("GET", "api/test").then(({ response }) => response);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get details about your Teslemetry account
|
|
27
|
+
* @param update_region Update the server URL based on the region in the metadata
|
|
28
|
+
*/
|
|
29
|
+
async metadata(update_region = true) {
|
|
30
|
+
return this._request("GET", "api/metadata").then((metadata) => {
|
|
31
|
+
if (update_region) this.server = `https://${metadata.region.toLowerCase()}.teslemetry.com`;
|
|
32
|
+
return metadata;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.default = Teslemetry;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import TeslaFleetApi from "./teslafleetapi.cjs";
|
|
2
|
+
import { Scope } from "./const.cjs";
|
|
3
|
+
type Region = "na" | "eu" | "api";
|
|
4
|
+
type Metadata = {
|
|
5
|
+
uid: string;
|
|
6
|
+
region: "NA" | "EU";
|
|
7
|
+
scopes: Scope[];
|
|
8
|
+
vins: string[];
|
|
9
|
+
};
|
|
10
|
+
declare class Teslemetry extends TeslaFleetApi {
|
|
11
|
+
constructor(accessToken: string, region?: Region);
|
|
12
|
+
_response(resp: Response): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Test the connection to Teslemetry
|
|
15
|
+
*/
|
|
16
|
+
test(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Get details about your Teslemetry account
|
|
19
|
+
* @param update_region Update the server URL based on the region in the metadata
|
|
20
|
+
*/
|
|
21
|
+
metadata(update_region?: boolean): Promise<Metadata>;
|
|
22
|
+
}
|
|
23
|
+
export = Teslemetry;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import TeslaFleetApi from "./teslafleetapi.mjs";
|
|
2
|
+
import { Scope } from "./const.mjs";
|
|
3
|
+
type Region = "na" | "eu" | "api";
|
|
4
|
+
type Metadata = {
|
|
5
|
+
uid: string;
|
|
6
|
+
region: "NA" | "EU";
|
|
7
|
+
scopes: Scope[];
|
|
8
|
+
vins: string[];
|
|
9
|
+
};
|
|
10
|
+
export default class Teslemetry extends TeslaFleetApi {
|
|
11
|
+
constructor(accessToken: string, region?: Region);
|
|
12
|
+
_response(resp: Response): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Test the connection to Teslemetry
|
|
15
|
+
*/
|
|
16
|
+
test(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Get details about your Teslemetry account
|
|
19
|
+
* @param update_region Update the server URL based on the region in the metadata
|
|
20
|
+
*/
|
|
21
|
+
metadata(update_region?: boolean): Promise<Metadata>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import TeslaFleetApi from "./teslafleetapi.mjs";
|
|
2
|
+
// src/teslemetry.ts
|
|
3
|
+
var Teslemetry = class extends TeslaFleetApi {
|
|
4
|
+
constructor(accessToken, region = "api") {
|
|
5
|
+
super({
|
|
6
|
+
accessToken,
|
|
7
|
+
server: `https://${region}.teslemetry.com`,
|
|
8
|
+
partnerScope: false,
|
|
9
|
+
userScope: false
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async _response(resp) {
|
|
13
|
+
if (resp.headers.has("x-region")) {
|
|
14
|
+
const region = resp.headers.get("x-region")?.toLowerCase();
|
|
15
|
+
if (region) this.server = `https://${region}.teslemetry.com`;
|
|
16
|
+
}
|
|
17
|
+
return super._response(resp);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Test the connection to Teslemetry
|
|
21
|
+
*/
|
|
22
|
+
async test() {
|
|
23
|
+
return this._request("GET", "api/test").then(({ response }) => response);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get details about your Teslemetry account
|
|
27
|
+
* @param update_region Update the server URL based on the region in the metadata
|
|
28
|
+
*/
|
|
29
|
+
async metadata(update_region = true) {
|
|
30
|
+
return this._request("GET", "api/metadata").then((metadata) => {
|
|
31
|
+
if (update_region) this.server = `https://${metadata.region.toLowerCase()}.teslemetry.com`;
|
|
32
|
+
return metadata;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export { Teslemetry as default };
|
package/dist/tessie.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const require_teslafleetapi = require("./teslafleetapi.cjs");
|
|
2
|
+
// src/tessie.ts
|
|
3
|
+
var Tessie = class extends require_teslafleetapi.default {
|
|
4
|
+
constructor(accessToken) {
|
|
5
|
+
super({
|
|
6
|
+
accessToken,
|
|
7
|
+
server: `https://api.tessie.com`,
|
|
8
|
+
partnerScope: false,
|
|
9
|
+
userScope: false
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get your approved Tesla scopes
|
|
14
|
+
*/
|
|
15
|
+
async tesla_scopes() {
|
|
16
|
+
return this._request("GET", "auth/tesla_scopes").then(({ scopes }) => scopes);
|
|
17
|
+
}
|
|
18
|
+
async metadata() {
|
|
19
|
+
return this._request("GET", "auth/tesla_scopes");
|
|
20
|
+
}
|
|
21
|
+
async status(vin) {
|
|
22
|
+
return this._request("GET", `${vin}/status`).then(({ status }) => status);
|
|
23
|
+
}
|
|
24
|
+
async state(vin, use_cache = true) {
|
|
25
|
+
return this._request("GET", `${vin}/state`, { use_cache });
|
|
26
|
+
}
|
|
27
|
+
async vehicles(only_active = false) {
|
|
28
|
+
return this._request("GET", "vehicles", { only_active }).then(({ results }) => results);
|
|
29
|
+
}
|
|
30
|
+
async wake(vin) {
|
|
31
|
+
return this._request("POST", `${vin}/wake`).then(({ result }) => result);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.default = Tessie;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import TeslaFleetApi from "./teslafleetapi.cjs";
|
|
2
|
+
import { Scope } from "./const.cjs";
|
|
3
|
+
import { VehicleDataResponse } from "./types/vehicle_data.cjs";
|
|
4
|
+
type TessieVehicleResponse = {
|
|
5
|
+
vin: string;
|
|
6
|
+
is_active: boolean;
|
|
7
|
+
last_state: VehicleDataResponse;
|
|
8
|
+
};
|
|
9
|
+
declare class Tessie extends TeslaFleetApi {
|
|
10
|
+
constructor(accessToken: string);
|
|
11
|
+
/**
|
|
12
|
+
* Get your approved Tesla scopes
|
|
13
|
+
*/
|
|
14
|
+
tesla_scopes(): Promise<Scope[]>;
|
|
15
|
+
metadata(): Promise<{
|
|
16
|
+
scopes: Scope[];
|
|
17
|
+
}>;
|
|
18
|
+
status(vin: string): Promise<"asleep" | "waiting_for_sleep" | "awake">;
|
|
19
|
+
state(vin: string, use_cache?: boolean): Promise<VehicleDataResponse>;
|
|
20
|
+
vehicles(only_active?: boolean): Promise<TessieVehicleResponse[]>;
|
|
21
|
+
wake(vin: string): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
export = Tessie;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import TeslaFleetApi from "./teslafleetapi.mjs";
|
|
2
|
+
import { Scope } from "./const.mjs";
|
|
3
|
+
import { VehicleDataResponse } from "./types/vehicle_data.mjs";
|
|
4
|
+
type TessieVehicleResponse = {
|
|
5
|
+
vin: string;
|
|
6
|
+
is_active: boolean;
|
|
7
|
+
last_state: VehicleDataResponse;
|
|
8
|
+
};
|
|
9
|
+
export default class Tessie extends TeslaFleetApi {
|
|
10
|
+
constructor(accessToken: string);
|
|
11
|
+
/**
|
|
12
|
+
* Get your approved Tesla scopes
|
|
13
|
+
*/
|
|
14
|
+
tesla_scopes(): Promise<Scope[]>;
|
|
15
|
+
metadata(): Promise<{
|
|
16
|
+
scopes: Scope[];
|
|
17
|
+
}>;
|
|
18
|
+
status(vin: string): Promise<"asleep" | "waiting_for_sleep" | "awake">;
|
|
19
|
+
state(vin: string, use_cache?: boolean): Promise<VehicleDataResponse>;
|
|
20
|
+
vehicles(only_active?: boolean): Promise<TessieVehicleResponse[]>;
|
|
21
|
+
wake(vin: string): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
package/dist/tessie.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import TeslaFleetApi from "./teslafleetapi.mjs";
|
|
2
|
+
// src/tessie.ts
|
|
3
|
+
var Tessie = class extends TeslaFleetApi {
|
|
4
|
+
constructor(accessToken) {
|
|
5
|
+
super({
|
|
6
|
+
accessToken,
|
|
7
|
+
server: `https://api.tessie.com`,
|
|
8
|
+
partnerScope: false,
|
|
9
|
+
userScope: false
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get your approved Tesla scopes
|
|
14
|
+
*/
|
|
15
|
+
async tesla_scopes() {
|
|
16
|
+
return this._request("GET", "auth/tesla_scopes").then(({ scopes }) => scopes);
|
|
17
|
+
}
|
|
18
|
+
async metadata() {
|
|
19
|
+
return this._request("GET", "auth/tesla_scopes");
|
|
20
|
+
}
|
|
21
|
+
async status(vin) {
|
|
22
|
+
return this._request("GET", `${vin}/status`).then(({ status }) => status);
|
|
23
|
+
}
|
|
24
|
+
async state(vin, use_cache = true) {
|
|
25
|
+
return this._request("GET", `${vin}/state`, { use_cache });
|
|
26
|
+
}
|
|
27
|
+
async vehicles(only_active = false) {
|
|
28
|
+
return this._request("GET", "vehicles", { only_active }).then(({ results }) => results);
|
|
29
|
+
}
|
|
30
|
+
async wake(vin) {
|
|
31
|
+
return this._request("POST", `${vin}/wake`).then(({ result }) => result);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export { Tessie as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ClimateMode, ClimateModes, Level, Scope, Seat, Seats, Trunk, VehicleDataEndpoint } from "../const.cjs";
|
|
2
|
+
declare namespace commands_d_exports {
|
|
3
|
+
export { AlertTypes, ClimateMode, ClimateModes, CommandResponse, FleetTelemetryConfig, Level, Scope, Seat, Seats, Trunk, VehicleDataEndpoint };
|
|
4
|
+
}
|
|
5
|
+
export interface CommandResponse {
|
|
6
|
+
response: {
|
|
7
|
+
result: boolean;
|
|
8
|
+
reason: string;
|
|
9
|
+
};
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
export type AlertTypes = "customer" | "service";
|
|
13
|
+
export interface FleetTelemetryConfig {
|
|
14
|
+
vins: string[];
|
|
15
|
+
config: {
|
|
16
|
+
hostname: string;
|
|
17
|
+
ca: string;
|
|
18
|
+
fields: {
|
|
19
|
+
[key: string]: {
|
|
20
|
+
interval_seconds: number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
alert_types: AlertTypes[];
|
|
24
|
+
exp: number;
|
|
25
|
+
port: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { type ClimateMode, ClimateModes, type Level, type Scope, type Seat, Seats, type Trunk, type VehicleDataEndpoint, commands_d_exports };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ClimateMode, ClimateModes, Level, Scope, Seat, Seats, Trunk, VehicleDataEndpoint } from "../const.mjs";
|
|
2
|
+
declare namespace commands_d_exports {
|
|
3
|
+
export { AlertTypes, ClimateMode, ClimateModes, CommandResponse, FleetTelemetryConfig, Level, Scope, Seat, Seats, Trunk, VehicleDataEndpoint };
|
|
4
|
+
}
|
|
5
|
+
export interface CommandResponse {
|
|
6
|
+
response: {
|
|
7
|
+
result: boolean;
|
|
8
|
+
reason: string;
|
|
9
|
+
};
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
export type AlertTypes = "customer" | "service";
|
|
13
|
+
export interface FleetTelemetryConfig {
|
|
14
|
+
vins: string[];
|
|
15
|
+
config: {
|
|
16
|
+
hostname: string;
|
|
17
|
+
ca: string;
|
|
18
|
+
fields: {
|
|
19
|
+
[key: string]: {
|
|
20
|
+
interval_seconds: number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
alert_types: AlertTypes[];
|
|
24
|
+
exp: number;
|
|
25
|
+
port: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { type ClimateMode, ClimateModes, type Level, type Scope, type Seat, Seats, type Trunk, type VehicleDataEndpoint, commands_d_exports };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare namespace live_status_d_exports {
|
|
2
|
+
export { LiveStatusResponse, WallConnector };
|
|
3
|
+
}
|
|
4
|
+
export type LiveStatusResponse = {
|
|
5
|
+
solar_power?: number;
|
|
6
|
+
energy_left?: number;
|
|
7
|
+
total_pack_energy?: number;
|
|
8
|
+
percentage_charged?: number;
|
|
9
|
+
backup_capable?: boolean;
|
|
10
|
+
battery_power?: number;
|
|
11
|
+
load_power?: number;
|
|
12
|
+
grid_status?: string;
|
|
13
|
+
grid_services_active?: boolean;
|
|
14
|
+
grid_power?: number;
|
|
15
|
+
grid_services_power?: number;
|
|
16
|
+
generator_power?: number;
|
|
17
|
+
island_status?: string;
|
|
18
|
+
storm_mode_active?: boolean;
|
|
19
|
+
timestamp: Date;
|
|
20
|
+
wall_connectors?: WallConnector[];
|
|
21
|
+
};
|
|
22
|
+
export type WallConnector = {
|
|
23
|
+
din: string;
|
|
24
|
+
vin?: string;
|
|
25
|
+
wall_connector_state: number;
|
|
26
|
+
wall_connector_fault_state: number;
|
|
27
|
+
wall_connector_power: number;
|
|
28
|
+
ocpp_status: number;
|
|
29
|
+
};
|
|
30
|
+
export { live_status_d_exports };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare namespace live_status_d_exports {
|
|
2
|
+
export { LiveStatusResponse, WallConnector };
|
|
3
|
+
}
|
|
4
|
+
export type LiveStatusResponse = {
|
|
5
|
+
solar_power?: number;
|
|
6
|
+
energy_left?: number;
|
|
7
|
+
total_pack_energy?: number;
|
|
8
|
+
percentage_charged?: number;
|
|
9
|
+
backup_capable?: boolean;
|
|
10
|
+
battery_power?: number;
|
|
11
|
+
load_power?: number;
|
|
12
|
+
grid_status?: string;
|
|
13
|
+
grid_services_active?: boolean;
|
|
14
|
+
grid_power?: number;
|
|
15
|
+
grid_services_power?: number;
|
|
16
|
+
generator_power?: number;
|
|
17
|
+
island_status?: string;
|
|
18
|
+
storm_mode_active?: boolean;
|
|
19
|
+
timestamp: Date;
|
|
20
|
+
wall_connectors?: WallConnector[];
|
|
21
|
+
};
|
|
22
|
+
export type WallConnector = {
|
|
23
|
+
din: string;
|
|
24
|
+
vin?: string;
|
|
25
|
+
wall_connector_state: number;
|
|
26
|
+
wall_connector_fault_state: number;
|
|
27
|
+
wall_connector_power: number;
|
|
28
|
+
ocpp_status: number;
|
|
29
|
+
};
|
|
30
|
+
export { live_status_d_exports };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { VehicleResponse } from "./vehicle.cjs";
|
|
2
|
+
import { VehicleConfig } from "./vehicle_data.cjs";
|
|
3
|
+
declare namespace products_d_exports {
|
|
4
|
+
export { Components, EnergyProduct, Features, ProductsData, ProductsResponse, VehicleProduct, WallConnector };
|
|
5
|
+
}
|
|
6
|
+
export type ProductsData = {
|
|
7
|
+
response: ProductsResponse;
|
|
8
|
+
count: number;
|
|
9
|
+
};
|
|
10
|
+
export type ProductsResponse = (VehicleProduct | EnergyProduct)[];
|
|
11
|
+
export type VehicleProduct = VehicleResponse & {
|
|
12
|
+
vehicle_config: VehicleConfig;
|
|
13
|
+
command_signing: string;
|
|
14
|
+
release_notes_supported: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type EnergyProduct = {
|
|
17
|
+
energy_site_id: number;
|
|
18
|
+
resource_type: string;
|
|
19
|
+
site_name: string;
|
|
20
|
+
id: string;
|
|
21
|
+
gateway_id: string;
|
|
22
|
+
asset_site_id: string;
|
|
23
|
+
warp_site_number: string;
|
|
24
|
+
energy_left: number;
|
|
25
|
+
total_pack_energy: number;
|
|
26
|
+
percentage_charged: number;
|
|
27
|
+
battery_type: string;
|
|
28
|
+
backup_capable: boolean;
|
|
29
|
+
battery_power: number;
|
|
30
|
+
go_off_grid_test_banner_enabled: null | boolean;
|
|
31
|
+
storm_mode_enabled: boolean;
|
|
32
|
+
powerwall_onboarding_settings_set: boolean;
|
|
33
|
+
powerwall_tesla_electric_interested_in: null | boolean;
|
|
34
|
+
vpp_tour_enabled: null | boolean;
|
|
35
|
+
sync_grid_alert_enabled: boolean;
|
|
36
|
+
breaker_alert_enabled: boolean;
|
|
37
|
+
components: Components;
|
|
38
|
+
features: Features;
|
|
39
|
+
};
|
|
40
|
+
export type Components = {
|
|
41
|
+
battery: boolean;
|
|
42
|
+
battery_type: string;
|
|
43
|
+
solar: boolean;
|
|
44
|
+
solar_type: string;
|
|
45
|
+
grid: boolean;
|
|
46
|
+
load_meter: boolean;
|
|
47
|
+
market_type: string;
|
|
48
|
+
wall_connectors: WallConnector[];
|
|
49
|
+
};
|
|
50
|
+
export type WallConnector = {
|
|
51
|
+
device_id: string;
|
|
52
|
+
din: string;
|
|
53
|
+
is_active: boolean;
|
|
54
|
+
};
|
|
55
|
+
export type Features = {
|
|
56
|
+
rate_plan_manager_no_pricing_constraint: boolean;
|
|
57
|
+
};
|
|
58
|
+
export { products_d_exports };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { VehicleResponse } from "./vehicle.mjs";
|
|
2
|
+
import { VehicleConfig } from "./vehicle_data.mjs";
|
|
3
|
+
declare namespace products_d_exports {
|
|
4
|
+
export { Components, EnergyProduct, Features, ProductsData, ProductsResponse, VehicleProduct, WallConnector };
|
|
5
|
+
}
|
|
6
|
+
export type ProductsData = {
|
|
7
|
+
response: ProductsResponse;
|
|
8
|
+
count: number;
|
|
9
|
+
};
|
|
10
|
+
export type ProductsResponse = (VehicleProduct | EnergyProduct)[];
|
|
11
|
+
export type VehicleProduct = VehicleResponse & {
|
|
12
|
+
vehicle_config: VehicleConfig;
|
|
13
|
+
command_signing: string;
|
|
14
|
+
release_notes_supported: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type EnergyProduct = {
|
|
17
|
+
energy_site_id: number;
|
|
18
|
+
resource_type: string;
|
|
19
|
+
site_name: string;
|
|
20
|
+
id: string;
|
|
21
|
+
gateway_id: string;
|
|
22
|
+
asset_site_id: string;
|
|
23
|
+
warp_site_number: string;
|
|
24
|
+
energy_left: number;
|
|
25
|
+
total_pack_energy: number;
|
|
26
|
+
percentage_charged: number;
|
|
27
|
+
battery_type: string;
|
|
28
|
+
backup_capable: boolean;
|
|
29
|
+
battery_power: number;
|
|
30
|
+
go_off_grid_test_banner_enabled: null | boolean;
|
|
31
|
+
storm_mode_enabled: boolean;
|
|
32
|
+
powerwall_onboarding_settings_set: boolean;
|
|
33
|
+
powerwall_tesla_electric_interested_in: null | boolean;
|
|
34
|
+
vpp_tour_enabled: null | boolean;
|
|
35
|
+
sync_grid_alert_enabled: boolean;
|
|
36
|
+
breaker_alert_enabled: boolean;
|
|
37
|
+
components: Components;
|
|
38
|
+
features: Features;
|
|
39
|
+
};
|
|
40
|
+
export type Components = {
|
|
41
|
+
battery: boolean;
|
|
42
|
+
battery_type: string;
|
|
43
|
+
solar: boolean;
|
|
44
|
+
solar_type: string;
|
|
45
|
+
grid: boolean;
|
|
46
|
+
load_meter: boolean;
|
|
47
|
+
market_type: string;
|
|
48
|
+
wall_connectors: WallConnector[];
|
|
49
|
+
};
|
|
50
|
+
export type WallConnector = {
|
|
51
|
+
device_id: string;
|
|
52
|
+
din: string;
|
|
53
|
+
is_active: boolean;
|
|
54
|
+
};
|
|
55
|
+
export type Features = {
|
|
56
|
+
rate_plan_manager_no_pricing_constraint: boolean;
|
|
57
|
+
};
|
|
58
|
+
export { products_d_exports };
|