myenergi-api 2.11.0 → 2.12.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 +1 -0
- package/dist/src/MyEnergiAccount.d.ts +3 -0
- package/dist/src/MyEnergiAccount.js +29 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,6 +185,7 @@ await account.addZappiSingleCharge(zappi.id, {
|
|
|
185
185
|
|
|
186
186
|
await account.clearZappiSingleCharges(zappi.id);
|
|
187
187
|
```
|
|
188
|
+
`setZappiSingleCharge` takes the same arguments but replaces the single charges that have the same name, and `removeZappiSingleCharges(id, name)` removes only those. Both leave single charges with other names alone, which suits an automation that should own one entry.
|
|
188
189
|
The API only replaces the complete list of a schedule type; `saveChargeSchedules` gives direct access to that call.
|
|
189
190
|
|
|
190
191
|
## From myenergi documentation
|
|
@@ -29,6 +29,9 @@ export declare class MyEnergiAccount {
|
|
|
29
29
|
hasTariffPrices(hubId: string): Promise<boolean>;
|
|
30
30
|
saveChargeSchedules(deviceId: string, scheduleType: string, chargeSchedules: any[], isActive?: boolean): Promise<unknown>;
|
|
31
31
|
addZappiSingleCharge(deviceId: string, charge: ZappiSingleCharge): Promise<unknown>;
|
|
32
|
+
setZappiSingleCharge(deviceId: string, charge: ZappiSingleCharge): Promise<unknown>;
|
|
33
|
+
removeZappiSingleCharges(deviceId: string, name: string): Promise<unknown>;
|
|
34
|
+
private updateZappiSingleCharges;
|
|
32
35
|
clearZappiSingleCharges(deviceId: string): Promise<unknown>;
|
|
33
36
|
getDualTariff(hubId: string): Promise<DualTariff[]>;
|
|
34
37
|
saveDualTariff(tariffs: DualTariff[]): Promise<unknown>;
|
|
@@ -154,22 +154,39 @@ class MyEnergiAccount {
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
addZappiSingleCharge(deviceId, charge) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
return this.updateZappiSingleCharges(deviceId, () => true, charge);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
setZappiSingleCharge(deviceId, charge) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
return this.updateZappiSingleCharges(deviceId, (c) => c.scheduleNickName !== charge.name, charge);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
removeZappiSingleCharges(deviceId, name) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return this.updateZappiSingleCharges(deviceId, (c) => c.scheduleNickName !== name);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
updateZappiSingleCharges(deviceId, keep, add) {
|
|
157
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
173
|
const [device, vehicles] = yield Promise.all([this.getDeviceChargeSchedules(deviceId), this.getVehicles()]);
|
|
159
174
|
if (!device)
|
|
160
175
|
throw new MyEnergiAccountError("The device does not support charge schedules.");
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
176
|
+
const charges = (device.singleCharges || []).filter(keep).map((c) => this.toSingleChargeRequest(c, vehicles));
|
|
177
|
+
if (add) {
|
|
178
|
+
charges.push(this.toSingleChargeRequest({
|
|
179
|
+
scheduleType: "Single",
|
|
180
|
+
scheduleNickName: add.name,
|
|
181
|
+
chargingOutputName: add.vehicleId,
|
|
182
|
+
chargeAmountMinutes: 0,
|
|
183
|
+
chargeAmountKWh: add.kWh,
|
|
184
|
+
fromTime: add.fromTime,
|
|
185
|
+
toTime: add.toTime,
|
|
186
|
+
singleChargeDay: typeof add.date === "string" ? add.date : this.formatDay(add.date),
|
|
187
|
+
}, vehicles));
|
|
188
|
+
}
|
|
189
|
+
return this.saveChargeSchedules(deviceId, "Single", charges);
|
|
173
190
|
});
|
|
174
191
|
}
|
|
175
192
|
clearZappiSingleCharges(deviceId) {
|
package/package.json
CHANGED