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
package/src/tariff.ts
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
import { EnergyCharges, Season, TariffContentV2, TouPeriods } from "./types/site_info.js";
|
|
2
|
-
|
|
3
|
-
export interface TariffRate {
|
|
4
|
-
price: number | null;
|
|
5
|
-
periodName: string | null;
|
|
6
|
-
seasonName: string | null;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface TariffPeriod {
|
|
10
|
-
start: Date;
|
|
11
|
-
end: Date;
|
|
12
|
-
buy: TariffRate;
|
|
13
|
-
sell: TariffRate;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface TariffResolution {
|
|
17
|
-
buy: TariffRate;
|
|
18
|
-
sell: TariffRate;
|
|
19
|
-
currentStart: Date;
|
|
20
|
-
nextChange: Date;
|
|
21
|
-
currency: string | null;
|
|
22
|
-
upcoming: TariffPeriod[] | null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const MINUTES_PER_DAY = 1440;
|
|
26
|
-
|
|
27
|
-
type WallClock = { year: number; month: number; day: number; dow: number; minuteOfDay: number };
|
|
28
|
-
|
|
29
|
-
/** One day's period windows, expressed in that day's own minute-of-day (0..1440). */
|
|
30
|
-
type DaySegment = { periodName: string; startMin: number; endMin: number; trueStartMin: number };
|
|
31
|
-
|
|
32
|
-
function formatParts(date: Date, timeZone: string): Record<string, number> {
|
|
33
|
-
const parts = new Intl.DateTimeFormat("en-US", {
|
|
34
|
-
timeZone,
|
|
35
|
-
year: "numeric",
|
|
36
|
-
month: "2-digit",
|
|
37
|
-
day: "2-digit",
|
|
38
|
-
hour: "2-digit",
|
|
39
|
-
minute: "2-digit",
|
|
40
|
-
second: "2-digit",
|
|
41
|
-
hourCycle: "h23",
|
|
42
|
-
}).formatToParts(date);
|
|
43
|
-
const out: Record<string, number> = {};
|
|
44
|
-
for (const p of parts) out[p.type] = Number(p.value);
|
|
45
|
-
return out;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Tesla weekday (Mon=0..Sun=6) for a calendar date, via JS Date.getUTCDay() (Sun=0..Sat=6). */
|
|
49
|
-
function dowFromDate(year: number, month: number, day: number): number {
|
|
50
|
-
const jsDow = new Date(Date.UTC(year, month - 1, day)).getUTCDay();
|
|
51
|
-
return (jsDow + 6) % 7;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getWallClock(now: Date, timeZone: string): WallClock {
|
|
55
|
-
const { year, month, day, hour, minute } = formatParts(now, timeZone);
|
|
56
|
-
return { year, month, day, dow: dowFromDate(year, month, day), minuteOfDay: hour * 60 + minute };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Converts a target site-local wall-clock (year/month/day/hour/minute in `timeZone`) to the UTC
|
|
61
|
-
* instant it represents. Iterates because the zone's UTC offset at the target instant is itself
|
|
62
|
-
* what we're solving for (DST) - 3 rounds converges for any real-world offset change.
|
|
63
|
-
*/
|
|
64
|
-
function wallClockToUtcMillis(year: number, month: number, day: number, hour: number, minute: number, timeZone: string): number {
|
|
65
|
-
const target = Date.UTC(year, month - 1, day, hour, minute);
|
|
66
|
-
let guess = target;
|
|
67
|
-
for (let i = 0; i < 3; i++) {
|
|
68
|
-
const p = formatParts(new Date(guess), timeZone);
|
|
69
|
-
const asUtc = Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second);
|
|
70
|
-
const offset = asUtc - guess;
|
|
71
|
-
const next = target - offset;
|
|
72
|
-
if (next === guess) break;
|
|
73
|
-
guess = next;
|
|
74
|
-
}
|
|
75
|
-
return guess;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Adds `deltaMinutes` of wall-clock time (not elapsed real time) to a wall-clock reading, staying
|
|
80
|
-
* in pure calendar arithmetic throughout - no `timeZone`/`Intl` round trip, so this is safe to use
|
|
81
|
-
* for "what day/weekday is N minutes from now" even across a DST transition, where a real-time-ms
|
|
82
|
-
* shift and a wall-clock-minutes shift land on different calendar days.
|
|
83
|
-
*/
|
|
84
|
-
function wallClockAt(wallClock: WallClock, deltaMinutes: number): WallClock {
|
|
85
|
-
const naive = new Date(Date.UTC(wallClock.year, wallClock.month - 1, wallClock.day, 0, wallClock.minuteOfDay + deltaMinutes));
|
|
86
|
-
const year = naive.getUTCFullYear();
|
|
87
|
-
const month = naive.getUTCMonth() + 1;
|
|
88
|
-
const day = naive.getUTCDate();
|
|
89
|
-
const minuteOfDay = naive.getUTCHours() * 60 + naive.getUTCMinutes();
|
|
90
|
-
return { year, month, day, dow: dowFromDate(year, month, day), minuteOfDay };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function dowInRange(d: number, fromDow: number, toDow: number): boolean {
|
|
94
|
-
return fromDow <= toDow ? d >= fromDow && d <= toDow : d >= fromDow || d <= toDow;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function seasonContains(season: Season, month: number, day: number): boolean {
|
|
98
|
-
if (!season?.tou_periods) return false;
|
|
99
|
-
const fromMonth = season.fromMonth ?? 1;
|
|
100
|
-
const fromDay = season.fromDay ?? 1;
|
|
101
|
-
const toMonth = season.toMonth ?? 12;
|
|
102
|
-
const toDay = season.toDay ?? 31;
|
|
103
|
-
const from = fromMonth * 100 + fromDay;
|
|
104
|
-
const to = toMonth * 100 + toDay;
|
|
105
|
-
const cur = month * 100 + day;
|
|
106
|
-
return from <= to ? cur >= from && cur <= to : cur >= from || cur <= to;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function findSeason(seasons: Record<string, Season> | undefined, month: number, day: number): { name: string; season: Season } | null {
|
|
110
|
-
if (!seasons) return null;
|
|
111
|
-
for (const [name, season] of Object.entries(seasons)) {
|
|
112
|
-
if (seasonContains(season, month, day)) {
|
|
113
|
-
return { name, season };
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Expands a season's `tou_periods` into the windows active on one specific calendar day (given
|
|
121
|
-
* as a Tesla weekday, Mon=0..Sun=6). A period whose `fromDayOfWeek..toDayOfWeek` includes `dow`
|
|
122
|
-
* contributes its own window (clamped to this day, `endMin` capped at 1440 if it crosses
|
|
123
|
-
* midnight); a period that crosses midnight and includes *yesterday* also contributes its
|
|
124
|
-
* early-morning continuation here, `trueStartMin` carrying its real (pre-midnight) start so a
|
|
125
|
-
* currently-active continuation can still report an accurate `currentStart`.
|
|
126
|
-
*/
|
|
127
|
-
function dayPeriods(touPeriods: TouPeriods, dow: number): DaySegment[] {
|
|
128
|
-
const segments: DaySegment[] = [];
|
|
129
|
-
const prevDow = (dow + 6) % 7;
|
|
130
|
-
for (const [periodName, def] of Object.entries(touPeriods)) {
|
|
131
|
-
for (const window of def.periods ?? []) {
|
|
132
|
-
const fromDow = window.fromDayOfWeek ?? 0;
|
|
133
|
-
const toDow = window.toDayOfWeek ?? 6;
|
|
134
|
-
const fromMin = (window.fromHour ?? 0) * 60 + (window.fromMinute ?? 0);
|
|
135
|
-
const toMin = (window.toHour ?? 0) * 60 + (window.toMinute ?? 0);
|
|
136
|
-
const crossesMidnight = toMin <= fromMin;
|
|
137
|
-
if (dowInRange(dow, fromDow, toDow)) {
|
|
138
|
-
const endMin = crossesMidnight ? MINUTES_PER_DAY : toMin;
|
|
139
|
-
if (endMin > fromMin) segments.push({ periodName, startMin: fromMin, endMin, trueStartMin: fromMin });
|
|
140
|
-
}
|
|
141
|
-
if (crossesMidnight && toMin > 0 && dowInRange(prevDow, fromDow, toDow)) {
|
|
142
|
-
segments.push({ periodName, startMin: 0, endMin: toMin, trueStartMin: fromMin - MINUTES_PER_DAY });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return segments;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function lookupPrice(charges: EnergyCharges | undefined, seasonName: string, periodName: string): number | null {
|
|
150
|
-
if (!charges) return null;
|
|
151
|
-
// A season key can be present but carry no rates at all (e.g. an empty `"Winter": {}` stub
|
|
152
|
-
// alongside a populated `"ALL"`) - that must fall back to ALL exactly like a missing key.
|
|
153
|
-
const seasonRates = charges[seasonName]?.rates ?? charges["ALL"]?.rates;
|
|
154
|
-
if (!seasonRates) return null;
|
|
155
|
-
const value = Object.prototype.hasOwnProperty.call(seasonRates, periodName) ? seasonRates[periodName] : seasonRates["ALL"];
|
|
156
|
-
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const EMPTY_RATE: TariffRate = { price: null, periodName: null, seasonName: null };
|
|
160
|
-
|
|
161
|
-
type Schedule = {
|
|
162
|
-
seasonName: string;
|
|
163
|
-
/** The segment active right now, or null if `wallClock` falls in a gap between scheduled periods. */
|
|
164
|
-
current: DaySegment | null;
|
|
165
|
-
/**
|
|
166
|
-
* The next minute-of-day boundary (GM units relative to `wallClock`) at which this grid's rate
|
|
167
|
-
* changes - present whether or not a period is active right now, so a caller can still learn
|
|
168
|
-
* when a currently-empty grid (a gap) is about to start a period. Null only when neither today
|
|
169
|
-
* nor tomorrow has anything scheduled at all.
|
|
170
|
-
*/
|
|
171
|
-
nextChangeGM: number | null;
|
|
172
|
-
/**
|
|
173
|
-
* When the *current state* began (GM units relative to `wallClock`) - the active period's true
|
|
174
|
-
* start if one is active, or the moment the current gap began (the previous period's end)
|
|
175
|
-
* otherwise, so a currently-empty grid still reports an accurate "valid since". Bounded to at
|
|
176
|
-
* most one day of lookback (mirrors `nextChangeGM`'s one-day lookahead bound): null only when
|
|
177
|
-
* neither today nor yesterday has anything scheduled at all (this grid never constrains the
|
|
178
|
-
* combined `currentStart`).
|
|
179
|
-
*/
|
|
180
|
-
sinceGM: number | null;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Resolves one grid's (buy's, or sell's) state at `wallClock`: the active period if any, and the
|
|
185
|
-
* next boundary regardless of whether a period is currently active - a sparse tariff's gap still
|
|
186
|
-
* has a "next change" (the gap's own end) and a "since" (the gap's own start), just like an active
|
|
187
|
-
* period does (its own end and start).
|
|
188
|
-
*/
|
|
189
|
-
function scheduleAt(seasons: Record<string, Season> | undefined, wallClock: WallClock): Schedule | null {
|
|
190
|
-
const matched = findSeason(seasons, wallClock.month, wallClock.day);
|
|
191
|
-
if (!matched) return null;
|
|
192
|
-
|
|
193
|
-
const todaySegs = dayPeriods(matched.season.tou_periods!, wallClock.dow);
|
|
194
|
-
const current = todaySegs.find((s) => s.startMin <= wallClock.minuteOfDay && wallClock.minuteOfDay < s.endMin) ?? null;
|
|
195
|
-
const laterTodayStarts = todaySegs.filter((s) => s.startMin > wallClock.minuteOfDay).map((s) => s.startMin);
|
|
196
|
-
|
|
197
|
-
let nextMin: number | null = current ? current.endMin : null;
|
|
198
|
-
if (laterTodayStarts.length > 0) {
|
|
199
|
-
nextMin = nextMin === null ? Math.min(...laterTodayStarts) : Math.min(nextMin, Math.min(...laterTodayStarts));
|
|
200
|
-
} else if (nextMin === null || nextMin >= MINUTES_PER_DAY) {
|
|
201
|
-
// Either in a gap with nothing left today, or the active period runs up to midnight -
|
|
202
|
-
// check tomorrow before treating midnight itself as the boundary.
|
|
203
|
-
const tomorrowWallClock = wallClockAt(wallClock, MINUTES_PER_DAY - wallClock.minuteOfDay);
|
|
204
|
-
const tomorrowMatched = findSeason(seasons, tomorrowWallClock.month, tomorrowWallClock.day);
|
|
205
|
-
const tomorrowSegs = tomorrowMatched ? dayPeriods(tomorrowMatched.season.tou_periods!, tomorrowWallClock.dow) : [];
|
|
206
|
-
const continuation = current && tomorrowMatched?.name === matched.name ? tomorrowSegs.find((s) => s.startMin === 0 && s.periodName === current.periodName) : undefined;
|
|
207
|
-
if (continuation) {
|
|
208
|
-
nextMin = MINUTES_PER_DAY + continuation.endMin;
|
|
209
|
-
} else if (tomorrowSegs.length > 0) {
|
|
210
|
-
const tomorrowFirst = MINUTES_PER_DAY + Math.min(...tomorrowSegs.map((s) => s.startMin));
|
|
211
|
-
nextMin = nextMin === null ? tomorrowFirst : Math.min(nextMin, tomorrowFirst);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
let sinceMin: number | null;
|
|
216
|
-
if (current) {
|
|
217
|
-
sinceMin = current.trueStartMin;
|
|
218
|
-
} else {
|
|
219
|
-
const earlierTodayEnds = todaySegs.filter((s) => s.endMin <= wallClock.minuteOfDay).map((s) => s.endMin);
|
|
220
|
-
if (earlierTodayEnds.length > 0) {
|
|
221
|
-
sinceMin = Math.max(...earlierTodayEnds);
|
|
222
|
-
} else {
|
|
223
|
-
// Nothing has ended yet today either - the gap may have started yesterday (or earlier).
|
|
224
|
-
// Peek one day back, same one-day bound as the forward "tomorrow" check above.
|
|
225
|
-
const yesterdayWallClock = wallClockAt(wallClock, -MINUTES_PER_DAY);
|
|
226
|
-
const yesterdayMatched = findSeason(seasons, yesterdayWallClock.month, yesterdayWallClock.day);
|
|
227
|
-
const yesterdaySegs = yesterdayMatched ? dayPeriods(yesterdayMatched.season.tou_periods!, yesterdayWallClock.dow) : [];
|
|
228
|
-
sinceMin = yesterdaySegs.length > 0 ? Math.max(...yesterdaySegs.map((s) => s.endMin)) - MINUTES_PER_DAY : null;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return {
|
|
233
|
-
seasonName: matched.name,
|
|
234
|
-
current,
|
|
235
|
-
nextChangeGM: nextMin === null ? null : nextMin - wallClock.minuteOfDay,
|
|
236
|
-
sinceGM: sinceMin === null ? null : sinceMin - wallClock.minuteOfDay,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
type ScheduleSegment = { startGM: number; endGM: number; periodName: string; seasonName: string };
|
|
241
|
-
|
|
242
|
-
/** Walks one calendar day at a time across the horizon, re-resolving the season fresh on each day (via pure wall-clock arithmetic, not elapsed-ms/DST-sensitive arithmetic) so a horizon crossing a season boundary re-prices and re-labels correctly. */
|
|
243
|
-
function collectSegments(seasons: Record<string, Season> | undefined, wallClock: WallClock, horizonMinutes: number): ScheduleSegment[] {
|
|
244
|
-
const segments: ScheduleSegment[] = [];
|
|
245
|
-
let dayStartGM = -wallClock.minuteOfDay;
|
|
246
|
-
while (dayStartGM < horizonMinutes) {
|
|
247
|
-
const dayWallClock = wallClockAt(wallClock, dayStartGM);
|
|
248
|
-
const matched = findSeason(seasons, dayWallClock.month, dayWallClock.day);
|
|
249
|
-
if (matched) {
|
|
250
|
-
for (const seg of dayPeriods(matched.season.tou_periods!, dayWallClock.dow)) {
|
|
251
|
-
const startGM = dayStartGM + seg.startMin;
|
|
252
|
-
const endGM = dayStartGM + seg.endMin;
|
|
253
|
-
if (endGM > 0 && startGM < horizonMinutes) {
|
|
254
|
-
segments.push({ startGM, endGM, periodName: seg.periodName, seasonName: matched.name });
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
dayStartGM += MINUTES_PER_DAY;
|
|
259
|
-
}
|
|
260
|
-
segments.sort((a, b) => a.startGM - b.startGM);
|
|
261
|
-
const merged: ScheduleSegment[] = [];
|
|
262
|
-
for (const seg of segments) {
|
|
263
|
-
const last = merged[merged.length - 1];
|
|
264
|
-
if (last && last.endGM === seg.startGM && last.periodName === seg.periodName && last.seasonName === seg.seasonName) {
|
|
265
|
-
last.endGM = seg.endGM;
|
|
266
|
-
} else {
|
|
267
|
-
merged.push({ ...seg });
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return merged;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function buildUpcoming(
|
|
274
|
-
buySeasons: Record<string, Season> | undefined,
|
|
275
|
-
buyCharges: EnergyCharges | undefined,
|
|
276
|
-
sellSeasons: Record<string, Season> | undefined,
|
|
277
|
-
sellCharges: EnergyCharges | undefined,
|
|
278
|
-
hasSell: boolean,
|
|
279
|
-
wallClock: WallClock,
|
|
280
|
-
horizonMinutes: number,
|
|
281
|
-
toDate: (gm: number) => Date,
|
|
282
|
-
): TariffPeriod[] {
|
|
283
|
-
const buySegs = collectSegments(buySeasons, wallClock, horizonMinutes);
|
|
284
|
-
const sellSegs = hasSell ? collectSegments(sellSeasons, wallClock, horizonMinutes) : [];
|
|
285
|
-
|
|
286
|
-
const boundaries = new Set<number>([0, horizonMinutes]);
|
|
287
|
-
const addBoundary = (gm: number): void => {
|
|
288
|
-
if (gm > 0 && gm < horizonMinutes) boundaries.add(gm);
|
|
289
|
-
};
|
|
290
|
-
for (const s of buySegs) {
|
|
291
|
-
addBoundary(s.startGM);
|
|
292
|
-
addBoundary(s.endGM);
|
|
293
|
-
}
|
|
294
|
-
for (const s of sellSegs) {
|
|
295
|
-
addBoundary(s.startGM);
|
|
296
|
-
addBoundary(s.endGM);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const sorted = [...boundaries].sort((a, b) => a - b);
|
|
300
|
-
const periods: TariffPeriod[] = [];
|
|
301
|
-
for (let i = 0; i < sorted.length - 1; i++) {
|
|
302
|
-
const segStart = sorted[i];
|
|
303
|
-
const segEnd = sorted[i + 1];
|
|
304
|
-
if (segStart === segEnd) continue;
|
|
305
|
-
const buyAt = buySegs.find((s) => s.startGM <= segStart && segStart < s.endGM);
|
|
306
|
-
const sellAt = sellSegs.find((s) => s.startGM <= segStart && segStart < s.endGM);
|
|
307
|
-
periods.push({
|
|
308
|
-
start: toDate(segStart),
|
|
309
|
-
end: toDate(segEnd),
|
|
310
|
-
buy: buyAt ? { price: lookupPrice(buyCharges, buyAt.seasonName, buyAt.periodName), periodName: buyAt.periodName, seasonName: buyAt.seasonName } : EMPTY_RATE,
|
|
311
|
-
sell: sellAt ? { price: lookupPrice(sellCharges, sellAt.seasonName, sellAt.periodName), periodName: sellAt.periodName, seasonName: sellAt.seasonName } : EMPTY_RATE,
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
return periods;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Resolves the current buy/sell time-of-use rate for a Tariff V2 object at a given instant.
|
|
319
|
-
* `tariff` carries no timezone; the caller must supply the site's IANA zone (e.g. from
|
|
320
|
-
* `site_info.installation_time_zone`) so wall-clock period boundaries match correctly.
|
|
321
|
-
*/
|
|
322
|
-
export function getTariffPeriods(tariff: TariffContentV2, now: Date, opts?: { timeZone: string; horizonHours?: number }): TariffResolution | null {
|
|
323
|
-
if (!tariff?.seasons || !tariff?.energy_charges) return null;
|
|
324
|
-
if (!opts?.timeZone) throw new Error("getTariffPeriods requires opts.timeZone");
|
|
325
|
-
const timeZone = opts.timeZone;
|
|
326
|
-
|
|
327
|
-
const wallClock = getWallClock(now, timeZone);
|
|
328
|
-
const buySchedule = scheduleAt(tariff.seasons, wallClock);
|
|
329
|
-
if (!buySchedule?.current) return null;
|
|
330
|
-
|
|
331
|
-
const sellSeasons = tariff.sell_tariff?.seasons ?? tariff.seasons;
|
|
332
|
-
const sellSchedule = tariff.sell_tariff ? scheduleAt(sellSeasons, wallClock) : null;
|
|
333
|
-
|
|
334
|
-
const buyRate: TariffRate = { price: lookupPrice(tariff.energy_charges, buySchedule.seasonName, buySchedule.current.periodName), periodName: buySchedule.current.periodName, seasonName: buySchedule.seasonName };
|
|
335
|
-
const sellRate: TariffRate = sellSchedule?.current
|
|
336
|
-
? { price: lookupPrice(tariff.sell_tariff!.energy_charges, sellSchedule.seasonName, sellSchedule.current.periodName), periodName: sellSchedule.current.periodName, seasonName: sellSchedule.seasonName }
|
|
337
|
-
: EMPTY_RATE;
|
|
338
|
-
|
|
339
|
-
// Boundaries are wall-clock minute deltas, so converting one back to an instant means
|
|
340
|
-
// re-deriving the target wall-clock label and reconverting *that*, not adding elapsed
|
|
341
|
-
// real minutes to `now` - the two differ across a DST transition.
|
|
342
|
-
const toDate = (gm: number): Date => {
|
|
343
|
-
const target = wallClockAt(wallClock, gm);
|
|
344
|
-
const hour = Math.floor(target.minuteOfDay / 60);
|
|
345
|
-
const minute = target.minuteOfDay % 60;
|
|
346
|
-
return new Date(wallClockToUtcMillis(target.year, target.month, target.day, hour, minute, timeZone));
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
// `scheduleAt` reports a next-boundary GM even for a grid that's currently in a gap (e.g. a
|
|
350
|
-
// sell/export window not open yet), so combining via the sell side's own next boundary - not
|
|
351
|
-
// skipping it just because sell has no active period right now - catches "sell starts" too.
|
|
352
|
-
const nextChangeGM = sellSchedule?.nextChangeGM != null ? Math.min(buySchedule.nextChangeGM!, sellSchedule.nextChangeGM) : buySchedule.nextChangeGM!;
|
|
353
|
-
|
|
354
|
-
// When buy and sell schedules differ, the interval the returned pair is valid for only began
|
|
355
|
-
// once BOTH sides' current *states* began - the later of the two, not just buy's. `sinceGM`
|
|
356
|
-
// covers sell being in a gap too (e.g. an export window that already closed), not only sell
|
|
357
|
-
// having its own active period. `buySchedule.sinceGM` is always non-null: buy is guaranteed to
|
|
358
|
-
// have an active `current` period at this point (checked above), and that branch always sets it.
|
|
359
|
-
const currentStartGM = sellSchedule?.sinceGM != null ? Math.max(buySchedule.sinceGM!, sellSchedule.sinceGM) : buySchedule.sinceGM!;
|
|
360
|
-
|
|
361
|
-
const resolution: TariffResolution = {
|
|
362
|
-
buy: buyRate,
|
|
363
|
-
sell: sellRate,
|
|
364
|
-
currentStart: toDate(currentStartGM),
|
|
365
|
-
nextChange: toDate(nextChangeGM),
|
|
366
|
-
currency: typeof tariff.currency === "string" ? tariff.currency : null,
|
|
367
|
-
upcoming: null,
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
if (opts.horizonHours) {
|
|
371
|
-
resolution.upcoming = buildUpcoming(tariff.seasons, tariff.energy_charges, sellSeasons, tariff.sell_tariff?.energy_charges, !!tariff.sell_tariff, wallClock, opts.horizonHours * 60, toDate);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return resolution;
|
|
375
|
-
}
|
package/src/teslafleetapi.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import Charging from "./charging.js";
|
|
2
|
-
import Energy from "./energy.js";
|
|
3
|
-
import Partner from "./partner.js";
|
|
4
|
-
import User from "./user.js";
|
|
5
|
-
import Vehicle from "./vehicle.js";
|
|
6
|
-
import {
|
|
7
|
-
EnergyProduct,
|
|
8
|
-
ProductsResponse,
|
|
9
|
-
VehicleProduct,
|
|
10
|
-
} from "./types/products.js";
|
|
11
|
-
|
|
12
|
-
type Region = "na" | "eu" | "cn";
|
|
13
|
-
type Method = "GET" | "POST" | "PUT" | "DELETE";
|
|
14
|
-
|
|
15
|
-
const servers: Record<Region, string> = {
|
|
16
|
-
na: "https://fleet-api.prd.na.vn.cloud.tesla.com",
|
|
17
|
-
eu: "https://fleet-api.prd.eu.vn.cloud.tesla.com",
|
|
18
|
-
cn: "https://fleet-api.prd.cn.vn.cloud.tesla.cn",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type ProductsByType = {
|
|
22
|
-
vehicles: VehicleProduct[];
|
|
23
|
-
energy_sites: EnergyProduct[];
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export default class TeslaFleetApi {
|
|
27
|
-
server: string | null = null;
|
|
28
|
-
accessToken: string | null;
|
|
29
|
-
charging?: Charging;
|
|
30
|
-
energy?: Energy;
|
|
31
|
-
partner?: Partner;
|
|
32
|
-
user?: User;
|
|
33
|
-
vehicle?: Vehicle;
|
|
34
|
-
debug: boolean = false;
|
|
35
|
-
|
|
36
|
-
constructor(options: {
|
|
37
|
-
accessToken?: string;
|
|
38
|
-
region?: Region;
|
|
39
|
-
server?: string;
|
|
40
|
-
chargingScope?: boolean;
|
|
41
|
-
energyScope?: boolean;
|
|
42
|
-
partnerScope?: boolean;
|
|
43
|
-
userScope?: boolean;
|
|
44
|
-
vehicleScope?: boolean;
|
|
45
|
-
debug?: boolean;
|
|
46
|
-
}) {
|
|
47
|
-
this.debug = !!options.debug;
|
|
48
|
-
this.accessToken = options.accessToken;
|
|
49
|
-
|
|
50
|
-
if (options.server) {
|
|
51
|
-
this.server = options.server;
|
|
52
|
-
} else if (options.region && options.region in servers) {
|
|
53
|
-
this.server = servers[options.region];
|
|
54
|
-
} else {
|
|
55
|
-
throw new Error("Either server or region must be provided.");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.debug && console.debug(`Using server ${this.server}`);
|
|
59
|
-
|
|
60
|
-
if (options.chargingScope !== false) {
|
|
61
|
-
this.charging = new Charging(this);
|
|
62
|
-
}
|
|
63
|
-
if (options.energyScope !== false) {
|
|
64
|
-
this.energy = new Energy(this);
|
|
65
|
-
}
|
|
66
|
-
if (options.userScope !== false) {
|
|
67
|
-
this.user = new User(this);
|
|
68
|
-
}
|
|
69
|
-
if (options.partnerScope !== false) {
|
|
70
|
-
this.partner = new Partner(this);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (options.vehicleScope !== false) {
|
|
74
|
-
this.vehicle = new Vehicle(this);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async _response(resp: Response) {
|
|
79
|
-
return {status: resp.status, data: await resp.json()};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Make a request to the Tesla Fleet API.
|
|
84
|
-
* @param method
|
|
85
|
-
* @param path
|
|
86
|
-
* @param params
|
|
87
|
-
* @param json
|
|
88
|
-
* @returns
|
|
89
|
-
*/
|
|
90
|
-
async _request(
|
|
91
|
-
method: Method,
|
|
92
|
-
path: string,
|
|
93
|
-
params: Record<string, any> | null = null,
|
|
94
|
-
json: Record<string, any> | null = null,
|
|
95
|
-
): Promise<any> {
|
|
96
|
-
if (!this.server) {
|
|
97
|
-
throw new Error("Server was not set at init. Call findServer() first.");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (method === "GET" && json !== null) {
|
|
101
|
-
throw new Error("GET requests cannot have a body.");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this.debug && console.debug(`Sending request to ${path}`);
|
|
105
|
-
|
|
106
|
-
// Remove null and undefined values from params and json
|
|
107
|
-
if (params) {
|
|
108
|
-
params = Object.fromEntries(
|
|
109
|
-
Object.entries(params).filter(([_, v]) => v != null),
|
|
110
|
-
);
|
|
111
|
-
this.debug && console.debug(`Parameters: ${JSON.stringify(params)}`);
|
|
112
|
-
}
|
|
113
|
-
if (json) {
|
|
114
|
-
json = Object.fromEntries(
|
|
115
|
-
Object.entries(json).filter(([_, v]) => v != null),
|
|
116
|
-
);
|
|
117
|
-
this.debug && console.debug(`Body: ${JSON.stringify(json)}`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const headers = {
|
|
121
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
122
|
-
"Content-Type": "application/json",
|
|
123
|
-
"X-Library": `node tesla_fleet_api`,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const query = params ? "?" + new URLSearchParams(params).toString() : "";
|
|
127
|
-
|
|
128
|
-
return fetch(`${this.server}/${path}${query}`, {
|
|
129
|
-
method,
|
|
130
|
-
headers,
|
|
131
|
-
body: json ? JSON.stringify(json) : null,
|
|
132
|
-
})
|
|
133
|
-
.then(this._response)
|
|
134
|
-
.then(
|
|
135
|
-
({status,data}) => {
|
|
136
|
-
if (status <= 299) return data;
|
|
137
|
-
return Promise.reject({ status, data });
|
|
138
|
-
},
|
|
139
|
-
(e) => Promise.reject({error: e})
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Returns products mapped to user.
|
|
145
|
-
* @returns An array of products including both vehicles and energy sites.
|
|
146
|
-
*/
|
|
147
|
-
async products(): Promise<ProductsResponse> {
|
|
148
|
-
return this._request("GET", "api/1/products").then(
|
|
149
|
-
({ response }) => response,
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Return Tesla products separated into vehicles and energy_sites
|
|
155
|
-
* @returns A dictionary of vehicles and energy sites, each with an array of those products
|
|
156
|
-
*/
|
|
157
|
-
async products_by_type(): Promise<ProductsByType> {
|
|
158
|
-
return this.products().then((products) => ({
|
|
159
|
-
vehicles: products.filter(
|
|
160
|
-
(product): product is VehicleProduct => "vin" in product,
|
|
161
|
-
),
|
|
162
|
-
energy_sites: products.filter(
|
|
163
|
-
(product): product is EnergyProduct => "energy_site_id" in product,
|
|
164
|
-
),
|
|
165
|
-
}));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async loadPrivateKey(path: string): Promise<void> {
|
|
169
|
-
// Try read file, if not create it
|
|
170
|
-
return (await import("fs")).promises.readFile(path, "utf8").then((key) => {
|
|
171
|
-
this.accessToken = key;
|
|
172
|
-
}
|
|
173
|
-
).catch(async () => {
|
|
174
|
-
// Create SECP256R1 private key and save it as a pem file at path
|
|
175
|
-
const { privateKey } = (await import("crypto")).generateKeyPairSync("ec", {
|
|
176
|
-
namedCurve: "secp256r1",
|
|
177
|
-
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
178
|
-
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
package/src/teslemetry.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import TeslaFleetApi from "./teslafleetapi.js";
|
|
2
|
-
import { Scope } from "./types/commands.js";
|
|
3
|
-
|
|
4
|
-
type Region = "na" | "eu" | "api";
|
|
5
|
-
|
|
6
|
-
type Test = { response: boolean };
|
|
7
|
-
|
|
8
|
-
type Metadata = {
|
|
9
|
-
uid: string;
|
|
10
|
-
region: "NA" | "EU";
|
|
11
|
-
scopes: Scope[];
|
|
12
|
-
vins: string[];
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default class Telemetry extends TeslaFleetApi {
|
|
16
|
-
constructor(accessToken: string, region: Region = "api") {
|
|
17
|
-
super({
|
|
18
|
-
accessToken,
|
|
19
|
-
server: `https://${region}.teslemetry.com`,
|
|
20
|
-
partnerScope: false,
|
|
21
|
-
userScope: false,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async _response(resp: Response) {
|
|
26
|
-
if (resp.headers.has("x-region")) {
|
|
27
|
-
const region = resp.headers.get("x-region")?.toLowerCase();
|
|
28
|
-
if (region) {
|
|
29
|
-
this.server = `https://${region}.teslemetry.com`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return super._response(resp);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Test the connection to Teslemetry
|
|
37
|
-
*/
|
|
38
|
-
async test(): Promise<Test> {
|
|
39
|
-
return this._request("GET", "/api/test").then(({ response }) => response);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get details about your Teslemetry account
|
|
44
|
-
* @param update_region Update the server URL based on the region in the metadata
|
|
45
|
-
*/
|
|
46
|
-
async metadata(update_region = true): Promise<Metadata> {
|
|
47
|
-
return this._request("GET", "/api/metadata").then((metadata) => {
|
|
48
|
-
if (update_region) {
|
|
49
|
-
this.server = `https://${metadata.region.toLowerCase()}.teslemetry.com`;
|
|
50
|
-
}
|
|
51
|
-
return metadata;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
package/src/tessie.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import TeslaFleetApi from "./teslafleetapi.js";
|
|
2
|
-
import { Scope } from "./types/commands.js";
|
|
3
|
-
import { VehicleDataResponse } from "./types/vehicle_data.js";
|
|
4
|
-
|
|
5
|
-
type TessieVehicleResponse = {
|
|
6
|
-
vin: string,
|
|
7
|
-
is_active: boolean,
|
|
8
|
-
last_state: VehicleDataResponse,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default class Telemetry extends TeslaFleetApi {
|
|
12
|
-
constructor(accessToken: string) {
|
|
13
|
-
super({ accessToken, server: `https://api.tessie.com`, partnerScope: false, userScope: false });
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Get your approved Tesla scopes
|
|
18
|
-
*/
|
|
19
|
-
async tesla_scopes(): Promise<Scope[]> {
|
|
20
|
-
return this._request("GET", "auth/tesla_scopes").then(({ scopes }) => scopes)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async metadata(): Promise<{ scopes: Scope[] }> {
|
|
24
|
-
return this._request("GET", "auth/tesla_scopes")
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async status(vin: string): Promise<"asleep" | "waiting_for_sleep" | "awake"> {
|
|
28
|
-
return this._request("GET", `${vin}/status`).then(({ status }) => status);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async state(vin: string, use_cache: boolean = true): Promise<VehicleDataResponse> {
|
|
32
|
-
return this._request("GET", `${vin}/state`, { use_cache });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async vehicles(only_active: boolean = false): Promise<TessieVehicleResponse[]> {
|
|
36
|
-
return this._request("GET", "vehicles", { only_active }).then(({ results }) => results);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async wake(vin: string): Promise<boolean> {
|
|
40
|
-
return this._request("POST", `${vin}/wake`).then(({ result }) => result);
|
|
41
|
-
}
|
|
42
|
-
}
|