tesla-fleet-api 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/README.md +284 -1
  2. package/dist/_virtual/_rolldown/runtime.cjs +32 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +12 -0
  4. package/dist/bluetooth/adapters/shared.cjs +38 -0
  5. package/dist/bluetooth/adapters/shared.mjs +36 -0
  6. package/dist/bluetooth/async.cjs +121 -0
  7. package/dist/bluetooth/async.d.cts +10 -0
  8. package/dist/bluetooth/async.d.mts +10 -0
  9. package/dist/bluetooth/async.mjs +116 -0
  10. package/dist/bluetooth/broadcast.cjs +153 -0
  11. package/dist/bluetooth/broadcast.d.cts +59 -0
  12. package/dist/bluetooth/broadcast.d.mts +59 -0
  13. package/dist/bluetooth/broadcast.mjs +151 -0
  14. package/dist/bluetooth/constants.cjs +99 -0
  15. package/dist/bluetooth/constants.d.cts +70 -0
  16. package/dist/bluetooth/constants.d.mts +70 -0
  17. package/dist/bluetooth/constants.mjs +72 -0
  18. package/dist/bluetooth/esphome.cjs +292 -0
  19. package/dist/bluetooth/esphome.d.cts +83 -0
  20. package/dist/bluetooth/esphome.d.mts +83 -0
  21. package/dist/bluetooth/esphome.mjs +291 -0
  22. package/dist/bluetooth/framing.cjs +125 -0
  23. package/dist/bluetooth/framing.d.cts +45 -0
  24. package/dist/bluetooth/framing.d.mts +45 -0
  25. package/dist/bluetooth/framing.mjs +122 -0
  26. package/dist/bluetooth/homey.cjs +155 -0
  27. package/dist/bluetooth/homey.d.cts +75 -0
  28. package/dist/bluetooth/homey.d.mts +75 -0
  29. package/dist/bluetooth/homey.mjs +150 -0
  30. package/dist/bluetooth/names.cjs +24 -0
  31. package/dist/bluetooth/names.d.cts +10 -0
  32. package/dist/bluetooth/names.d.mts +10 -0
  33. package/dist/bluetooth/names.mjs +20 -0
  34. package/dist/bluetooth/noble.cjs +178 -0
  35. package/dist/bluetooth/noble.d.cts +58 -0
  36. package/dist/bluetooth/noble.d.mts +58 -0
  37. package/dist/bluetooth/noble.mjs +177 -0
  38. package/dist/bluetooth/streamglue.cjs +157 -0
  39. package/dist/bluetooth/streamglue.d.cts +37 -0
  40. package/dist/bluetooth/streamglue.d.mts +37 -0
  41. package/dist/bluetooth/streamglue.mjs +154 -0
  42. package/dist/bluetooth/teslabluetooth.cjs +67 -0
  43. package/dist/bluetooth/teslabluetooth.d.cts +41 -0
  44. package/dist/bluetooth/teslabluetooth.d.mts +41 -0
  45. package/dist/bluetooth/teslabluetooth.mjs +66 -0
  46. package/dist/bluetooth/transport.cjs +10 -0
  47. package/dist/bluetooth/transport.d.cts +95 -0
  48. package/dist/bluetooth/transport.d.mts +95 -0
  49. package/dist/bluetooth/transport.mjs +10 -0
  50. package/dist/bluetooth/vehiclebluetooth.cjs +1272 -0
  51. package/dist/bluetooth/vehiclebluetooth.d.cts +495 -0
  52. package/dist/bluetooth/vehiclebluetooth.d.mts +495 -0
  53. package/dist/bluetooth/vehiclebluetooth.mjs +1270 -0
  54. package/dist/bluetooth/verify.cjs +93 -0
  55. package/dist/bluetooth/verify.d.cts +35 -0
  56. package/dist/bluetooth/verify.d.mts +35 -0
  57. package/dist/bluetooth/verify.mjs +91 -0
  58. package/dist/bluetooth.cjs +53 -0
  59. package/dist/bluetooth.d.cts +10 -0
  60. package/dist/bluetooth.d.mts +10 -0
  61. package/dist/bluetooth.mjs +9 -0
  62. package/dist/charging.cjs +53 -0
  63. package/dist/charging.d.cts +31 -0
  64. package/dist/charging.d.mts +30 -0
  65. package/dist/charging.mjs +53 -0
  66. package/dist/commands.cjs +1797 -0
  67. package/dist/commands.d.cts +881 -0
  68. package/dist/commands.d.mts +881 -0
  69. package/dist/commands.mjs +1791 -0
  70. package/dist/const.cjs +322 -0
  71. package/dist/const.d.cts +308 -0
  72. package/dist/const.d.mts +308 -0
  73. package/dist/const.mjs +282 -0
  74. package/dist/energy.cjs +142 -0
  75. package/dist/energy.d.cts +101 -0
  76. package/dist/energy.d.mts +100 -0
  77. package/dist/energy.mjs +142 -0
  78. package/dist/energyisland.cjs +38 -0
  79. package/dist/energyisland.mjs +37 -0
  80. package/dist/energyparsers.cjs +118 -0
  81. package/dist/energyparsers.d.cts +39 -0
  82. package/dist/energyparsers.d.mts +39 -0
  83. package/dist/energyparsers.mjs +116 -0
  84. package/dist/energyspecific.cjs +457 -0
  85. package/dist/energyspecific.d.cts +258 -0
  86. package/dist/energyspecific.d.mts +258 -0
  87. package/dist/energyspecific.mjs +451 -0
  88. package/dist/exceptions.cjs +1488 -0
  89. package/dist/exceptions.d.cts +1143 -0
  90. package/dist/exceptions.d.mts +1143 -0
  91. package/dist/exceptions.mjs +1325 -0
  92. package/dist/funnel.cjs +297 -0
  93. package/dist/funnel.d.cts +118 -0
  94. package/dist/funnel.d.mts +118 -0
  95. package/dist/funnel.mjs +292 -0
  96. package/dist/index.cjs +287 -0
  97. package/dist/index.d.cts +28 -0
  98. package/dist/index.d.mts +28 -0
  99. package/dist/index.mjs +27 -0
  100. package/dist/log.cjs +75 -0
  101. package/dist/log.d.cts +4 -0
  102. package/dist/log.d.mts +4 -0
  103. package/dist/log.mjs +71 -0
  104. package/dist/oauth.cjs +143 -0
  105. package/dist/oauth.d.cts +69 -0
  106. package/dist/oauth.d.mts +69 -0
  107. package/dist/oauth.mjs +143 -0
  108. package/dist/partner.cjs +32 -0
  109. package/dist/partner.d.cts +24 -0
  110. package/dist/partner.d.mts +23 -0
  111. package/dist/partner.mjs +32 -0
  112. package/dist/powerwall/client.cjs +818 -0
  113. package/dist/powerwall/client.d.cts +297 -0
  114. package/dist/powerwall/client.d.mts +297 -0
  115. package/dist/powerwall/client.mjs +807 -0
  116. package/dist/powerwall/components.cjs +188 -0
  117. package/dist/powerwall/components.d.cts +45 -0
  118. package/dist/powerwall/components.d.mts +45 -0
  119. package/dist/powerwall/components.mjs +182 -0
  120. package/dist/powerwall/energysite.cjs +216 -0
  121. package/dist/powerwall/energysite.d.cts +104 -0
  122. package/dist/powerwall/energysite.d.mts +104 -0
  123. package/dist/powerwall/energysite.mjs +214 -0
  124. package/dist/powerwall/exceptions.cjs +59 -0
  125. package/dist/powerwall/exceptions.d.cts +38 -0
  126. package/dist/powerwall/exceptions.d.mts +38 -0
  127. package/dist/powerwall/exceptions.mjs +51 -0
  128. package/dist/powerwall/gateway.cjs +102 -0
  129. package/dist/powerwall/gateway.d.cts +57 -0
  130. package/dist/powerwall/gateway.d.mts +57 -0
  131. package/dist/powerwall/gateway.mjs +101 -0
  132. package/dist/powerwall/merge.cjs +163 -0
  133. package/dist/powerwall/merge.d.cts +63 -0
  134. package/dist/powerwall/merge.d.mts +63 -0
  135. package/dist/powerwall/merge.mjs +159 -0
  136. package/dist/powerwall/models.d.cts +95 -0
  137. package/dist/powerwall/models.d.mts +95 -0
  138. package/dist/powerwall/queries.cjs +17 -0
  139. package/dist/powerwall/queries.mjs +10 -0
  140. package/dist/powerwall/transport.cjs +232 -0
  141. package/dist/powerwall/transport.mjs +227 -0
  142. package/dist/powerwall.cjs +47 -0
  143. package/dist/powerwall.d.cts +9 -0
  144. package/dist/powerwall.d.mts +9 -0
  145. package/dist/powerwall.mjs +8 -0
  146. package/dist/router/base.cjs +203 -0
  147. package/dist/router/base.d.cts +112 -0
  148. package/dist/router/base.d.mts +112 -0
  149. package/dist/router/base.mjs +200 -0
  150. package/dist/router/energysite.cjs +65 -0
  151. package/dist/router/energysite.d.cts +47 -0
  152. package/dist/router/energysite.d.mts +47 -0
  153. package/dist/router/energysite.mjs +60 -0
  154. package/dist/router.cjs +13 -0
  155. package/dist/router.d.cts +3 -0
  156. package/dist/router.d.mts +3 -0
  157. package/dist/router.mjs +3 -0
  158. package/dist/signing/crypto.cjs +59 -0
  159. package/dist/signing/crypto.mjs +52 -0
  160. package/dist/signing/energy.cjs +123 -0
  161. package/dist/signing/energy.d.cts +45 -0
  162. package/dist/signing/energy.d.mts +45 -0
  163. package/dist/signing/energy.mjs +120 -0
  164. package/dist/signing/jws.cjs +229 -0
  165. package/dist/signing/jws.d.cts +45 -0
  166. package/dist/signing/jws.d.mts +45 -0
  167. package/dist/signing/jws.mjs +211 -0
  168. package/dist/signing/keys.cjs +191 -0
  169. package/dist/signing/keys.d.cts +21 -0
  170. package/dist/signing/keys.d.mts +21 -0
  171. package/dist/signing/keys.mjs +182 -0
  172. package/dist/signing/session.cjs +186 -0
  173. package/dist/signing/session.d.cts +106 -0
  174. package/dist/signing/session.d.mts +106 -0
  175. package/dist/signing/session.mjs +184 -0
  176. package/dist/tariff.cjs +319 -0
  177. package/dist/tariff.d.cts +40 -0
  178. package/dist/tariff.d.mts +40 -0
  179. package/dist/tariff.mjs +317 -0
  180. package/dist/teslafleetapi.cjs +326 -0
  181. package/dist/teslafleetapi.d.cts +160 -0
  182. package/dist/teslafleetapi.d.mts +160 -0
  183. package/dist/teslafleetapi.mjs +326 -0
  184. package/dist/teslemetry.cjs +183 -0
  185. package/dist/teslemetry.d.cts +113 -0
  186. package/dist/teslemetry.d.mts +113 -0
  187. package/dist/teslemetry.mjs +181 -0
  188. package/dist/teslemetryenergy.cjs +287 -0
  189. package/dist/teslemetryenergy.d.cts +154 -0
  190. package/dist/teslemetryenergy.d.mts +154 -0
  191. package/dist/teslemetryenergy.mjs +282 -0
  192. package/dist/teslemetryvehicle.cjs +407 -0
  193. package/dist/teslemetryvehicle.d.cts +238 -0
  194. package/dist/teslemetryvehicle.d.mts +238 -0
  195. package/dist/teslemetryvehicle.mjs +405 -0
  196. package/dist/tessie.cjs +71 -0
  197. package/dist/tessie.d.cts +69 -0
  198. package/dist/tessie.d.mts +69 -0
  199. package/dist/tessie.mjs +71 -0
  200. package/dist/tessievehicle.cjs +514 -0
  201. package/dist/tessievehicle.d.cts +333 -0
  202. package/dist/tessievehicle.d.mts +333 -0
  203. package/dist/tessievehicle.mjs +513 -0
  204. package/dist/types/commands.d.cts +28 -0
  205. package/dist/types/commands.d.mts +28 -0
  206. package/dist/types/live_status.d.cts +30 -0
  207. package/dist/types/live_status.d.mts +30 -0
  208. package/dist/types/products.d.cts +58 -0
  209. package/dist/types/products.d.mts +58 -0
  210. package/dist/types/responses.d.cts +13 -0
  211. package/dist/types/responses.d.mts +13 -0
  212. package/dist/types/site_info.d.cts +154 -0
  213. package/dist/types/site_info.d.mts +154 -0
  214. package/dist/types/vehicle.d.cts +33 -0
  215. package/dist/types/vehicle.d.mts +33 -0
  216. package/dist/types/vehicle_data.d.cts +278 -0
  217. package/dist/types/vehicle_data.d.mts +278 -0
  218. package/dist/types.cjs +0 -0
  219. package/dist/types.d.cts +9 -0
  220. package/dist/types.d.mts +9 -0
  221. package/dist/types.mjs +1 -0
  222. package/dist/user.cjs +28 -0
  223. package/dist/user.d.cts +17 -0
  224. package/dist/user.d.mts +16 -0
  225. package/dist/user.mjs +28 -0
  226. package/dist/util.cjs +41 -0
  227. package/dist/util.d.cts +18 -0
  228. package/dist/util.d.mts +18 -0
  229. package/dist/util.mjs +40 -0
  230. package/dist/vehicle.cjs +847 -0
  231. package/dist/vehicle.d.cts +566 -0
  232. package/dist/vehicle.d.mts +565 -0
  233. package/dist/vehicle.mjs +847 -0
  234. package/dist/vehiclesigned.cjs +35 -0
  235. package/dist/vehiclesigned.d.cts +23 -0
  236. package/dist/vehiclesigned.d.mts +22 -0
  237. package/dist/vehiclesigned.mjs +35 -0
  238. package/dist/vehiclespecific.cjs +715 -0
  239. package/dist/vehiclespecific.d.cts +497 -0
  240. package/dist/vehiclespecific.d.mts +496 -0
  241. package/dist/vehiclespecific.mjs +715 -0
  242. package/package.json +178 -38
  243. package/dist/charging.d.ts +0 -30
  244. package/dist/charging.js +0 -51
  245. package/dist/charging.js.map +0 -1
  246. package/dist/commands.d.ts +0 -352
  247. package/dist/commands.js +0 -875
  248. package/dist/commands.js.map +0 -1
  249. package/dist/energy.d.ts +0 -94
  250. package/dist/energy.js +0 -125
  251. package/dist/energy.js.map +0 -1
  252. package/dist/energyspecific.d.ts +0 -77
  253. package/dist/energyspecific.js +0 -97
  254. package/dist/energyspecific.js.map +0 -1
  255. package/dist/helpers.d.ts +0 -2
  256. package/dist/helpers.js +0 -10
  257. package/dist/helpers.js.map +0 -1
  258. package/dist/index.d.ts +0 -15
  259. package/dist/index.js +0 -15
  260. package/dist/index.js.map +0 -1
  261. package/dist/partner.d.ts +0 -23
  262. package/dist/partner.js +0 -31
  263. package/dist/partner.js.map +0 -1
  264. package/dist/signing/crypto.d.ts +0 -10
  265. package/dist/signing/crypto.js +0 -26
  266. package/dist/signing/crypto.js.map +0 -1
  267. package/dist/signing/errors.d.ts +0 -29
  268. package/dist/signing/errors.js +0 -40
  269. package/dist/signing/errors.js.map +0 -1
  270. package/dist/signing/session.d.ts +0 -69
  271. package/dist/signing/session.js +0 -102
  272. package/dist/signing/session.js.map +0 -1
  273. package/dist/tariff.d.ts +0 -29
  274. package/dist/tariff.js +0 -302
  275. package/dist/tariff.js.map +0 -1
  276. package/dist/teslafleetapi.d.ts +0 -58
  277. package/dist/teslafleetapi.js +0 -120
  278. package/dist/teslafleetapi.js.map +0 -1
  279. package/dist/teslemetry.d.ts +0 -29
  280. package/dist/teslemetry.js +0 -39
  281. package/dist/teslemetry.js.map +0 -1
  282. package/dist/tessie.d.ts +0 -23
  283. package/dist/tessie.js +0 -28
  284. package/dist/tessie.js.map +0 -1
  285. package/dist/types/commands.d.ts +0 -44
  286. package/dist/types/commands.js +0 -11
  287. package/dist/types/commands.js.map +0 -1
  288. package/dist/types/live_status.d.ts +0 -26
  289. package/dist/types/live_status.js +0 -2
  290. package/dist/types/live_status.js.map +0 -1
  291. package/dist/types/products.d.ts +0 -54
  292. package/dist/types/products.js +0 -2
  293. package/dist/types/products.js.map +0 -1
  294. package/dist/types/responses.d.ts +0 -5
  295. package/dist/types/responses.js +0 -2
  296. package/dist/types/responses.js.map +0 -1
  297. package/dist/types/site_info.d.ts +0 -150
  298. package/dist/types/site_info.js +0 -2
  299. package/dist/types/site_info.js.map +0 -1
  300. package/dist/types/vehicle.d.ts +0 -23
  301. package/dist/types/vehicle.js +0 -10
  302. package/dist/types/vehicle.js.map +0 -1
  303. package/dist/types/vehicle_data.d.ts +0 -274
  304. package/dist/types/vehicle_data.js +0 -2
  305. package/dist/types/vehicle_data.js.map +0 -1
  306. package/dist/user.d.ts +0 -16
  307. package/dist/user.js +0 -26
  308. package/dist/user.js.map +0 -1
  309. package/dist/vehicle.d.ts +0 -548
  310. package/dist/vehicle.js +0 -774
  311. package/dist/vehicle.js.map +0 -1
  312. package/dist/vehiclesigned.d.ts +0 -13
  313. package/dist/vehiclesigned.js +0 -19
  314. package/dist/vehiclesigned.js.map +0 -1
  315. package/dist/vehiclespecific.d.ts +0 -432
  316. package/dist/vehiclespecific.js +0 -601
  317. package/dist/vehiclespecific.js.map +0 -1
  318. package/src/charging.ts +0 -66
  319. package/src/commands.ts +0 -1134
  320. package/src/energy.ts +0 -217
  321. package/src/energyspecific.ts +0 -116
  322. package/src/helpers.ts +0 -11
  323. package/src/index.ts +0 -21
  324. package/src/partner.ts +0 -37
  325. package/src/signing/crypto.ts +0 -29
  326. package/src/signing/errors.ts +0 -50
  327. package/src/signing/session.ts +0 -132
  328. package/src/tariff.ts +0 -375
  329. package/src/teslafleetapi.ts +0 -182
  330. package/src/teslemetry.ts +0 -54
  331. package/src/tessie.ts +0 -42
  332. package/src/types/commands.ts +0 -62
  333. package/src/types/live_status.ts +0 -27
  334. package/src/types/products.ts +0 -61
  335. package/src/types/responses.ts +0 -1
  336. package/src/types/site_info.ts +0 -159
  337. package/src/types/vehicle.ts +0 -33
  338. package/src/types/vehicle_data.ts +0 -286
  339. package/src/user.ts +0 -35
  340. package/src/vehicle.ts +0 -886
  341. package/src/vehiclesigned.ts +0 -20
  342. package/src/vehiclespecific.ts +0 -818
