tesla-fleet-api 0.4.0 → 0.6.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/README.md +269 -1
- package/dist/_virtual/_rolldown/runtime.cjs +10 -0
- package/dist/bluetooth/adapters/shared.cjs +38 -0
- package/dist/bluetooth/adapters/shared.mjs +36 -0
- package/dist/bluetooth/async.cjs +121 -0
- package/dist/bluetooth/async.d.cts +10 -0
- package/dist/bluetooth/async.d.mts +10 -0
- package/dist/bluetooth/async.mjs +116 -0
- package/dist/bluetooth/broadcast.cjs +153 -0
- package/dist/bluetooth/broadcast.d.cts +59 -0
- package/dist/bluetooth/broadcast.d.mts +59 -0
- package/dist/bluetooth/broadcast.mjs +151 -0
- package/dist/bluetooth/constants.cjs +96 -0
- package/dist/bluetooth/constants.d.cts +68 -0
- package/dist/bluetooth/constants.d.mts +68 -0
- package/dist/bluetooth/constants.mjs +70 -0
- package/dist/bluetooth/framing.cjs +125 -0
- package/dist/bluetooth/framing.d.cts +45 -0
- package/dist/bluetooth/framing.d.mts +45 -0
- package/dist/bluetooth/framing.mjs +122 -0
- package/dist/bluetooth/homey.cjs +165 -0
- package/dist/bluetooth/homey.d.cts +84 -0
- package/dist/bluetooth/homey.d.mts +84 -0
- package/dist/bluetooth/homey.mjs +159 -0
- package/dist/bluetooth/names.cjs +24 -0
- package/dist/bluetooth/names.d.cts +10 -0
- package/dist/bluetooth/names.d.mts +10 -0
- package/dist/bluetooth/names.mjs +20 -0
- package/dist/bluetooth/noble.cjs +178 -0
- package/dist/bluetooth/noble.d.cts +58 -0
- package/dist/bluetooth/noble.d.mts +58 -0
- package/dist/bluetooth/noble.mjs +177 -0
- package/dist/bluetooth/streamglue.cjs +157 -0
- package/dist/bluetooth/streamglue.d.cts +37 -0
- package/dist/bluetooth/streamglue.d.mts +37 -0
- package/dist/bluetooth/streamglue.mjs +154 -0
- package/dist/bluetooth/teslabluetooth.cjs +67 -0
- package/dist/bluetooth/teslabluetooth.d.cts +41 -0
- package/dist/bluetooth/teslabluetooth.d.mts +41 -0
- package/dist/bluetooth/teslabluetooth.mjs +66 -0
- package/dist/bluetooth/transport.cjs +10 -0
- package/dist/bluetooth/transport.d.cts +97 -0
- package/dist/bluetooth/transport.d.mts +97 -0
- package/dist/bluetooth/transport.mjs +10 -0
- package/dist/bluetooth/vehiclebluetooth.cjs +1272 -0
- package/dist/bluetooth/vehiclebluetooth.d.cts +495 -0
- package/dist/bluetooth/vehiclebluetooth.d.mts +495 -0
- package/dist/bluetooth/vehiclebluetooth.mjs +1270 -0
- package/dist/bluetooth/verify.cjs +93 -0
- package/dist/bluetooth/verify.d.cts +35 -0
- package/dist/bluetooth/verify.d.mts +35 -0
- package/dist/bluetooth/verify.mjs +91 -0
- package/dist/bluetooth.cjs +52 -0
- package/dist/bluetooth.d.cts +10 -0
- package/dist/bluetooth.d.mts +10 -0
- package/dist/bluetooth.mjs +9 -0
- package/dist/commands.cjs +1080 -85
- package/dist/commands.d.cts +585 -54
- package/dist/commands.d.mts +583 -51
- package/dist/commands.mjs +1084 -93
- package/dist/const.cjs +22 -0
- package/dist/const.d.cts +21 -0
- package/dist/const.d.mts +21 -0
- package/dist/const.mjs +20 -1
- package/dist/energy.cjs +24 -19
- package/dist/energy.d.cts +21 -15
- package/dist/energy.d.mts +21 -15
- package/dist/energy.mjs +24 -19
- package/dist/energyisland.cjs +38 -0
- package/dist/energyisland.mjs +37 -0
- package/dist/energyparsers.cjs +118 -0
- package/dist/energyparsers.d.cts +39 -0
- package/dist/energyparsers.d.mts +39 -0
- package/dist/energyparsers.mjs +116 -0
- package/dist/energyspecific.cjs +375 -17
- package/dist/energyspecific.d.cts +199 -19
- package/dist/energyspecific.d.mts +197 -16
- package/dist/energyspecific.mjs +370 -18
- package/dist/exceptions.cjs +3 -2
- package/dist/exceptions.d.cts +3 -2
- package/dist/exceptions.d.mts +3 -2
- package/dist/exceptions.mjs +3 -2
- package/dist/funnel.cjs +297 -0
- package/dist/funnel.d.cts +118 -0
- package/dist/funnel.d.mts +118 -0
- package/dist/funnel.mjs +292 -0
- package/dist/index.cjs +61 -0
- package/dist/index.d.cts +22 -8
- package/dist/index.d.mts +22 -8
- package/dist/index.mjs +19 -6
- package/dist/log.cjs +75 -0
- package/dist/log.d.cts +4 -0
- package/dist/log.d.mts +4 -0
- package/dist/log.mjs +71 -0
- package/dist/oauth.cjs +143 -0
- package/dist/oauth.d.cts +69 -0
- package/dist/oauth.d.mts +69 -0
- package/dist/oauth.mjs +143 -0
- package/dist/powerwall/client.cjs +818 -0
- package/dist/powerwall/client.d.cts +297 -0
- package/dist/powerwall/client.d.mts +297 -0
- package/dist/powerwall/client.mjs +807 -0
- package/dist/powerwall/components.cjs +188 -0
- package/dist/powerwall/components.d.cts +45 -0
- package/dist/powerwall/components.d.mts +45 -0
- package/dist/powerwall/components.mjs +182 -0
- package/dist/powerwall/energysite.cjs +216 -0
- package/dist/powerwall/energysite.d.cts +104 -0
- package/dist/powerwall/energysite.d.mts +104 -0
- package/dist/powerwall/energysite.mjs +214 -0
- package/dist/powerwall/exceptions.cjs +59 -0
- package/dist/powerwall/exceptions.d.cts +38 -0
- package/dist/powerwall/exceptions.d.mts +38 -0
- package/dist/powerwall/exceptions.mjs +51 -0
- package/dist/powerwall/gateway.cjs +102 -0
- package/dist/powerwall/gateway.d.cts +57 -0
- package/dist/powerwall/gateway.d.mts +57 -0
- package/dist/powerwall/gateway.mjs +101 -0
- package/dist/powerwall/merge.cjs +163 -0
- package/dist/powerwall/merge.d.cts +63 -0
- package/dist/powerwall/merge.d.mts +63 -0
- package/dist/powerwall/merge.mjs +159 -0
- package/dist/powerwall/models.d.cts +95 -0
- package/dist/powerwall/models.d.mts +95 -0
- package/dist/powerwall/queries.cjs +17 -0
- package/dist/powerwall/queries.mjs +10 -0
- package/dist/powerwall/transport.cjs +232 -0
- package/dist/powerwall/transport.mjs +227 -0
- package/dist/powerwall.cjs +47 -0
- package/dist/powerwall.d.cts +9 -0
- package/dist/powerwall.d.mts +9 -0
- package/dist/powerwall.mjs +8 -0
- package/dist/router/base.cjs +203 -0
- package/dist/router/base.d.cts +112 -0
- package/dist/router/base.d.mts +112 -0
- package/dist/router/base.mjs +200 -0
- package/dist/router/energysite.cjs +65 -0
- package/dist/router/energysite.d.cts +47 -0
- package/dist/router/energysite.d.mts +47 -0
- package/dist/router/energysite.mjs +60 -0
- package/dist/router.cjs +13 -0
- package/dist/router.d.cts +3 -1
- package/dist/router.d.mts +3 -1
- package/dist/router.mjs +3 -1
- package/dist/signing/crypto.cjs +28 -0
- package/dist/signing/crypto.mjs +26 -1
- package/dist/signing/energy.cjs +123 -0
- package/dist/signing/energy.d.cts +45 -0
- package/dist/signing/energy.d.mts +45 -0
- package/dist/signing/energy.mjs +120 -0
- package/dist/signing/jws.cjs +229 -0
- package/dist/signing/jws.d.cts +45 -0
- package/dist/signing/jws.d.mts +45 -0
- package/dist/signing/jws.mjs +211 -0
- package/dist/signing/keys.cjs +191 -0
- package/dist/signing/keys.d.cts +21 -0
- package/dist/signing/keys.d.mts +21 -0
- package/dist/signing/keys.mjs +182 -0
- package/dist/signing/session.cjs +104 -30
- package/dist/signing/session.d.cts +60 -23
- package/dist/signing/session.d.mts +60 -23
- package/dist/signing/session.mjs +105 -31
- package/dist/tariff.cjs +27 -0
- package/dist/tariff.d.cts +11 -0
- package/dist/tariff.d.mts +11 -0
- package/dist/tariff.mjs +27 -1
- package/dist/teslafleetapi.cjs +256 -55
- package/dist/teslafleetapi.d.cts +110 -14
- package/dist/teslafleetapi.d.mts +110 -14
- package/dist/teslafleetapi.mjs +258 -57
- package/dist/teslemetry.cjs +152 -5
- package/dist/teslemetry.d.cts +95 -5
- package/dist/teslemetry.d.mts +93 -3
- package/dist/teslemetry.mjs +151 -6
- package/dist/teslemetryenergy.cjs +287 -0
- package/dist/teslemetryenergy.d.cts +154 -0
- package/dist/teslemetryenergy.d.mts +154 -0
- package/dist/teslemetryenergy.mjs +282 -0
- package/dist/teslemetryvehicle.cjs +407 -0
- package/dist/teslemetryvehicle.d.cts +238 -0
- package/dist/teslemetryvehicle.d.mts +238 -0
- package/dist/teslemetryvehicle.mjs +405 -0
- package/dist/tessie.cjs +42 -5
- package/dist/tessie.d.cts +51 -5
- package/dist/tessie.d.mts +49 -3
- package/dist/tessie.mjs +42 -5
- package/dist/tessievehicle.cjs +514 -0
- package/dist/tessievehicle.d.cts +333 -0
- package/dist/tessievehicle.d.mts +333 -0
- package/dist/tessievehicle.mjs +513 -0
- package/dist/types/live_status.d.cts +16 -16
- package/dist/types/live_status.d.mts +16 -16
- package/dist/types/responses.d.cts +5 -1
- package/dist/types/responses.d.mts +5 -1
- package/dist/types/vehicle.d.cts +7 -1
- package/dist/types/vehicle.d.mts +7 -1
- package/dist/types.d.cts +3 -3
- package/dist/types.d.mts +3 -3
- package/dist/util.cjs +41 -0
- package/dist/util.d.cts +18 -0
- package/dist/util.d.mts +18 -0
- package/dist/util.mjs +40 -0
- package/dist/vehicle.cjs +79 -36
- package/dist/vehicle.d.cts +42 -26
- package/dist/vehicle.d.mts +42 -26
- package/dist/vehicle.mjs +80 -37
- package/dist/vehiclesigned.cjs +20 -5
- package/dist/vehiclesigned.d.cts +14 -5
- package/dist/vehiclesigned.d.mts +14 -5
- package/dist/vehiclesigned.mjs +20 -5
- package/dist/vehiclespecific.cjs +126 -15
- package/dist/vehiclespecific.d.cts +82 -18
- package/dist/vehiclespecific.d.mts +82 -18
- package/dist/vehiclespecific.mjs +126 -15
- package/package.json +56 -3
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { Logger } from "../log.cjs";
|
|
2
|
+
import { AuthorizedClientsPayload, BackupEventsPayload, BatteryCalibrationDelayStatus, ComponentsPayload, ConfigPayload, ControllableDeviceProgramsPayload, ControllerPayload, FirmwareDetails, StatusPayload } from "./models.cjs";
|
|
3
|
+
/** The gateway's own Wi-Fi access point. */
|
|
4
|
+
export declare const DEFAULT_GATEWAY_HOST = "192.168.91.1";
|
|
5
|
+
/** Values of `default_real_mode`. Each sticks and reads back verbatim on a Powerwall 3. */
|
|
6
|
+
export declare const OPERATION_MODES: readonly ["self_consumption", "autonomous", "backup"];
|
|
7
|
+
/** Values of `site_info.customer_preferred_export_rule`. Each sticks and reads back verbatim on a Powerwall 3. */
|
|
8
|
+
export declare const GRID_EXPORT_RULES: readonly ["battery_ok", "pv_only", "never"];
|
|
9
|
+
export interface PowerwallClientOptions {
|
|
10
|
+
/** The gateway address, optionally `host:port`. */
|
|
11
|
+
host?: string;
|
|
12
|
+
/** The full gateway/Wi-Fi password, or its last 5 characters. */
|
|
13
|
+
gatewayPassword: string;
|
|
14
|
+
/** An RSA key already paired with the gateway through the cloud. */
|
|
15
|
+
rsaPrivateKeyPem: string | Buffer;
|
|
16
|
+
/** Total time allowed per request. */
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
/** The gateway's DIN, when known. Any other DIN fails `connect`, so nothing is sent to the wrong gateway. */
|
|
19
|
+
expectedDin?: string;
|
|
20
|
+
/** Receives debug lines. */
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Client for a gateway on the LAN, over `/tedapi/v1r` and its REST reads.
|
|
25
|
+
*
|
|
26
|
+
* The connection is not authenticated: like Python, this accepts any
|
|
27
|
+
* certificate, and replies carry no signature. A device on the LAN that can
|
|
28
|
+
* intercept traffic can read the password and forge readings, but it cannot
|
|
29
|
+
* forge a signed command.
|
|
30
|
+
*/
|
|
31
|
+
export declare class PowerwallClient {
|
|
32
|
+
#private;
|
|
33
|
+
/** @throws PowerwallAuthenticationError for a bad PEM or a key that is not RSA. */
|
|
34
|
+
constructor(options: PowerwallClientOptions, _legacyGateway?: boolean);
|
|
35
|
+
/**
|
|
36
|
+
* A client for an early Gateway 1 unit, which rejects the last-5 login and
|
|
37
|
+
* needs the full `gatewayPassword`. Everything else is the same.
|
|
38
|
+
*/
|
|
39
|
+
static legacy_gateway(options: PowerwallClientOptions): PowerwallClient;
|
|
40
|
+
get host(): string;
|
|
41
|
+
/** The gateway DIN, or `null` until `connect` succeeds. */
|
|
42
|
+
get din(): string | null;
|
|
43
|
+
/** True between `curtail` and `restore_from_curtailment`. */
|
|
44
|
+
get curtailment_active(): boolean;
|
|
45
|
+
/** Log in and fetch the gateway DIN. Idempotent, and concurrent callers share one attempt. */
|
|
46
|
+
connect(): Promise<string>;
|
|
47
|
+
/** Destroy the idle sockets. */
|
|
48
|
+
close(): void;
|
|
49
|
+
/** The cached DIN, connecting first if needed. */
|
|
50
|
+
get_din(): Promise<string>;
|
|
51
|
+
/** `/api/meters/aggregates`: instantaneous power per location. */
|
|
52
|
+
get_meters_aggregates(): Promise<Record<string, any>>;
|
|
53
|
+
/** The raw state of charge, where the bottom 5% is an inaccessible buffer. It reads higher than the Tesla app. */
|
|
54
|
+
get_battery_soe_raw(): Promise<number>;
|
|
55
|
+
/** The state of charge the Tesla app and Fleet API show. */
|
|
56
|
+
get_battery_soe(): Promise<number>;
|
|
57
|
+
/** The gateway grid status string, such as `SystemGridConnected`. */
|
|
58
|
+
get_grid_status(): Promise<string>;
|
|
59
|
+
/** The gateway's `config.json`. `battery_blocks` is always present. */
|
|
60
|
+
get_config(): Promise<ConfigPayload>;
|
|
61
|
+
/** The gateway status, from the narrow DeviceControllerQuery. */
|
|
62
|
+
get_status(): Promise<StatusPayload>;
|
|
63
|
+
/** The extended DeviceControllerQuery payload. */
|
|
64
|
+
get_device_controller(): Promise<ControllerPayload>;
|
|
65
|
+
/** Powerwall 3 component data: `pch`, `pws`, `bms`, `hvp` and `baggr`. */
|
|
66
|
+
get_components(): Promise<ComponentsPayload>;
|
|
67
|
+
/** Gateway firmware details. Python's `five` and `six` keys are `update_status` and `device_type` here. */
|
|
68
|
+
get_firmware_details(): Promise<FirmwareDetails>;
|
|
69
|
+
/** The active manual backup and any scheduled backup events. Times are epoch seconds. */
|
|
70
|
+
get_backup_events(): Promise<BackupEventsPayload>;
|
|
71
|
+
/**
|
|
72
|
+
* The battery calibration delay counters.
|
|
73
|
+
* @throws PowerwallNotSupportedError on firmware without this command. Powerwall 3 firmware 26.26.4 is one.
|
|
74
|
+
*/
|
|
75
|
+
get_battery_calibration_delay_status(): Promise<BatteryCalibrationDelayStatus>;
|
|
76
|
+
/**
|
|
77
|
+
* The load programs of Backup Switch and smart breaker devices. A site with
|
|
78
|
+
* none returns two empty lists.
|
|
79
|
+
* @param device_ids The devices to read, or every device when omitted.
|
|
80
|
+
*/
|
|
81
|
+
get_controllable_device_programs(device_ids?: string[]): Promise<ControllableDeviceProgramsPayload>;
|
|
82
|
+
/** The keys paired with the gateway, in the gateway's raw form. */
|
|
83
|
+
list_authorized_clients(): Promise<AuthorizedClientsPayload>;
|
|
84
|
+
/**
|
|
85
|
+
* Patch `config.json`, a read-modify-write. The update carries the hash from
|
|
86
|
+
* the read unchanged: it is an optimistic lock held by the gateway, and the
|
|
87
|
+
* client never computes one.
|
|
88
|
+
* @param updates Dotted paths to values, such as `{"site_info.backup_reserve_percent": 24}`.
|
|
89
|
+
* Writes on one client run one at a time, so two cannot interleave. Another
|
|
90
|
+
* client's write is caught by that lock instead, and refused.
|
|
91
|
+
* @throws RangeError on a number that is not finite, before any request.
|
|
92
|
+
* @throws PowerwallProtocolError on bad JSON, or a reply with no `filestore`.
|
|
93
|
+
*/
|
|
94
|
+
write_config(updates: Record<string, unknown>): Promise<void>;
|
|
95
|
+
private _write_config;
|
|
96
|
+
/**
|
|
97
|
+
* Set the backup reserve on the app's 0-100 scale.
|
|
98
|
+
* @throws RangeError outside 0-100.
|
|
99
|
+
*/
|
|
100
|
+
set_backup_reserve(percent: number): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Write the backup reserve on the gateway's raw scale, where app 0% is raw 5%.
|
|
103
|
+
* @throws RangeError outside 0-100.
|
|
104
|
+
*/
|
|
105
|
+
set_backup_reserve_raw(percent: number): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Set the operation mode, as `operation` does through the cloud.
|
|
108
|
+
* @param mode One of `OPERATION_MODES`.
|
|
109
|
+
* @throws RangeError for any other value.
|
|
110
|
+
*/
|
|
111
|
+
set_operation_mode(mode: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Set `strategy.TOU_mode`, which is local-only: the cloud API does not expose it.
|
|
114
|
+
*
|
|
115
|
+
* The gateway does not validate this field, so a typo silently sets an
|
|
116
|
+
* unrecognized mode. Only `economic` is confirmed in use. The tariff itself
|
|
117
|
+
* lives in the cloud and cannot be set here.
|
|
118
|
+
* @throws RangeError on an empty string.
|
|
119
|
+
*/
|
|
120
|
+
set_tou_mode(mode: string): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Set the export rule, the grid-charging flag, or both in one write. See
|
|
123
|
+
* `set_export_rule` and `set_grid_charging` for one of each.
|
|
124
|
+
* @throws RangeError for an unknown rule.
|
|
125
|
+
* @throws TypeError when given neither.
|
|
126
|
+
*/
|
|
127
|
+
set_grid_import_export(options: {
|
|
128
|
+
customer_preferred_export_rule?: string | null;
|
|
129
|
+
disallow_charge_from_grid_with_solar_installed?: boolean | null;
|
|
130
|
+
}): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Set the export rule. `net_meter_mode` is independent and does not move.
|
|
133
|
+
* @param rule `battery_ok` exports solar and battery, `pv_only` solar only, `never` nothing.
|
|
134
|
+
* @throws RangeError for any other value.
|
|
135
|
+
*/
|
|
136
|
+
set_export_rule(rule: string): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Allow or disallow charging from the grid. The gateway stores the inverse
|
|
139
|
+
* flag and drops the key rather than store `false`, so treat an absent key
|
|
140
|
+
* as "allowed".
|
|
141
|
+
*/
|
|
142
|
+
set_grid_charging(enabled: boolean): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Enable on-grid solar curtailment. The gateway drops the key rather than
|
|
145
|
+
* store `false`, so treat an absent key as disabled.
|
|
146
|
+
*/
|
|
147
|
+
set_on_grid_solar_curtailment(enabled: boolean): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Cap grid import, in kilowatts, stored as given.
|
|
150
|
+
* @throws RangeError on a negative value.
|
|
151
|
+
*/
|
|
152
|
+
set_import_limit(kilowatts: number): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Cap grid export, in kilowatts. Pass a positive magnitude: the gateway
|
|
155
|
+
* represents export as negative site-meter power.
|
|
156
|
+
* @throws RangeError on a negative value.
|
|
157
|
+
*/
|
|
158
|
+
set_export_limit(kilowatts: number): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Stop grid export by switching to `backup` mode at a high reserve. This uses
|
|
161
|
+
* a config write, so no contactor cycles, but it takes about 90 seconds to
|
|
162
|
+
* apply. `restore_from_curtailment` puts back what this replaced.
|
|
163
|
+
* @param options.reserve_percent The reserve during curtailment, on the **raw** scale.
|
|
164
|
+
* @throws RangeError outside 0-100.
|
|
165
|
+
*/
|
|
166
|
+
curtail(options?: {
|
|
167
|
+
reserve_percent?: number;
|
|
168
|
+
}): Promise<void>;
|
|
169
|
+
/** Write back what `curtail` replaced, or `self_consumption` at a raw 5 if nothing was saved. */
|
|
170
|
+
restore_from_curtailment(): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Schedule a manual "max backup" event that starts now, at maximum priority.
|
|
173
|
+
* The gateway requires any earlier event to be cancelled first, even an
|
|
174
|
+
* expired one, so this sends that cancel before scheduling.
|
|
175
|
+
* @param duration_seconds At least 60.
|
|
176
|
+
* @throws RangeError on a shorter or fractional duration.
|
|
177
|
+
*/
|
|
178
|
+
schedule_max_backup(duration_seconds?: number): Promise<void>;
|
|
179
|
+
/** Cancel the active manual backup event, if any. */
|
|
180
|
+
cancel_max_backup(): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Request a timed battery power setpoint.
|
|
183
|
+
*
|
|
184
|
+
* The gateway holds it for the duration and then returns to its mode by
|
|
185
|
+
* itself. A new call replaces the active setpoint, power and timer both. The
|
|
186
|
+
* reply only acknowledges the request, so read `get_meters_aggregates` to see
|
|
187
|
+
* what the battery does. Keep durations short and renew them: a third party
|
|
188
|
+
* reports a dispatch discharging below reserve and exporting regardless of the
|
|
189
|
+
* export setting. Verified on Powerwall 3 firmware 26.26.4.
|
|
190
|
+
* @param power_watts Positive discharges, negative charges.
|
|
191
|
+
* @param duration_seconds Whole seconds from 1 to 86400.
|
|
192
|
+
* @throws PowerwallCommandError with code 11 above the site limit. The gateway refuses, and does not clamp.
|
|
193
|
+
* @throws PowerwallNotSupportedError on firmware without this command.
|
|
194
|
+
*/
|
|
195
|
+
dispatch_battery_power(power_watts: number, duration_seconds: number): Promise<void>;
|
|
196
|
+
/** Release a `dispatch_battery_power` setpoint. This does not cancel a manual backup event. */
|
|
197
|
+
resume_battery_operation(): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Postpone the next battery calibration. Powerwall 3 firmware 26.26.4
|
|
200
|
+
* acknowledges this, but its effect is unverified: that firmware cannot report
|
|
201
|
+
* the delay status.
|
|
202
|
+
* @param delay_hours An integer from 1 to `2^32 - 1`.
|
|
203
|
+
*/
|
|
204
|
+
delay_battery_calibration(delay_hours: number): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Point the gateway at an OCPP central system.
|
|
207
|
+
* @throws PowerwallNotSupportedError on firmware without this command. Powerwall 3 firmware 26.26.4 is one.
|
|
208
|
+
*/
|
|
209
|
+
configure_ocpp(csms_base_url: string): Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
* Revoke a paired key. This needs no presence proof, and any paired key can
|
|
212
|
+
* remove any other. Removing the signing key locks this client out, and
|
|
213
|
+
* pairing it again needs the usual registration and breaker toggle. A success
|
|
214
|
+
* carries no fields, so call `list_authorized_clients` to confirm.
|
|
215
|
+
* @param public_key Raw DER bytes, or base64 as `list_authorized_clients` reports it.
|
|
216
|
+
* @throws RangeError on an empty key.
|
|
217
|
+
*/
|
|
218
|
+
remove_authorized_client(public_key: Uint8Array | string): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Ask the gateway to go off grid or reconnect.
|
|
221
|
+
*
|
|
222
|
+
* A success-shaped reply does not prove the contactor moved: PowerSync reports
|
|
223
|
+
* firmware that acknowledges without acting. Read `islanding.contactorClosed`
|
|
224
|
+
* from `get_status` afterwards before relying on it.
|
|
225
|
+
* @param options.off_grid Mode 6 (off grid) when true, mode 1 (on grid) when false.
|
|
226
|
+
* @param options.force Required by some Powerwalls.
|
|
227
|
+
* @param options.mode_override Send this mode instead: 1 or 6.
|
|
228
|
+
* @throws TypeError on any other mode, or an `off_grid` that is not a boolean.
|
|
229
|
+
* @throws PowerwallCommandError on a `REJECTED_*` result, with `code` the enum value and `status_message` its name, or on `common.error_response`.
|
|
230
|
+
*/
|
|
231
|
+
set_island_mode(options: {
|
|
232
|
+
off_grid: boolean;
|
|
233
|
+
force?: boolean;
|
|
234
|
+
mode_override?: number | null;
|
|
235
|
+
}): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Disconnect from the grid. See `set_island_mode`, including its warning: read
|
|
238
|
+
* `islanding.contactorClosed` afterwards.
|
|
239
|
+
* @param options.force Defaults to true.
|
|
240
|
+
*/
|
|
241
|
+
go_off_grid(options?: {
|
|
242
|
+
force?: boolean;
|
|
243
|
+
mode_override?: number | null;
|
|
244
|
+
}): Promise<void>;
|
|
245
|
+
/** Reconnect to the grid. See `set_island_mode`, including its warning: read `islanding.contactorClosed` afterwards. */
|
|
246
|
+
reconnect_grid(): Promise<void>;
|
|
247
|
+
/**
|
|
248
|
+
* The explicit black-start command, which drives the full islanding
|
|
249
|
+
* transition: grid-frequency ramp-down, contactor open, inverter restart.
|
|
250
|
+
* `set_island_mode` only updates the desired mode. No hardware result is
|
|
251
|
+
* recorded for this command, so check the contactor afterwards.
|
|
252
|
+
* @throws PowerwallCommandError on `common.error_response`.
|
|
253
|
+
*/
|
|
254
|
+
trigger_islanding(): Promise<void>;
|
|
255
|
+
private _cancel_manual_backup;
|
|
256
|
+
private _query_graphql;
|
|
257
|
+
private _read_config;
|
|
258
|
+
/** Sign, send once, and decode the reply envelope. */
|
|
259
|
+
private _post;
|
|
260
|
+
/**
|
|
261
|
+
* The one path for Command-header messages.
|
|
262
|
+
*
|
|
263
|
+
* Python's tolerated calls swallow every error, so a BUSY fault while revoking
|
|
264
|
+
* a compromised key reports success with the key still paired. Here `empty`
|
|
265
|
+
* accepts only an empty reply, and `ignored_status` the one refusal that means
|
|
266
|
+
* there was nothing to do.
|
|
267
|
+
* @param din The gateway DIN.
|
|
268
|
+
* @param payload The message's category and request.
|
|
269
|
+
* @param answered Reads the expected response field from a reply.
|
|
270
|
+
* @param request The request's proto field name, for errors.
|
|
271
|
+
* @param missing What to do when the reply lacks the response.
|
|
272
|
+
* @param ignored_status A `common.error_response` code that is not a failure.
|
|
273
|
+
*/
|
|
274
|
+
private _send_command_request;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Convert a reserve percentage from the app's scale to the gateway's raw value.
|
|
278
|
+
* @throws RangeError outside 0-100.
|
|
279
|
+
*/
|
|
280
|
+
export declare function scaled_to_raw_reserve(percent: number): number;
|
|
281
|
+
/** Convert a raw gateway reserve value to the app's scale. */
|
|
282
|
+
export declare function raw_to_scaled_reserve(percent: number): number;
|
|
283
|
+
/**
|
|
284
|
+
* Convert a state of charge from the app's scale to the raw value.
|
|
285
|
+
* @throws RangeError outside 0-100.
|
|
286
|
+
*/
|
|
287
|
+
export declare function scaled_to_raw_soc(percent: number): number;
|
|
288
|
+
/** Convert a raw state of charge to the value the Tesla app and Fleet API show. */
|
|
289
|
+
export declare function raw_to_scaled_soc(percent: number): number;
|
|
290
|
+
/** The raw physical state of charge from a status payload, or `null` when either figure is missing or zero. */
|
|
291
|
+
export declare function battery_level_raw(status: StatusPayload): number | null;
|
|
292
|
+
/** The state of charge the Tesla app and Fleet API show, from a status payload, or `null`. */
|
|
293
|
+
export declare function battery_level(status: StatusPayload): number | null;
|
|
294
|
+
/** Real power in watts by upper-case meter location. Malformed aggregates give `{}`. */
|
|
295
|
+
export declare function current_power(status: StatusPayload): Record<string, number | null>;
|
|
296
|
+
/** Backup runtime in hours at the current load, or `null` when unknown. */
|
|
297
|
+
export declare function backup_time_remaining(status: StatusPayload): number | null;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { Logger } from "../log.mjs";
|
|
2
|
+
import { AuthorizedClientsPayload, BackupEventsPayload, BatteryCalibrationDelayStatus, ComponentsPayload, ConfigPayload, ControllableDeviceProgramsPayload, ControllerPayload, FirmwareDetails, StatusPayload } from "./models.mjs";
|
|
3
|
+
/** The gateway's own Wi-Fi access point. */
|
|
4
|
+
export declare const DEFAULT_GATEWAY_HOST = "192.168.91.1";
|
|
5
|
+
/** Values of `default_real_mode`. Each sticks and reads back verbatim on a Powerwall 3. */
|
|
6
|
+
export declare const OPERATION_MODES: readonly ["self_consumption", "autonomous", "backup"];
|
|
7
|
+
/** Values of `site_info.customer_preferred_export_rule`. Each sticks and reads back verbatim on a Powerwall 3. */
|
|
8
|
+
export declare const GRID_EXPORT_RULES: readonly ["battery_ok", "pv_only", "never"];
|
|
9
|
+
export interface PowerwallClientOptions {
|
|
10
|
+
/** The gateway address, optionally `host:port`. */
|
|
11
|
+
host?: string;
|
|
12
|
+
/** The full gateway/Wi-Fi password, or its last 5 characters. */
|
|
13
|
+
gatewayPassword: string;
|
|
14
|
+
/** An RSA key already paired with the gateway through the cloud. */
|
|
15
|
+
rsaPrivateKeyPem: string | Buffer;
|
|
16
|
+
/** Total time allowed per request. */
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
/** The gateway's DIN, when known. Any other DIN fails `connect`, so nothing is sent to the wrong gateway. */
|
|
19
|
+
expectedDin?: string;
|
|
20
|
+
/** Receives debug lines. */
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Client for a gateway on the LAN, over `/tedapi/v1r` and its REST reads.
|
|
25
|
+
*
|
|
26
|
+
* The connection is not authenticated: like Python, this accepts any
|
|
27
|
+
* certificate, and replies carry no signature. A device on the LAN that can
|
|
28
|
+
* intercept traffic can read the password and forge readings, but it cannot
|
|
29
|
+
* forge a signed command.
|
|
30
|
+
*/
|
|
31
|
+
export declare class PowerwallClient {
|
|
32
|
+
#private;
|
|
33
|
+
/** @throws PowerwallAuthenticationError for a bad PEM or a key that is not RSA. */
|
|
34
|
+
constructor(options: PowerwallClientOptions, _legacyGateway?: boolean);
|
|
35
|
+
/**
|
|
36
|
+
* A client for an early Gateway 1 unit, which rejects the last-5 login and
|
|
37
|
+
* needs the full `gatewayPassword`. Everything else is the same.
|
|
38
|
+
*/
|
|
39
|
+
static legacy_gateway(options: PowerwallClientOptions): PowerwallClient;
|
|
40
|
+
get host(): string;
|
|
41
|
+
/** The gateway DIN, or `null` until `connect` succeeds. */
|
|
42
|
+
get din(): string | null;
|
|
43
|
+
/** True between `curtail` and `restore_from_curtailment`. */
|
|
44
|
+
get curtailment_active(): boolean;
|
|
45
|
+
/** Log in and fetch the gateway DIN. Idempotent, and concurrent callers share one attempt. */
|
|
46
|
+
connect(): Promise<string>;
|
|
47
|
+
/** Destroy the idle sockets. */
|
|
48
|
+
close(): void;
|
|
49
|
+
/** The cached DIN, connecting first if needed. */
|
|
50
|
+
get_din(): Promise<string>;
|
|
51
|
+
/** `/api/meters/aggregates`: instantaneous power per location. */
|
|
52
|
+
get_meters_aggregates(): Promise<Record<string, any>>;
|
|
53
|
+
/** The raw state of charge, where the bottom 5% is an inaccessible buffer. It reads higher than the Tesla app. */
|
|
54
|
+
get_battery_soe_raw(): Promise<number>;
|
|
55
|
+
/** The state of charge the Tesla app and Fleet API show. */
|
|
56
|
+
get_battery_soe(): Promise<number>;
|
|
57
|
+
/** The gateway grid status string, such as `SystemGridConnected`. */
|
|
58
|
+
get_grid_status(): Promise<string>;
|
|
59
|
+
/** The gateway's `config.json`. `battery_blocks` is always present. */
|
|
60
|
+
get_config(): Promise<ConfigPayload>;
|
|
61
|
+
/** The gateway status, from the narrow DeviceControllerQuery. */
|
|
62
|
+
get_status(): Promise<StatusPayload>;
|
|
63
|
+
/** The extended DeviceControllerQuery payload. */
|
|
64
|
+
get_device_controller(): Promise<ControllerPayload>;
|
|
65
|
+
/** Powerwall 3 component data: `pch`, `pws`, `bms`, `hvp` and `baggr`. */
|
|
66
|
+
get_components(): Promise<ComponentsPayload>;
|
|
67
|
+
/** Gateway firmware details. Python's `five` and `six` keys are `update_status` and `device_type` here. */
|
|
68
|
+
get_firmware_details(): Promise<FirmwareDetails>;
|
|
69
|
+
/** The active manual backup and any scheduled backup events. Times are epoch seconds. */
|
|
70
|
+
get_backup_events(): Promise<BackupEventsPayload>;
|
|
71
|
+
/**
|
|
72
|
+
* The battery calibration delay counters.
|
|
73
|
+
* @throws PowerwallNotSupportedError on firmware without this command. Powerwall 3 firmware 26.26.4 is one.
|
|
74
|
+
*/
|
|
75
|
+
get_battery_calibration_delay_status(): Promise<BatteryCalibrationDelayStatus>;
|
|
76
|
+
/**
|
|
77
|
+
* The load programs of Backup Switch and smart breaker devices. A site with
|
|
78
|
+
* none returns two empty lists.
|
|
79
|
+
* @param device_ids The devices to read, or every device when omitted.
|
|
80
|
+
*/
|
|
81
|
+
get_controllable_device_programs(device_ids?: string[]): Promise<ControllableDeviceProgramsPayload>;
|
|
82
|
+
/** The keys paired with the gateway, in the gateway's raw form. */
|
|
83
|
+
list_authorized_clients(): Promise<AuthorizedClientsPayload>;
|
|
84
|
+
/**
|
|
85
|
+
* Patch `config.json`, a read-modify-write. The update carries the hash from
|
|
86
|
+
* the read unchanged: it is an optimistic lock held by the gateway, and the
|
|
87
|
+
* client never computes one.
|
|
88
|
+
* @param updates Dotted paths to values, such as `{"site_info.backup_reserve_percent": 24}`.
|
|
89
|
+
* Writes on one client run one at a time, so two cannot interleave. Another
|
|
90
|
+
* client's write is caught by that lock instead, and refused.
|
|
91
|
+
* @throws RangeError on a number that is not finite, before any request.
|
|
92
|
+
* @throws PowerwallProtocolError on bad JSON, or a reply with no `filestore`.
|
|
93
|
+
*/
|
|
94
|
+
write_config(updates: Record<string, unknown>): Promise<void>;
|
|
95
|
+
private _write_config;
|
|
96
|
+
/**
|
|
97
|
+
* Set the backup reserve on the app's 0-100 scale.
|
|
98
|
+
* @throws RangeError outside 0-100.
|
|
99
|
+
*/
|
|
100
|
+
set_backup_reserve(percent: number): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Write the backup reserve on the gateway's raw scale, where app 0% is raw 5%.
|
|
103
|
+
* @throws RangeError outside 0-100.
|
|
104
|
+
*/
|
|
105
|
+
set_backup_reserve_raw(percent: number): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Set the operation mode, as `operation` does through the cloud.
|
|
108
|
+
* @param mode One of `OPERATION_MODES`.
|
|
109
|
+
* @throws RangeError for any other value.
|
|
110
|
+
*/
|
|
111
|
+
set_operation_mode(mode: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Set `strategy.TOU_mode`, which is local-only: the cloud API does not expose it.
|
|
114
|
+
*
|
|
115
|
+
* The gateway does not validate this field, so a typo silently sets an
|
|
116
|
+
* unrecognized mode. Only `economic` is confirmed in use. The tariff itself
|
|
117
|
+
* lives in the cloud and cannot be set here.
|
|
118
|
+
* @throws RangeError on an empty string.
|
|
119
|
+
*/
|
|
120
|
+
set_tou_mode(mode: string): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Set the export rule, the grid-charging flag, or both in one write. See
|
|
123
|
+
* `set_export_rule` and `set_grid_charging` for one of each.
|
|
124
|
+
* @throws RangeError for an unknown rule.
|
|
125
|
+
* @throws TypeError when given neither.
|
|
126
|
+
*/
|
|
127
|
+
set_grid_import_export(options: {
|
|
128
|
+
customer_preferred_export_rule?: string | null;
|
|
129
|
+
disallow_charge_from_grid_with_solar_installed?: boolean | null;
|
|
130
|
+
}): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Set the export rule. `net_meter_mode` is independent and does not move.
|
|
133
|
+
* @param rule `battery_ok` exports solar and battery, `pv_only` solar only, `never` nothing.
|
|
134
|
+
* @throws RangeError for any other value.
|
|
135
|
+
*/
|
|
136
|
+
set_export_rule(rule: string): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Allow or disallow charging from the grid. The gateway stores the inverse
|
|
139
|
+
* flag and drops the key rather than store `false`, so treat an absent key
|
|
140
|
+
* as "allowed".
|
|
141
|
+
*/
|
|
142
|
+
set_grid_charging(enabled: boolean): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Enable on-grid solar curtailment. The gateway drops the key rather than
|
|
145
|
+
* store `false`, so treat an absent key as disabled.
|
|
146
|
+
*/
|
|
147
|
+
set_on_grid_solar_curtailment(enabled: boolean): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Cap grid import, in kilowatts, stored as given.
|
|
150
|
+
* @throws RangeError on a negative value.
|
|
151
|
+
*/
|
|
152
|
+
set_import_limit(kilowatts: number): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Cap grid export, in kilowatts. Pass a positive magnitude: the gateway
|
|
155
|
+
* represents export as negative site-meter power.
|
|
156
|
+
* @throws RangeError on a negative value.
|
|
157
|
+
*/
|
|
158
|
+
set_export_limit(kilowatts: number): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Stop grid export by switching to `backup` mode at a high reserve. This uses
|
|
161
|
+
* a config write, so no contactor cycles, but it takes about 90 seconds to
|
|
162
|
+
* apply. `restore_from_curtailment` puts back what this replaced.
|
|
163
|
+
* @param options.reserve_percent The reserve during curtailment, on the **raw** scale.
|
|
164
|
+
* @throws RangeError outside 0-100.
|
|
165
|
+
*/
|
|
166
|
+
curtail(options?: {
|
|
167
|
+
reserve_percent?: number;
|
|
168
|
+
}): Promise<void>;
|
|
169
|
+
/** Write back what `curtail` replaced, or `self_consumption` at a raw 5 if nothing was saved. */
|
|
170
|
+
restore_from_curtailment(): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Schedule a manual "max backup" event that starts now, at maximum priority.
|
|
173
|
+
* The gateway requires any earlier event to be cancelled first, even an
|
|
174
|
+
* expired one, so this sends that cancel before scheduling.
|
|
175
|
+
* @param duration_seconds At least 60.
|
|
176
|
+
* @throws RangeError on a shorter or fractional duration.
|
|
177
|
+
*/
|
|
178
|
+
schedule_max_backup(duration_seconds?: number): Promise<void>;
|
|
179
|
+
/** Cancel the active manual backup event, if any. */
|
|
180
|
+
cancel_max_backup(): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Request a timed battery power setpoint.
|
|
183
|
+
*
|
|
184
|
+
* The gateway holds it for the duration and then returns to its mode by
|
|
185
|
+
* itself. A new call replaces the active setpoint, power and timer both. The
|
|
186
|
+
* reply only acknowledges the request, so read `get_meters_aggregates` to see
|
|
187
|
+
* what the battery does. Keep durations short and renew them: a third party
|
|
188
|
+
* reports a dispatch discharging below reserve and exporting regardless of the
|
|
189
|
+
* export setting. Verified on Powerwall 3 firmware 26.26.4.
|
|
190
|
+
* @param power_watts Positive discharges, negative charges.
|
|
191
|
+
* @param duration_seconds Whole seconds from 1 to 86400.
|
|
192
|
+
* @throws PowerwallCommandError with code 11 above the site limit. The gateway refuses, and does not clamp.
|
|
193
|
+
* @throws PowerwallNotSupportedError on firmware without this command.
|
|
194
|
+
*/
|
|
195
|
+
dispatch_battery_power(power_watts: number, duration_seconds: number): Promise<void>;
|
|
196
|
+
/** Release a `dispatch_battery_power` setpoint. This does not cancel a manual backup event. */
|
|
197
|
+
resume_battery_operation(): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Postpone the next battery calibration. Powerwall 3 firmware 26.26.4
|
|
200
|
+
* acknowledges this, but its effect is unverified: that firmware cannot report
|
|
201
|
+
* the delay status.
|
|
202
|
+
* @param delay_hours An integer from 1 to `2^32 - 1`.
|
|
203
|
+
*/
|
|
204
|
+
delay_battery_calibration(delay_hours: number): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Point the gateway at an OCPP central system.
|
|
207
|
+
* @throws PowerwallNotSupportedError on firmware without this command. Powerwall 3 firmware 26.26.4 is one.
|
|
208
|
+
*/
|
|
209
|
+
configure_ocpp(csms_base_url: string): Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
* Revoke a paired key. This needs no presence proof, and any paired key can
|
|
212
|
+
* remove any other. Removing the signing key locks this client out, and
|
|
213
|
+
* pairing it again needs the usual registration and breaker toggle. A success
|
|
214
|
+
* carries no fields, so call `list_authorized_clients` to confirm.
|
|
215
|
+
* @param public_key Raw DER bytes, or base64 as `list_authorized_clients` reports it.
|
|
216
|
+
* @throws RangeError on an empty key.
|
|
217
|
+
*/
|
|
218
|
+
remove_authorized_client(public_key: Uint8Array | string): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Ask the gateway to go off grid or reconnect.
|
|
221
|
+
*
|
|
222
|
+
* A success-shaped reply does not prove the contactor moved: PowerSync reports
|
|
223
|
+
* firmware that acknowledges without acting. Read `islanding.contactorClosed`
|
|
224
|
+
* from `get_status` afterwards before relying on it.
|
|
225
|
+
* @param options.off_grid Mode 6 (off grid) when true, mode 1 (on grid) when false.
|
|
226
|
+
* @param options.force Required by some Powerwalls.
|
|
227
|
+
* @param options.mode_override Send this mode instead: 1 or 6.
|
|
228
|
+
* @throws TypeError on any other mode, or an `off_grid` that is not a boolean.
|
|
229
|
+
* @throws PowerwallCommandError on a `REJECTED_*` result, with `code` the enum value and `status_message` its name, or on `common.error_response`.
|
|
230
|
+
*/
|
|
231
|
+
set_island_mode(options: {
|
|
232
|
+
off_grid: boolean;
|
|
233
|
+
force?: boolean;
|
|
234
|
+
mode_override?: number | null;
|
|
235
|
+
}): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Disconnect from the grid. See `set_island_mode`, including its warning: read
|
|
238
|
+
* `islanding.contactorClosed` afterwards.
|
|
239
|
+
* @param options.force Defaults to true.
|
|
240
|
+
*/
|
|
241
|
+
go_off_grid(options?: {
|
|
242
|
+
force?: boolean;
|
|
243
|
+
mode_override?: number | null;
|
|
244
|
+
}): Promise<void>;
|
|
245
|
+
/** Reconnect to the grid. See `set_island_mode`, including its warning: read `islanding.contactorClosed` afterwards. */
|
|
246
|
+
reconnect_grid(): Promise<void>;
|
|
247
|
+
/**
|
|
248
|
+
* The explicit black-start command, which drives the full islanding
|
|
249
|
+
* transition: grid-frequency ramp-down, contactor open, inverter restart.
|
|
250
|
+
* `set_island_mode` only updates the desired mode. No hardware result is
|
|
251
|
+
* recorded for this command, so check the contactor afterwards.
|
|
252
|
+
* @throws PowerwallCommandError on `common.error_response`.
|
|
253
|
+
*/
|
|
254
|
+
trigger_islanding(): Promise<void>;
|
|
255
|
+
private _cancel_manual_backup;
|
|
256
|
+
private _query_graphql;
|
|
257
|
+
private _read_config;
|
|
258
|
+
/** Sign, send once, and decode the reply envelope. */
|
|
259
|
+
private _post;
|
|
260
|
+
/**
|
|
261
|
+
* The one path for Command-header messages.
|
|
262
|
+
*
|
|
263
|
+
* Python's tolerated calls swallow every error, so a BUSY fault while revoking
|
|
264
|
+
* a compromised key reports success with the key still paired. Here `empty`
|
|
265
|
+
* accepts only an empty reply, and `ignored_status` the one refusal that means
|
|
266
|
+
* there was nothing to do.
|
|
267
|
+
* @param din The gateway DIN.
|
|
268
|
+
* @param payload The message's category and request.
|
|
269
|
+
* @param answered Reads the expected response field from a reply.
|
|
270
|
+
* @param request The request's proto field name, for errors.
|
|
271
|
+
* @param missing What to do when the reply lacks the response.
|
|
272
|
+
* @param ignored_status A `common.error_response` code that is not a failure.
|
|
273
|
+
*/
|
|
274
|
+
private _send_command_request;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Convert a reserve percentage from the app's scale to the gateway's raw value.
|
|
278
|
+
* @throws RangeError outside 0-100.
|
|
279
|
+
*/
|
|
280
|
+
export declare function scaled_to_raw_reserve(percent: number): number;
|
|
281
|
+
/** Convert a raw gateway reserve value to the app's scale. */
|
|
282
|
+
export declare function raw_to_scaled_reserve(percent: number): number;
|
|
283
|
+
/**
|
|
284
|
+
* Convert a state of charge from the app's scale to the raw value.
|
|
285
|
+
* @throws RangeError outside 0-100.
|
|
286
|
+
*/
|
|
287
|
+
export declare function scaled_to_raw_soc(percent: number): number;
|
|
288
|
+
/** Convert a raw state of charge to the value the Tesla app and Fleet API show. */
|
|
289
|
+
export declare function raw_to_scaled_soc(percent: number): number;
|
|
290
|
+
/** The raw physical state of charge from a status payload, or `null` when either figure is missing or zero. */
|
|
291
|
+
export declare function battery_level_raw(status: StatusPayload): number | null;
|
|
292
|
+
/** The state of charge the Tesla app and Fleet API show, from a status payload, or `null`. */
|
|
293
|
+
export declare function battery_level(status: StatusPayload): number | null;
|
|
294
|
+
/** Real power in watts by upper-case meter location. Malformed aggregates give `{}`. */
|
|
295
|
+
export declare function current_power(status: StatusPayload): Record<string, number | null>;
|
|
296
|
+
/** Backup runtime in hours at the current load, or `null` when unknown. */
|
|
297
|
+
export declare function backup_time_remaining(status: StatusPayload): number | null;
|