Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/open-nails-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ecoflow-api/rest-client": minor
---

feat: implement additional command methods for Delta2 device, including generator controls, AC charge/discharge settings, and UPS configuration
5 changes: 5 additions & 0 deletions .changeset/short-sites-strive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ecoflow-api/schemas": minor
---

refactor: rename `upsLowerLimitSchema` to `minDischargeSocSchema` and deprecate old schema
5 changes: 5 additions & 0 deletions .changeset/tangy-flowers-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ecoflow-api/schemas": minor
---

fix: update BMS schema constraints to enforce 0-100 range for SOC values
10 changes: 0 additions & 10 deletions packages/rest-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,6 @@ await powerStream.deleteTask(1)

Serial number must start with _R331_

Note: not all commands have been implemented yet.

Todo:
- "operateType":"acOutCfg"
- "operateType":"acChgCfg"
- "operateType":"upsConfig"
- "operateType":"dsgCfg"
- "operateType":"openOilSoc"
- "operateType":"closeOilSoc"

```ts
import {RestClient} from '@ecoflow-api/rest-client';

Expand Down
162 changes: 162 additions & 0 deletions packages/rest-client/src/lib/devices/Delta2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,54 @@ describe("Delta2", () => {
});
});

describe(".setAcDischarge()", () => {
it("sets ac discharge", async () => {
expect.assertions(1);
await delta2.setAcDischarge({
enabled: 1,
out_freq: 1,
out_voltage: 30,
xboost: 1,
});

expect(restClient.setCommandPlain).toHaveBeenCalledWith({
id: 123456789,
version: "1.0",
moduleType: 5,
operateType: "acOutCfg",
params: {
enabled: 1,
out_freq: 1,
out_voltage: 30,
xboost: 1,
},
sn: validSn,
});
});
});

describe(".setAcCharge()", () => {
it("sets ac charge", async () => {
expect.assertions(1);
await delta2.setAcCharge({
chgWatts: 100,
chgPauseFlag: 0,
});

expect(restClient.setCommandPlain).toHaveBeenCalledWith({
id: 123456789,
version: "1.0",
moduleType: 5,
operateType: "acChgCfg",
params: {
chgWatts: 100,
chgPauseFlag: 0,
},
sn: validSn,
});
});
});

describe(".setCarStandByDuration()", () => {
it("sets car standby duration", async () => {
expect.assertions(1);
Expand Down Expand Up @@ -311,4 +359,118 @@ describe("Delta2", () => {
});
});
});

describe(".setUpsMaxSoc()", () => {
it("sets upper SoC for UPS", async () => {
expect.assertions(2);
await delta2.setUpsMaxSoc(0);

expect(restClient.setCommandPlain).toHaveBeenCalledWith({
id: 123456789,
version: "1.0",
moduleType: 2,
operateType: "upsConfig",
params: {
maxChgSoc: 0,
},
sn: validSn,
});

await delta2.setUpsMaxSoc(100);

expect(restClient.setCommandPlain).nthCalledWith(2, {
id: 123456789,
version: "1.0",
moduleType: 2,
operateType: "upsConfig",
params: {
maxChgSoc: 100,
},
sn: validSn,
});
});

it("throws error for invalid values", async () => {
expect.assertions(2);

await expect(delta2.setUpsMaxSoc(-1)).rejects.toThrowError();
await expect(delta2.setUpsMaxSoc(101)).rejects.toThrowError();
});
});

describe(".setSocTurnOnGenerator()", () => {
it("sets SoC to start generator", async () => {
expect.assertions(2);
await delta2.setSocTurnOnGenerator(0);

expect(restClient.setCommandPlain).toHaveBeenCalledWith({
id: 123456789,
version: "1.0",
moduleType: 2,
operateType: "openOilSoc",
params: {
openOilSoc: 0,
},
sn: validSn,
});

await delta2.setSocTurnOnGenerator(100);

expect(restClient.setCommandPlain).nthCalledWith(2, {
id: 123456789,
version: "1.0",
moduleType: 2,
operateType: "openOilSoc",
params: {
openOilSoc: 100,
},
sn: validSn,
});
});

it("throws error for invalid values", async () => {
expect.assertions(2);

await expect(delta2.setMinDischargeSoc(-1)).rejects.toThrowError();
await expect(delta2.setMinDischargeSoc(101)).rejects.toThrowError();
});
});

describe(".setSocTurnOffGenerator()", () => {
it("sets SoC to turn off generator", async () => {
expect.assertions(2);
await delta2.setSocTurnOffGenerator(0);

expect(restClient.setCommandPlain).toHaveBeenCalledWith({
id: 123456789,
version: "1.0",
moduleType: 2,
operateType: "closeOilSoc",
params: {
closeOilSoc: 0,
},
sn: validSn,
});

await delta2.setSocTurnOffGenerator(100);

expect(restClient.setCommandPlain).nthCalledWith(2, {
id: 123456789,
version: "1.0",
moduleType: 2,
operateType: "closeOilSoc",
params: {
closeOilSoc: 100,
},
sn: validSn,
});
});

it("throws error for invalid values", async () => {
expect.assertions(2);

await expect(delta2.setSocTurnOffGenerator(-1)).rejects.toThrowError();
await expect(delta2.setSocTurnOffGenerator(101)).rejects.toThrowError();
});
});
});
Loading