@@ -0,0 +1,847 @@
1
+ import { AutoSeat, ClimateModes, DEFAULT_LOCALE, Models, Seats } from "./const.mjs";
2
+ import { VehicleOffline } from "./exceptions.mjs";
3
+ import VehicleSpecific from "./vehiclespecific.mjs";
4
+ import VehicleSigned from "./vehiclesigned.mjs";
5
+ // src/vehicle.ts
6
+ const WAKE_TIMEOUT_MS = 6e4;
7
+ const WAKE_POLL_MS = 5e3;
8
+ var Vehicle = class {
9
+ /** Class `createFleet` instantiates; a subclass overrides it to supply its own vehicle type. */
10
+ static Fleet = VehicleSpecific;
11
+ /** Class `createSigned` instantiates; a subclass overrides it to supply its own signed vehicle type. */
12
+ static Signed = VehicleSigned;
13
+ parent;
14
+ #privateKey;
15
+ /** Every vehicle created by this factory, keyed by VIN; the latest `create*` call for a VIN wins. */
16
+ byVin = /* @__PURE__ */ new Map();
17
+ constructor(parent) {
18
+ this.parent = parent;
19
+ }
20
+ /** Fallback private key for `createSigned()` when a call site doesn't pass one explicitly. */
21
+ get private_key() {
22
+ return this.#privateKey;
23
+ }
24
+ set private_key(key) {
25
+ this.#privateKey = key;
26
+ }
27
+ /**
28
+ * Creates a Fleet API vehicle that sends plaintext REST commands.
29
+ * @param vin
30
+ * @returns
31
+ */
32
+ createFleet(vin) {
33
+ const vehicle = new this.constructor.Fleet(this, vin);
34
+ this.byVin.set(vin, vehicle);
35
+ return vehicle;
36
+ }
37
+ /**
38
+ * Creates a Fleet API vehicle that signs commands with the Tesla Vehicle
39
+ * Command Protocol and dispatches them through the `/signed_command`
40
+ * endpoint, instead of the plaintext REST commands.
41
+ * @param vin
42
+ * @param private_key Raw 32-byte P-256 private key scalar. Falls back to `this.private_key`, then the client's `private_key`. `false` disables signing.
43
+ * @param public_key Uncompressed P-256 public key point. Derived from `private_key` if omitted.
44
+ */
45
+ createSigned(vin, private_key, public_key) {
46
+ const vehicle = new this.constructor.Signed(this, vin, private_key, public_key);
47
+ this.byVin.set(vin, vehicle);
48
+ return vehicle;
49
+ }
50
+ /** Legacy name for `createFleet`. */
51
+ specific(vin) {
52
+ return this.createFleet(vin);
53
+ }
54
+ /** Legacy name for `createSigned`. */
55
+ specificSigned(vin, private_key, public_key) {
56
+ return this.createSigned(vin, private_key, public_key);
57
+ }
58
+ /**
59
+ * Return the vehicle model name
60
+ * @param vin
61
+ * @returns
62
+ */
63
+ model(vin) {
64
+ return Models?.[vin[3]] || "Unknown";
65
+ }
66
+ /**
67
+ * Return if the vehicle was build before 2021 and cannot sleep without a break
68
+ * @param vin
69
+ * @returns
70
+ */
71
+ pre2021(vin) {
72
+ return (vin[3] === "S" || vin[3] === "X") && vin[9] < "L";
73
+ }
74
+ /**
75
+ * Controls the front (which_trunk: "front") or rear (which_trunk: "rear") trunk.
76
+ * @param vehicle_tag VIN or id field of a vehicle
77
+ * @param which_trunk "front" or "rear"
78
+ */
79
+ async actuate_trunk(vehicle_tag, which_trunk) {
80
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/actuate_trunk`, null, { which_trunk });
81
+ }
82
+ /**
83
+ * Adjusts vehicle media playback volume.
84
+ * @param vehicle_tag VIN or id field of a vehicle
85
+ * @param volume A floating point number from 0.0 to 11.0.
86
+ */
87
+ async adjust_volume(vehicle_tag, volume) {
88
+ if (volume < 0 || volume > 11) throw new Error("Volume must a number from 0.0 to 11.0");
89
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/adjust_volume`, null, { volume });
90
+ }
91
+ /**
92
+ * Starts climate preconditioning.
93
+ * @param vehicle_tag VIN or id field of a vehicle
94
+ */
95
+ async auto_conditioning_start(vehicle_tag) {
96
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/auto_conditioning_start`);
97
+ }
98
+ /**
99
+ * Stops climate preconditioning.
100
+ * @param vehicle_tag VIN or id field of a vehicle
101
+ */
102
+ async auto_conditioning_stop(vehicle_tag) {
103
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/auto_conditioning_stop`);
104
+ }
105
+ /**
106
+ * Cancels the countdown to install the vehicle software update.
107
+ * @param vehicle_tag VIN or id field of a vehicle
108
+ */
109
+ async cancel_software_update(vehicle_tag) {
110
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/cancel_software_update`);
111
+ }
112
+ /**
113
+ * Charges in max range mode -- we recommend limiting the use of this mode to long trips.
114
+ * @param vehicle_tag VIN or id field of a vehicle
115
+ */
116
+ async charge_max_range(vehicle_tag) {
117
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/charge_max_range`);
118
+ }
119
+ /**
120
+ * Closes the charge port door.
121
+ * @param vehicle_tag VIN or id field of a vehicle
122
+ */
123
+ async charge_port_door_close(vehicle_tag) {
124
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/charge_port_door_close`);
125
+ }
126
+ /**
127
+ * Opens the charge port door.
128
+ * @param vehicle_tag VIN or id field of a vehicle
129
+ */
130
+ async charge_port_door_open(vehicle_tag) {
131
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/charge_port_door_open`);
132
+ }
133
+ /**
134
+ * Charges in Standard mode.
135
+ * @param vehicle_tag VIN or id field of a vehicle
136
+ */
137
+ async charge_standard(vehicle_tag) {
138
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/charge_standard`);
139
+ }
140
+ /**
141
+ * Starts charging the vehicle.
142
+ * @param vehicle_tag VIN or id field of a vehicle
143
+ */
144
+ async charge_start(vehicle_tag) {
145
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/charge_start`);
146
+ }
147
+ /**
148
+ * Stops charging the vehicle.
149
+ * @param vehicle_tag VIN or id field of a vehicle
150
+ */
151
+ async charge_stop(vehicle_tag) {
152
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/charge_stop`);
153
+ }
154
+ /**
155
+ * Deactivates PIN to Drive and resets the associated PIN for vehicles running firmware versions 2023.44+. This command is only accessible to fleet managers or owners.
156
+ * @param vehicle_tag VIN or id field of a vehicle
157
+ * @param pin Optional four-digit PIN
158
+ */
159
+ async clear_pin_to_drive_admin(vehicle_tag, pin) {
160
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/clear_pin_to_drive_admin`, null, { pin: pin == null ? void 0 : String(pin) });
161
+ }
162
+ /**
163
+ * Locks the vehicle.
164
+ * @param vehicle_tag VIN or id field of a vehicle
165
+ */
166
+ async door_lock(vehicle_tag) {
167
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/door_lock`);
168
+ }
169
+ /**
170
+ * Unlocks the vehicle.
171
+ * @param vehicle_tag VIN or id field of a vehicle
172
+ */
173
+ async door_unlock(vehicle_tag) {
174
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/door_unlock`);
175
+ }
176
+ /**
177
+ * Erases user's data from the user interface. Requires the vehicle to be in park.
178
+ * @param vehicle_tag VIN or id field of a vehicle
179
+ */
180
+ async erase_user_data(vehicle_tag) {
181
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/erase_user_data`);
182
+ }
183
+ /**
184
+ * Briefly flashes the vehicle headlights. Requires the vehicle to be in park.
185
+ * @param vehicle_tag VIN or id field of a vehicle
186
+ */
187
+ async flash_lights(vehicle_tag) {
188
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/flash_lights`);
189
+ }
190
+ /**
191
+ * Restricts certain vehicle UI functionality from guest users
192
+ * @param vehicle_tag VIN or id field of a vehicle
193
+ * @param enable `true` or `false`
194
+ */
195
+ async guest_mode(vehicle_tag, enable) {
196
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/guest_mode`, null, { enable });
197
+ }
198
+ /**
199
+ * Honks the vehicle horn. Requires the vehicle to be in park.
200
+ * @param vehicle_tag VIN or id field of a vehicle
201
+ */
202
+ async honk_horn(vehicle_tag) {
203
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/honk_horn`);
204
+ }
205
+ /**
206
+ * Advances media player to next favorite track.
207
+ * @param vehicle_tag VIN or id field of a vehicle
208
+ */
209
+ async media_next_fav(vehicle_tag) {
210
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/media_next_fav`);
211
+ }
212
+ /**
213
+ * Advances media player to next track.
214
+ * @param vehicle_tag VIN or id field of a vehicle
215
+ */
216
+ async media_next_track(vehicle_tag) {
217
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/media_next_track`);
218
+ }
219
+ /**
220
+ * Advances media player to previous favorite track.
221
+ * @param vehicle_tag VIN or id field of a vehicle
222
+ */
223
+ async media_prev_fav(vehicle_tag) {
224
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/media_prev_fav`);
225
+ }
226
+ /**
227
+ * Advances media player to previous track.
228
+ * @param vehicle_tag VIN or id field of a vehicle
229
+ */
230
+ async media_prev_track(vehicle_tag) {
231
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/media_prev_track`);
232
+ }
233
+ /**
234
+ * Toggles current play/pause state.
235
+ * @param vehicle_tag VIN or id field of a vehicle
236
+ */
237
+ async media_toggle_playback(vehicle_tag) {
238
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/media_toggle_playback`);
239
+ }
240
+ /**
241
+ * Turns the volume down by one.
242
+ * @param vehicle_tag VIN or id field of a vehicle
243
+ */
244
+ async media_volume_down(vehicle_tag) {
245
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/media_volume_down`);
246
+ }
247
+ /**
248
+ * Start navigation to given coordinates. Order can be used to specify order of multiple stops.
249
+ * @param vehicle_tag VIN or id field of a vehicle
250
+ * @param lat Latitude
251
+ * @param lon Longitude
252
+ * @param order Order of multiple stops
253
+ */
254
+ async navigation_gps_request(vehicle_tag, lat, lon, order = 0) {
255
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/navigation_gps_request`, null, {
256
+ lat,
257
+ lon,
258
+ order
259
+ });
260
+ }
261
+ /**
262
+ * Sends a location to the in-vehicle navigation system.
263
+ * @param vehicle_tag VIN or id field of a vehicle
264
+ * @param value Destination text
265
+ * @param type "share_ext_content_raw"
266
+ * @param locale ISO locale such as "en-US". Defaults to `DEFAULT_LOCALE`.
267
+ * @param timestamp_ms Defaults to now
268
+ */
269
+ async navigation_request(vehicle_tag, value, type = "share_ext_content_raw", locale, timestamp_ms) {
270
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/navigation_request`, null, {
271
+ value: { "android.intent.extra.TEXT": value },
272
+ type,
273
+ locale: locale || DEFAULT_LOCALE,
274
+ timestamp_ms: timestamp_ms || Date.now()
275
+ });
276
+ }
277
+ /**
278
+ * Start navigation to a supercharger.
279
+ * @param vehicle_tag VIN or id field of a vehicle
280
+ * @param id Supercharger ID
281
+ * @param order Order of multiple stops
282
+ * @returns
283
+ */
284
+ async navigation_sc_request(vehicle_tag, id, order) {
285
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/navigation_sc_request`, null, {
286
+ id,
287
+ order
288
+ });
289
+ }
290
+ /**
291
+ * Sets automatic seat heating and cooling.
292
+ * @param vehicle_tag VIN or id field of a vehicle
293
+ * @param auto_seat_position `AutoSeat` position (1-indexed: front left is 1, front right is 2)
294
+ * @param auto_climate_on `true` or `false`
295
+ */
296
+ async remote_auto_seat_climate_request(vehicle_tag, auto_seat_position, auto_climate_on) {
297
+ if (typeof auto_seat_position === "string") auto_seat_position = AutoSeat[auto_seat_position];
298
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/remote_auto_seat_climate_request`, null, {
299
+ auto_seat_position,
300
+ auto_climate_on
301
+ });
302
+ }
303
+ /**
304
+ * Sets automatic steering wheel heating on/off.
305
+ * @param vehicle_tag VIN or id field of a vehicle
306
+ * @param on `true` or `false`
307
+ */
308
+ async remote_auto_steering_wheel_heat_climate_request(vehicle_tag, on) {
309
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/remote_auto_steering_wheel_heat_climate_request`, null, { on });
310
+ }
311
+ /**
312
+ * Plays a sound through the vehicle external speaker.
313
+ * @param vehicle_tag VIN or id field of a vehicle
314
+ * @param sound Fart is `0`, Locate ping is `2000`
315
+ */
316
+ async remote_boombox(vehicle_tag, sound = 0) {
317
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/remote_boombox`, null, { sound });
318
+ }
319
+ /**
320
+ * Sets seat cooling.
321
+ * @param vehicle_tag VIN or id field of a vehicle
322
+ * @param seat_position Seat position
323
+ * @param seat_cooler_level Cooling level
324
+ */
325
+ async remote_seat_cooler_request(vehicle_tag, seat_position, seat_cooler_level) {
326
+ if (typeof seat_position === "string") seat_position = AutoSeat[seat_position];
327
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/remote_seat_cooler_request`, null, {
328
+ seat_position,
329
+ seat_cooler_level
330
+ });
331
+ }
332
+ /**
333
+ * Sets seat heating.
334
+ * @param vehicle_tag VIN or id field of a vehicle
335
+ * @param seat_position Seat position
336
+ * @param seat_heater_level Heating level
337
+ */
338
+ async remote_seat_heater_request(vehicle_tag, seat_position, seat_heater_level) {
339
+ if (typeof seat_position === "string") seat_position = Seats[seat_position];
340
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/remote_seat_heater_request`, null, {
341
+ heater: seat_position,
342
+ level: seat_heater_level
343
+ });
344
+ }
345
+ /**
346
+ * Starts the vehicle remotely. Requires keyless driving to be enabled.
347
+ * @param vehicle_tag VIN or id field of a vehicle
348
+ */
349
+ async remote_start_drive(vehicle_tag) {
350
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/remote_start_drive`);
351
+ }
352
+ /**
353
+ * Sets steering wheel heat level.
354
+ * @param vehicle_tag VIN or id field of a vehicle
355
+ * @param level Heating level
356
+ */
357
+ async remote_steering_wheel_heat_level_request(vehicle_tag, level) {
358
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/remote_steering_wheel_heat_level_request`, null, { level });
359
+ }
360
+ /**
361
+ * Sets steering wheel heating on/off. For vehicles that do not support auto steering wheel heat.
362
+ * @param vehicle_tag VIN or id field of a vehicle
363
+ * @param on `true` or `false`
364
+ */
365
+ async remote_steering_wheel_heater_request(vehicle_tag, on) {
366
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/remote_steering_wheel_heater_request`, null, { on });
367
+ }
368
+ /**
369
+ * Removes PIN to Drive. Requires the car to be in Pin to Drive mode and not in Valet mode. Note that this only works if PIN to Drive is not active. This command also requires the Tesla Vehicle Command Protocol - for more information, please see refer to the documentation here.
370
+ * @param vehicle_tag VIN or id field of a vehicle
371
+ */
372
+ async reset_pin_to_drive_pin(vehicle_tag) {
373
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/reset_pin_to_drive_pin`);
374
+ }
375
+ /**
376
+ * Removes PIN for Valet Mode.
377
+ * @param vehicle_tag VIN or id field of a vehicle
378
+ */
379
+ async reset_valet_pin(vehicle_tag) {
380
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/reset_valet_pin`);
381
+ }
382
+ /**
383
+ * Schedules a vehicle software update (over the air "OTA") to be installed in the future.
384
+ * @param vehicle_tag VIN or id field of a vehicle
385
+ * @param offset_sec Offset in seconds
386
+ */
387
+ async schedule_software_update(vehicle_tag, offset_sec) {
388
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/schedule_software_update`, null, { offset_sec });
389
+ }
390
+ /**
391
+ * Turns Bioweapon Defense Mode on and off.
392
+ * @param vehicle_tag VIN or id field of a vehicle
393
+ * @param on `true` or `false`
394
+ * @param manual_override `true` or `false`
395
+ */
396
+ async set_bioweapon_mode(vehicle_tag, on, manual_override) {
397
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_bioweapon_mode`, null, {
398
+ on,
399
+ manual_override
400
+ });
401
+ }
402
+ /**
403
+ * Sets the vehicle overheat protection.
404
+ * @param vehicle_tag VIN or id field of a vehicle
405
+ * @param on `true` or `false`
406
+ * @param fan_only `true` or `false`
407
+ */
408
+ async set_cabin_overheat_protection(vehicle_tag, on, fan_only) {
409
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_cabin_overheat_protection`, null, {
410
+ on,
411
+ fan_only
412
+ });
413
+ }
414
+ /**
415
+ * Sets the vehicle's charge limit to a custom percentage.
416
+ * @param vehicle_tag VIN or id field of a vehicle
417
+ * @param percent Charge limit percentage typically between 50-100
418
+ */
419
+ async set_charge_limit(vehicle_tag, percent) {
420
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_charge_limit`, null, { percent });
421
+ }
422
+ /**
423
+ * Sets the charge limit to the standard setting.
424
+ * @param vehicle_tag VIN or id field of a vehicle
425
+ * @param percent Current limit in Amps typically between 5-32
426
+ */
427
+ async set_charging_amps(vehicle_tag, charging_amps) {
428
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_charging_amps`, null, { charging_amps });
429
+ }
430
+ /**
431
+ * Enables climate keeper mode.
432
+ * @param vehicle_tag VIN or id field of a vehicle
433
+ * @param climate_keeper_mode `0` is Off, `1` is Keep, `2` is Dog, `3` is Camp
434
+ */
435
+ async set_climate_keeper_mode(vehicle_tag, climate_keeper_mode) {
436
+ if (typeof climate_keeper_mode === "string") climate_keeper_mode = ClimateModes[climate_keeper_mode];
437
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_climate_keeper_mode`, null, { climate_keeper_mode });
438
+ }
439
+ /**
440
+ * Adjusts the Cabin Overheat Protection temperature (COP).
441
+ * @param vehicle_tag VIN or id field of a vehicle
442
+ * @param cop_temp Integer representing Low (0/30C/90F), Medium (1/35C/95F), or High (2/40C/100F)
443
+ */
444
+ async set_cop_temp(vehicle_tag, cop_temp) {
445
+ if (cop_temp >= 90) cop_temp = (cop_temp - 90) / 5;
446
+ else if (cop_temp >= 30) cop_temp = (cop_temp - 30) / 5;
447
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_cop_temp`, null, { cop_temp });
448
+ }
449
+ /**
450
+ * Sets a four-digit passcode for PIN to Drive. This PIN must then be entered before the vehicle can be driven.
451
+ * @param vehicle_tag VIN or id field of a vehicle
452
+ * @param on `true` or `false`
453
+ * @param password Four-digit passcode
454
+ */
455
+ async set_pin_to_drive(vehicle_tag, on, password) {
456
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_pin_to_drive`, null, {
457
+ on,
458
+ password: String(password)
459
+ });
460
+ }
461
+ /**
462
+ * Sets an override for preconditioning — it should default to empty if no override is used.
463
+ * Also known as "Defrost Mode"
464
+ * @param vehicle_tag VIN or id field of a vehicle
465
+ * @param on `true` or `false`
466
+ * @param manual_override `true` or `false`
467
+ */
468
+ async set_preconditioning_max(vehicle_tag, on, manual_override) {
469
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_preconditioning_max`, null, {
470
+ on,
471
+ manual_override
472
+ });
473
+ }
474
+ /**
475
+ * Sets a time at which charging should be completed. The time parameter is minutes after midnight (e.g: time=120 schedules charging for 2:00am vehicle local time).
476
+ * @param vehicle_tag VIN or id field of a vehicle
477
+ * @param enable `true` or `false`
478
+ * @param time Minutes after midnight
479
+ */
480
+ async set_scheduled_charging(vehicle_tag, enable, time) {
481
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_scheduled_charging`, null, {
482
+ enable,
483
+ time
484
+ });
485
+ }
486
+ /**
487
+ * Sets a time at which departure should be completed. The time parameter is minutes after midnight (e.g: time=120 schedules departure for 2:00am vehicle local time).
488
+ * @param vehicle_tag VIN or id field of a vehicle
489
+ * @param enable `true` or `false`
490
+ * @param preconditioning_enabled `true` or `false`
491
+ * @param preconditioning_weekdays_only `true` or `false`
492
+ * @param departure_time Minutes after midnight
493
+ * @param off_peak_charging_enabled `true` or `false`
494
+ * @param off_peak_charging_weekdays_only `true` or `false`
495
+ * @param end_off_peak_time Minutes after midnight
496
+ */
497
+ async set_scheduled_departure(vehicle_tag, enable = true, preconditioning_enabled = false, preconditioning_weekdays_only = false, departure_time = 0, off_peak_charging_enabled = false, off_peak_charging_weekdays_only = false, end_off_peak_time = 0) {
498
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_scheduled_departure`, null, {
499
+ enable,
500
+ preconditioning_enabled,
501
+ preconditioning_weekdays_only,
502
+ departure_time,
503
+ off_peak_charging_enabled,
504
+ off_peak_charging_weekdays_only,
505
+ end_off_peak_time
506
+ });
507
+ }
508
+ /**
509
+ * Enables and disables Sentry Mode. Sentry Mode allows customers to watch the vehicle cameras live from the mobile app, as well as record sentry events.
510
+ * @param vehicle_tag VIN or id field of a vehicle
511
+ * @param on `true` or `false`
512
+ */
513
+ async set_sentry_mode(vehicle_tag, on) {
514
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_sentry_mode`, null, { on });
515
+ }
516
+ /**
517
+ * Sets the driver and/or passenger-side cabin temperature (and other zones if sync is enabled).
518
+ * @param vehicle_tag VIN or id field of a vehicle
519
+ * @param driver_temp Driver temperature
520
+ * @param passenger_temp Passenger temperature
521
+ */
522
+ async set_temps(vehicle_tag, driver_temp, passenger_temp) {
523
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_temps`, null, {
524
+ driver_temp,
525
+ passenger_temp
526
+ });
527
+ }
528
+ /**
529
+ * Turns on Valet Mode and sets a four-digit passcode that must then be entered to disable Valet Mode.
530
+ * @param vehicle_tag VIN or id field of a vehicle
531
+ * @param on `true` or `false`
532
+ * @param password Four-digit passcode
533
+ */
534
+ async set_valet_mode(vehicle_tag, on, password) {
535
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_valet_mode`, null, {
536
+ on,
537
+ password: password == null ? void 0 : String(password)
538
+ });
539
+ }
540
+ /**
541
+ * Changes the name of a vehicle. This command also requires the Tesla Vehicle Command Protocol - for more information, please see refer to the documentation here.
542
+ * @param vehicle_tag VIN or id field of a vehicle
543
+ * @param vehicle_name New name
544
+ */
545
+ async set_vehicle_name(vehicle_tag, vehicle_name) {
546
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/set_vehicle_name`, null, { vehicle_name });
547
+ }
548
+ /**
549
+ * Activates Speed Limit Mode with a four-digit PIN.
550
+ * @param vehicle_tag VIN or id field of a vehicle
551
+ * @param pin Four-digit PIN
552
+ */
553
+ async speed_limit_activate(vehicle_tag, pin) {
554
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/speed_limit_activate`, null, { pin: String(pin) });
555
+ }
556
+ /**
557
+ * Deactivates Speed Limit Mode and resets the associated PIN.
558
+ * @param vehicle_tag VIN or id field of a vehicle
559
+ * @param pin Four-digit PIN
560
+ */
561
+ async speed_limit_clear_pin(vehicle_tag, pin) {
562
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/speed_limit_clear_pin`, null, { pin: String(pin) });
563
+ }
564
+ /**
565
+ * Deactivates Speed Limit Mode and resets the associated PIN for vehicles running firmware versions 2023.38+. This command is only accessible to fleet managers or owners.
566
+ * @param vehicle_tag VIN or id field of a vehicle
567
+ */
568
+ async speed_limit_clear_pin_admin(vehicle_tag) {
569
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/speed_limit_clear_pin_admin`);
570
+ }
571
+ /**
572
+ * Deactivates Speed Limit Mode.
573
+ * @param vehicle_tag VIN or id field of a vehicle
574
+ * @param pin Four-digit PIN
575
+ */
576
+ async speed_limit_deactivate(vehicle_tag, pin) {
577
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/speed_limit_deactivate`, null, { pin: String(pin) });
578
+ }
579
+ /**
580
+ * Sets the maximum speed allowed when Speed Limit Mode is active.
581
+ * @param vehicle_tag VIN or id field of a vehicle
582
+ * @param limit_mph Maximum speed in MPH
583
+ */
584
+ async speed_limit_set_limit(vehicle_tag, limit_mph) {
585
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/speed_limit_set_limit`, null, { limit_mph });
586
+ }
587
+ /**
588
+ * Controls the panoramic sunroof on the Model S.
589
+ * @param vehicle_tag VIN or id field of a vehicle
590
+ * @param state "stop", "close" or "vent"
591
+ */
592
+ async sun_roof_control(vehicle_tag, state) {
593
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/sun_roof_control`, null, { state });
594
+ }
595
+ /**
596
+ * Records a drive note. The note parameter is truncated to 80 characters in length.
597
+ * @param vehicle_tag VIN or id field of a vehicle
598
+ * @param note Drive note
599
+ */
600
+ async take_drivenote(vehicle_tag, note) {
601
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/take_drivenote`, null, { note });
602
+ }
603
+ /**
604
+ * Turns on HomeLink (used to open and close garage doors).
605
+ * @param vehicle_tag VIN or id field of a vehicle
606
+ * @param token
607
+ * @param lat Latitude
608
+ * @param lon Longitude
609
+ */
610
+ async trigger_homelink(vehicle_tag, token, lat, lon) {
611
+ const location = lat != null && lon != null ? {
612
+ lat,
613
+ lon
614
+ } : {};
615
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/trigger_homelink`, null, {
616
+ token: token || void 0,
617
+ ...location
618
+ });
619
+ }
620
+ /**
621
+ * Upcoming calendar entries stored on the vehicle.
622
+ * @param vehicle_tag VIN or id field of a vehicle
623
+ * @param calendar_data Calendar data
624
+ */
625
+ async upcoming_calendar_entries(vehicle_tag, calendar_data) {
626
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/upcoming_calendar_entries`, null, { calendar_data });
627
+ }
628
+ /**
629
+ * Control the windows of a parked vehicle. Supported commands: vent and close. When closing, specify lat and lon of user to ensure they are within range of vehicle (unless this is an M3 platform vehicle).
630
+ * @param vehicle_tag VIN or id field of a vehicle
631
+ * @param command "vent" or "close"
632
+ * @param lat Latitude
633
+ * @param lon Longitude
634
+ */
635
+ async window_control(vehicle_tag, command, lat, lon) {
636
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/command/window_control`, null, {
637
+ command,
638
+ lat,
639
+ lon
640
+ });
641
+ }
642
+ /**
643
+ * Returns all allowed drivers for a vehicle. This endpoint is only available for the vehicle owner.
644
+ * @param vehicle_tag VIN or id field of a vehicle
645
+ */
646
+ async drivers(vehicle_tag) {
647
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/drivers`);
648
+ }
649
+ /**
650
+ * Removes driver access from a vehicle. Share users can only remove their own access. Owners can remove share access or their own.
651
+ * @param vehicle_tag VIN or id field of a vehicle
652
+ * @param share_user_id
653
+ */
654
+ async drivers_remove(vehicle_tag, share_user_id) {
655
+ return this.parent._request("DELETE", `api/1/vehicles/${vehicle_tag}/drivers`, { share_user_id });
656
+ }
657
+ /**
658
+ * Returns eligible vehicle subscriptions.
659
+ * @param vin Vehicle Identification Number
660
+ */
661
+ async eligible_subscriptions(vin) {
662
+ return this.parent._request("GET", "api/1/dx/vehicles/subscriptions/eligibility", { vin });
663
+ }
664
+ /**
665
+ * Returns eligibile vehicle upgrades.
666
+ * @param vin Vehicle Identification Number
667
+ */
668
+ async eligible_upgrades(vin) {
669
+ return this.parent._request("GET", "api/1/dx/vehicles/upgrades/eligibility", { vin });
670
+ }
671
+ /**
672
+ * Checks whether vehicles can accept Tesla commands protocol for the partner's public key
673
+ * @param vins list of Vehicle Identification Number
674
+ * @returns
675
+ */
676
+ async fleet_status(vins) {
677
+ return this.parent._request("POST", "api/1/vehicles/fleet_status", null, { vins });
678
+ }
679
+ /**
680
+ * Configures vehicles to connect to self-hosted fleet-telemetry server. This endpoint has concurrency 1 (status 429 will be returned if many calls are made at the same time). Multiple vehicles can be configured with a single call.
681
+ * @param config A dictionary description the fleet telemetry configuration
682
+ * @returns
683
+ */
684
+ async fleet_telemetry_config_create(config) {
685
+ return this.parent._request("POST", "api/1/vehicles/fleet_telemetry_config", null, config);
686
+ }
687
+ /**
688
+ * Disconnects vehicles to stream telemetry data to self hosted fleet-telemetry server.
689
+ * @param vehicle_tag VIN or id field of a vehicle
690
+ * @returns
691
+ */
692
+ async fleet_telemetry_config_delete(vehicle_tag) {
693
+ return this.parent._request("DELETE", `api/1/vehicles/${vehicle_tag}/fleet_telemetry_config`);
694
+ }
695
+ /**
696
+ * Fetches a vehicle's fleet telemetry config. synced set to true means the vehicle has adopted the target config. synced set to false means the vehicle will attempt to adopt the target config when it next establishes a backend connection.
697
+ * @param vehicle_tag VIN or id field of a vehicle
698
+ * @returns
699
+ */
700
+ async fleet_telemetry_config_get(vehicle_tag) {
701
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/fleet_telemetry_config`);
702
+ }
703
+ /**
704
+ * Returns vehicles belonging to the account.
705
+ * @param page Page number
706
+ * @param per_page Number of items per page
707
+ */
708
+ async list(page, per_page) {
709
+ return this.parent._request("GET", "api/1/vehicles", {
710
+ page,
711
+ per_page
712
+ });
713
+ }
714
+ /**
715
+ * Returns whether or not mobile access is enabled for the vehicle.
716
+ * @param vehicle_tag VIN or id field of a vehicle
717
+ */
718
+ async mobile_enabled(vehicle_tag) {
719
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/mobile_enabled`);
720
+ }
721
+ /**
722
+ * Returns the charging sites near the current location of the vehicle.
723
+ * @param vehicle_tag VIN or id field of a vehicle
724
+ * @param count
725
+ * @param radius
726
+ * @param detail
727
+ */
728
+ async nearby_charging_sites(vehicle_tag, count, radius, detail) {
729
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/nearby_charging_sites`, {
730
+ count,
731
+ radius,
732
+ detail
733
+ });
734
+ }
735
+ /**
736
+ * Returns vehicle option details.
737
+ * @param vin Vehicle Identification Number
738
+ */
739
+ async options(vin) {
740
+ return this.parent._request("GET", "api/1/dx/vehicles/options", { vin }).then(({ codes }) => codes);
741
+ }
742
+ /**
743
+ * List of recent alerts
744
+ * @param vehicle_tag VIN or id field of a vehicle
745
+ */
746
+ async recent_alerts(vehicle_tag) {
747
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/recent_alerts`);
748
+ }
749
+ /**
750
+ * Returns firmware release notes.
751
+ * @param vehicle_tag VIN or id field of a vehicle
752
+ * @param staged
753
+ * @param language
754
+ */
755
+ async release_notes(vehicle_tag, staged, language) {
756
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/release_notes`, {
757
+ staged,
758
+ language
759
+ });
760
+ }
761
+ /**
762
+ * Returns service data.
763
+ * @param vehicle_tag VIN or id field of a vehicle
764
+ */
765
+ async service_data(vehicle_tag) {
766
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/service_data`);
767
+ }
768
+ /**
769
+ * Returns the share invites for a vehicle.
770
+ * @param vehicle_tag VIN or id field of a vehicle
771
+ */
772
+ async share_invites(vehicle_tag) {
773
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/invitations`);
774
+ }
775
+ /**
776
+ * Creates a share invite for a vehicle.
777
+ * @param vehicle_tag VIN or id field of a vehicle
778
+ */
779
+ async share_invites_create(vehicle_tag) {
780
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/invitations`);
781
+ }
782
+ /**
783
+ * Redeems a share invite.
784
+ * @param code
785
+ */
786
+ async share_invites_redeem(code) {
787
+ return this.parent._request("POST", "api/1/invitations/redeem", { code });
788
+ }
789
+ /**
790
+ * Revokes a share invite.
791
+ * @param vehicle_tag VIN or id field of a vehicle
792
+ * @param id
793
+ */
794
+ async share_invites_revoke(vehicle_tag, id) {
795
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/invitations/${id}/revoke`);
796
+ }
797
+ /**
798
+ * Signed Commands is a generic endpoint replacing legacy commands.
799
+ * @param vehicle_tag VIN or id field of a vehicle
800
+ * @param routable_message
801
+ */
802
+ async signed_command(vehicle_tag, routable_message) {
803
+ return this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/signed_command`, null, { routable_message });
804
+ }
805
+ /**
806
+ * Returns information about a vehicle.
807
+ * @param vehicle_tag VIN or id field of a vehicle
808
+ */
809
+ async vehicle(vehicle_tag) {
810
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}`);
811
+ }
812
+ /**
813
+ * Makes a live call to the vehicle. This may return cached data if the vehicle is offline. For vehicles running firmware versions 2023.38+, location_data is required to fetch vehicle location. This will result in a location sharing icon to show on the vehicle UI.
814
+ * @param vehicle_tag VIN or id field of a vehicle
815
+ * @param endpoints
816
+ */
817
+ async vehicle_data(vehicle_tag, endpoints) {
818
+ if (typeof endpoints === "object") endpoints = endpoints.join(";");
819
+ return this.parent._request("GET", `api/1/vehicles/${vehicle_tag}/vehicle_data`, { endpoints });
820
+ }
821
+ /**
822
+ * Wakes the vehicle from sleep, which is a state to minimize idle energy consumption.
823
+ * @param vehicle_tag VIN or id field of a vehicle
824
+ * @param options.wait Poll `vehicle()` until the vehicle reports `online`, raising `VehicleOffline` at the deadline
825
+ * @param options.timeoutMs Deadline for `wait`, in milliseconds (default 60000)
826
+ */
827
+ async wake_up(vehicle_tag, { wait = false, timeoutMs = WAKE_TIMEOUT_MS } = {}) {
828
+ const deadline = Date.now() + timeoutMs;
829
+ let result = await this.parent._request("POST", `api/1/vehicles/${vehicle_tag}/wake_up`);
830
+ if (!wait) return result;
831
+ while (result.response?.state !== "online") {
832
+ const remaining = deadline - Date.now();
833
+ if (remaining <= 0) throw new VehicleOffline(result);
834
+ await new Promise((resolve) => setTimeout(resolve, Math.min(WAKE_POLL_MS, remaining)));
835
+ result = await this.vehicle(vehicle_tag);
836
+ }
837
+ return result;
838
+ }
839
+ /**
840
+ * Returns warranty details.
841
+ * @param vin
842
+ */
843
+ async warranty_details(vin) {
844
+ return this.parent._request("GET", "api/1/dx/warranty/details", { vin });
845
+ }
846
+ };
847
+ export { Vehicle as default };