node-red-contrib-power-saver 2.0.5 → 3.0.2
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/.github/FUNDING.yml +12 -0
- package/CHANGELOG.md +1 -37
- package/README.md +3 -191
- package/docs/.vuepress/config.js +67 -0
- package/docs/.vuepress/dist/404.html +15 -0
- package/docs/.vuepress/dist/assets/css/styles.e835bef6.css +8 -0
- package/docs/.vuepress/dist/assets/img/back-to-top.8b37f773.svg +1 -0
- package/docs/.vuepress/dist/assets/img/elvia-config-no-config.b4bb972c.png +0 -0
- package/docs/.vuepress/dist/assets/img/elvia-config-no-tariff.3f89aba8.png +0 -0
- package/docs/.vuepress/dist/assets/img/elvia-config-select-tariff.0f73fd56.png +0 -0
- package/docs/.vuepress/dist/assets/img/elvia-config-subscription-key.8be8ab8a.png +0 -0
- package/docs/.vuepress/dist/assets/img/elvia-flow.bae2a4d5.png +0 -0
- package/docs/.vuepress/dist/assets/img/example-flow-1.3ff3e23f.png +0 -0
- package/docs/.vuepress/dist/assets/img/example-flow-2.b653b58d.png +0 -0
- package/docs/.vuepress/dist/assets/img/migrate-best-save.f73420f6.png +0 -0
- package/docs/.vuepress/dist/assets/img/migrate-power-saver.aae13f9d.png +0 -0
- package/docs/.vuepress/dist/assets/img/node-power-saver.51ff2e5d.png +0 -0
- package/docs/.vuepress/dist/assets/img/node-ps-elvia-add-tariff.94ea2b09.png +0 -0
- package/docs/.vuepress/dist/assets/img/node-ps-receive-price.76eaa418.png +0 -0
- package/docs/.vuepress/dist/assets/img/node-ps-strategy-best-save.392292d5.png +0 -0
- package/docs/.vuepress/dist/assets/img/node-ps-strategy-lowest-price.3a4ad347.png +0 -0
- package/docs/.vuepress/dist/assets/img/power-saver-nordpool-current-state.bf14afde.png +0 -0
- package/docs/.vuepress/dist/assets/img/power-saver-nordpool-events-state.8c392507.png +0 -0
- package/docs/.vuepress/dist/assets/img/power-saver-tibber-mqtt.16891dd2.png +0 -0
- package/docs/.vuepress/dist/assets/js/293.5e967839.js +1 -0
- package/docs/.vuepress/dist/assets/js/491.c183eba3.js +1 -0
- package/docs/.vuepress/dist/assets/js/812.79dad458.js +2 -0
- package/docs/.vuepress/dist/assets/js/812.79dad458.js.LICENSE.txt +8 -0
- package/docs/.vuepress/dist/assets/js/app.4ee3384b.js +1 -0
- package/docs/.vuepress/dist/assets/js/runtime~app.cafd6537.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-08683c60.07fe8291.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-0aca7ba6.aec5ba75.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-0b5e3c8c.d008d8bc.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-1ad821fa.85407071.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-30acb564.73b8e29f.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-3706649a.d7f73384.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-4637f9e4.22ab9413.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-510ed0d4.204a09ec.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-5954bcb2.be07962c.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-5db8da3a.ac192f35.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-61f728ca.802ab15e.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-677dfaed.9bbbd037.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-7c87f26e.457a1a60.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-8daa1a0e.db8b59c6.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-b4a42144.6e0c5aa0.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-e8c55052.5f85b6cd.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-fffb8e28.e815e852.js +1 -0
- package/docs/.vuepress/dist/changelog/index.html +15 -0
- package/docs/.vuepress/dist/contribute/index.html +15 -0
- package/docs/.vuepress/dist/euro.png +0 -0
- package/docs/.vuepress/dist/examples/example-nordpool-current-state.html +169 -0
- package/docs/.vuepress/dist/examples/example-nordpool-events-state.html +173 -0
- package/docs/.vuepress/dist/examples/example-tibber-mqtt.html +182 -0
- package/docs/.vuepress/dist/examples/index.html +15 -0
- package/docs/.vuepress/dist/guide/index.html +52 -0
- package/docs/.vuepress/dist/index.html +15 -0
- package/docs/.vuepress/dist/logo.png +0 -0
- package/docs/.vuepress/dist/nodes/index.html +15 -0
- package/docs/.vuepress/dist/nodes/old-power-saver-doc.html +97 -0
- package/docs/.vuepress/dist/nodes/power-saver.html +15 -0
- package/docs/.vuepress/dist/nodes/ps-elvia-add-tariff.html +15 -0
- package/docs/.vuepress/dist/nodes/ps-receive-price.html +80 -0
- package/docs/.vuepress/dist/nodes/ps-strategy-best-save.html +65 -0
- package/docs/.vuepress/dist/nodes/ps-strategy-lowest-price.html +89 -0
- package/docs/.vuepress/dist/nodes/strategy-input.html +40 -0
- package/docs/.vuepress/public/euro.png +0 -0
- package/docs/.vuepress/public/logo.png +0 -0
- package/docs/README.md +32 -0
- package/docs/changelog/README.md +65 -0
- package/docs/contribute/README.md +39 -0
- package/docs/examples/README.md +5 -0
- package/docs/examples/example-nordpool-current-state.md +166 -0
- package/docs/examples/example-nordpool-events-state.md +170 -0
- package/docs/examples/example-tibber-mqtt.md +179 -0
- package/docs/guide/README.md +202 -0
- package/docs/images/all-nodes.png +0 -0
- package/docs/images/best-save-config.png +0 -0
- package/docs/images/elvia-add-tariff-node-used.png +0 -0
- package/docs/images/elvia-config-no-config.png +0 -0
- package/docs/images/elvia-config-no-tariff.png +0 -0
- package/docs/images/elvia-config-select-tariff.png +0 -0
- package/docs/images/elvia-config-subscription-key.png +0 -0
- package/docs/images/elvia-flow.png +0 -0
- package/docs/images/elvia-tariff-config.png +0 -0
- package/docs/images/euro.png +0 -0
- package/docs/images/example-flow-1.png +0 -0
- package/docs/images/example-flow-2.png +0 -0
- package/docs/images/logo.png +0 -0
- package/docs/images/lowest-price-config.png +0 -0
- package/docs/images/migrate-best-save.png +0 -0
- package/docs/images/migrate-power-saver.png +0 -0
- package/docs/images/node-power-saver.png +0 -0
- package/docs/images/node-ps-elvia-add-tariff.png +0 -0
- package/docs/images/node-ps-elvia-tariff-types.png +0 -0
- package/docs/images/node-ps-elvia-tariff.png +0 -0
- package/docs/images/node-ps-receive-price.png +0 -0
- package/docs/images/node-ps-strategy-best-save.png +0 -0
- package/docs/images/node-ps-strategy-lowest-price.png +0 -0
- package/{doc → docs/images}/node-red-contrib-power-saver-flow.png +0 -0
- package/docs/images/power-saver-nordpool-current-state.png +0 -0
- package/docs/images/power-saver-nordpool-events-state.png +0 -0
- package/docs/images/power-saver-tibber-mqtt.png +0 -0
- package/docs/nodes/README.md +53 -0
- package/docs/nodes/old-power-saver-doc.md +231 -0
- package/docs/nodes/power-saver.md +23 -0
- package/docs/nodes/ps-elvia-add-tariff.md +52 -0
- package/docs/nodes/ps-receive-price.md +153 -0
- package/docs/nodes/ps-strategy-best-save.md +142 -0
- package/docs/nodes/ps-strategy-lowest-price.md +165 -0
- package/docs/nodes/strategy-input.md +39 -0
- package/package.json +19 -4
- package/src/elvia/elvia-add-tariff.html +70 -0
- package/src/elvia/elvia-add-tariff.js +47 -0
- package/src/elvia/elvia-api.js +61 -0
- package/src/elvia/elvia-config.html +46 -0
- package/src/elvia/elvia-config.js +19 -0
- package/src/elvia/elvia-tariff-types.html +34 -0
- package/src/elvia/elvia-tariff-types.js +25 -0
- package/src/elvia/elvia-tariff.html +89 -0
- package/src/elvia/elvia-tariff.js +22 -0
- package/src/elvia/icons/elvia_hvite.svg +4 -0
- package/src/elvia/icons/elvia_positive_4 copy.svg +4 -0
- package/src/handle-input.js +162 -0
- package/src/power-saver.html +116 -0
- package/{power-saver.js → src/power-saver.js} +90 -72
- package/src/receive-price-functions.js +99 -0
- package/src/receive-price.html +30 -0
- package/src/receive-price.js +21 -0
- package/src/strategy-best-save-functions.js +110 -0
- package/src/strategy-best-save.html +116 -0
- package/src/strategy-best-save.js +95 -0
- package/src/strategy-lowest-price-functions.js +35 -0
- package/src/strategy-lowest-price.html +168 -0
- package/src/strategy-lowest-price.js +125 -0
- package/{utils.js → src/utils.js} +59 -104
- package/test/data/adjustedResult.js +302 -0
- package/test/data/adjustedResult_old.js +154 -0
- package/test/data/best-save-result.json +357 -0
- package/test/data/converted-prices.json +196 -0
- package/test/data/elvia-input-grid-tariff.json +760 -0
- package/test/data/elvia-input-power-prices.json +194 -0
- package/test/data/elvia-output-add-tariff.json +290 -0
- package/test/data/lowest-price-result-cont.json +18 -0
- package/test/data/lowest-price-result-split-allday.json +21 -0
- package/test/data/lowest-price-result-split-allday10.json +20 -0
- package/test/data/lowest-price-result-split.json +20 -0
- package/test/data/nordpool-current-state-prices.json +283 -0
- package/test/data/nordpool-event-prices.json +574 -0
- package/test/data/reconfigResult.js +315 -0
- package/test/data/reconfigResult_old.js +141 -0
- package/test/data/result.js +1 -0
- package/test/data/tibber-prices-single-home.json +64 -0
- package/test/data/tibber-prices.json +124 -0
- package/test/data/{tibber_result.json → tibber-result.json} +2 -1
- package/test/elvia.test.js +26 -0
- package/test/mostSavedStrategy.test.js +22 -55
- package/test/power-saver.test.js +4 -38
- package/test/receive-price-functions.test.js +153 -0
- package/test/receive-price.test.js +122 -0
- package/test/send-config-input.test.js +121 -0
- package/test/strategy-best-save-test-utils.js +32 -0
- package/test/strategy-best-save.test.js +103 -0
- package/test/strategy-lowest-price-functions.test.js +40 -0
- package/test/strategy-lowest-price.test.js +472 -0
- package/test/test-utils.js +106 -0
- package/test/utils.test.js +53 -163
- package/doc/example-nordpool-current-state.md +0 -166
- package/doc/example-nordpool-events-state.md +0 -153
- package/doc/example-tibber-mqtt.md +0 -189
- package/doc/power-saver-nordpool-current-state.png +0 -0
- package/doc/power-saver-nordpool-events-state.png +0 -0
- package/doc/power-saver-tibber-mqtt.png +0 -0
- package/mostSavedStrategy.js +0 -84
- package/mostSavedStrategy_v2.js +0 -68
- package/power-saver.html +0 -259
- package/test/data/tibber_data.json +0 -412
- package/test/data/tibber_prices.json +0 -412
|
@@ -1,74 +1,44 @@
|
|
|
1
1
|
const expect = require("expect");
|
|
2
|
-
const
|
|
2
|
+
const { calculate, isOnOffSequencesOk } = require("../src/strategy-best-save-functions");
|
|
3
3
|
|
|
4
4
|
const prices = require("./data/prices");
|
|
5
5
|
|
|
6
6
|
describe("mostSavedStrategy", () => {
|
|
7
|
+
it("evaluates onOff sequences correct", () => {
|
|
8
|
+
expect(isOnOffSequencesOk([], 0, 0)).toBeTruthy();
|
|
9
|
+
expect(isOnOffSequencesOk([true], 0, 0)).toBeTruthy();
|
|
10
|
+
expect(isOnOffSequencesOk([false], 0, 0)).toBeFalsy();
|
|
11
|
+
expect(isOnOffSequencesOk([true, false], 0, 0)).toBeFalsy();
|
|
12
|
+
expect(isOnOffSequencesOk([true, false], 1, 0)).toBeTruthy();
|
|
13
|
+
const onOff = [true, true, false, false, false, true, true, false];
|
|
14
|
+
expect(isOnOffSequencesOk(onOff, 3, 2)).toBeTruthy();
|
|
15
|
+
expect(isOnOffSequencesOk(onOff, 4, 2)).toBeTruthy();
|
|
16
|
+
expect(isOnOffSequencesOk(onOff, 2, 2)).toBeFalsy();
|
|
17
|
+
expect(isOnOffSequencesOk(onOff, 3, 3)).toBeFalsy();
|
|
18
|
+
});
|
|
19
|
+
|
|
7
20
|
it("saves correct hours", () => {
|
|
8
21
|
const values = prices.today.map((p) => p.value);
|
|
9
|
-
expect(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
false,
|
|
17
|
-
false,
|
|
18
|
-
true,
|
|
19
|
-
true,
|
|
20
|
-
]);
|
|
21
|
-
expect(mostSavedStrategy.calculate(values, 3, 1, 0.001)).toEqual([
|
|
22
|
-
true,
|
|
23
|
-
true,
|
|
24
|
-
false,
|
|
25
|
-
false,
|
|
26
|
-
true,
|
|
27
|
-
false,
|
|
28
|
-
false,
|
|
29
|
-
false,
|
|
30
|
-
true,
|
|
31
|
-
true,
|
|
32
|
-
]);
|
|
33
|
-
expect(mostSavedStrategy.calculate(values, 2, 1, 0.001)).toEqual([
|
|
34
|
-
true,
|
|
35
|
-
true,
|
|
36
|
-
true,
|
|
22
|
+
expect(calculate(values, 3, 1, 0.001)).toEqual([true, true, false, false, true, false, false, false, true, true]);
|
|
23
|
+
expect(calculate(values, 3, 1, 0.001)).toEqual([true, true, false, false, true, false, false, false, true, true]);
|
|
24
|
+
expect(calculate(values, 2, 1, 0.001)).toEqual([true, true, true, false, false, true, false, false, true, true]);
|
|
25
|
+
expect(calculate(values, 2, 3, 0.001)).toEqual([true, true, true, false, true, true, false, false, true, true]);
|
|
26
|
+
expect(calculate(values, 2, 0, 0.001)).toEqual([true, true, true, false, false, true, false, false, true, true]);
|
|
27
|
+
const values2 = prices.tomorrow.map((p) => p.value);
|
|
28
|
+
expect(calculate(values2, 2, 1, 0.001, true, 1)).toEqual([
|
|
37
29
|
false,
|
|
38
30
|
false,
|
|
39
31
|
true,
|
|
40
32
|
false,
|
|
41
33
|
false,
|
|
42
34
|
true,
|
|
43
|
-
true,
|
|
44
|
-
]);
|
|
45
|
-
expect(mostSavedStrategy.calculate(values, 2, 3, 0.001)).toEqual([
|
|
46
|
-
true,
|
|
47
|
-
true,
|
|
48
|
-
true,
|
|
49
|
-
false,
|
|
50
|
-
true,
|
|
51
|
-
true,
|
|
52
35
|
false,
|
|
53
36
|
false,
|
|
54
37
|
true,
|
|
55
38
|
true,
|
|
56
39
|
]);
|
|
57
|
-
expect(
|
|
40
|
+
expect(calculate(values2, 2, 1, 0.001, false, 1)).toEqual([
|
|
58
41
|
true,
|
|
59
|
-
true,
|
|
60
|
-
true,
|
|
61
|
-
false,
|
|
62
|
-
false,
|
|
63
|
-
true,
|
|
64
|
-
false,
|
|
65
|
-
false,
|
|
66
|
-
true,
|
|
67
|
-
true,
|
|
68
|
-
]);
|
|
69
|
-
const values2 = prices.tomorrow.map((p) => p.value);
|
|
70
|
-
expect(mostSavedStrategy.calculate(values2, 2, 1, 0.001, true, 1)).toEqual([
|
|
71
|
-
false,
|
|
72
42
|
false,
|
|
73
43
|
true,
|
|
74
44
|
false,
|
|
@@ -79,8 +49,5 @@ describe("mostSavedStrategy", () => {
|
|
|
79
49
|
true,
|
|
80
50
|
true,
|
|
81
51
|
]);
|
|
82
|
-
expect(mostSavedStrategy.calculate(values2, 2, 1, 0.001, false, 1)).toEqual(
|
|
83
|
-
[true, false, true, false, false, true, false, false, true, true]
|
|
84
|
-
);
|
|
85
52
|
});
|
|
86
53
|
});
|
package/test/power-saver.test.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
const cloneDeep = require("lodash.clonedeep");
|
|
2
2
|
const expect = require("expect");
|
|
3
3
|
const helper = require("node-red-node-test-helper");
|
|
4
|
-
const powerSaver = require("../power-saver.js");
|
|
5
|
-
const { DateTime } = require("luxon");
|
|
4
|
+
const powerSaver = require("../src/power-saver.js");
|
|
6
5
|
|
|
7
6
|
const prices = require("./data/prices");
|
|
8
7
|
const result = require("./data/result");
|
|
9
|
-
|
|
10
|
-
const plan = {
|
|
11
|
-
schedule: [
|
|
12
|
-
{ time: "2021-06-20T01:50:00.000+02:00", value: true },
|
|
13
|
-
{ time: "2021-06-20T01:50:00.020+02:00", value: false },
|
|
14
|
-
{ time: "2021-06-20T01:50:00.040+02:00", value: true },
|
|
15
|
-
{ time: "2021-06-20T01:50:00.050+02:00", value: false },
|
|
16
|
-
{ time: "2021-06-20T01:50:00.080+02:00", value: true },
|
|
17
|
-
{ time: "2021-06-20T01:50:00.100+02:00", value: false },
|
|
18
|
-
{ time: "2021-06-20T01:50:00.120+02:00", value: true },
|
|
19
|
-
{ time: "2021-06-20T01:50:00.130+02:00", value: false },
|
|
20
|
-
{ time: "2021-06-20T01:50:00.140+02:00", value: true },
|
|
21
|
-
{ time: "2021-06-20T01:50:00.150+02:00", value: false },
|
|
22
|
-
{ time: "2021-06-20T01:50:00.180+02:00", value: true },
|
|
23
|
-
],
|
|
24
|
-
time: "2021-06-20T01:50:00+02:00",
|
|
25
|
-
};
|
|
8
|
+
const { testPlan: plan, makePayload } = require("./test-utils");
|
|
26
9
|
|
|
27
10
|
helper.init(require.resolve("node-red"));
|
|
28
11
|
|
|
@@ -167,8 +150,8 @@ describe("power-saver Node", function () {
|
|
|
167
150
|
});
|
|
168
151
|
});
|
|
169
152
|
it("works for Tibber data", function (done) {
|
|
170
|
-
const tibberData = require("./data/
|
|
171
|
-
const tibberResult = require("./data/
|
|
153
|
+
const tibberData = require("./data/tibber-prices.json");
|
|
154
|
+
const tibberResult = require("./data/tibber-result.json");
|
|
172
155
|
const flow = makeFlow(4, 2);
|
|
173
156
|
helper.load(powerSaver, flow, function () {
|
|
174
157
|
const n1 = helper.getNode("n1");
|
|
@@ -198,20 +181,3 @@ function makeFlow(maxHoursToSaveInSequence, minHoursOnAfterMaxSequenceSaved) {
|
|
|
198
181
|
{ id: "n4", type: "helper" },
|
|
199
182
|
];
|
|
200
183
|
}
|
|
201
|
-
|
|
202
|
-
function makePayload(prices, time) {
|
|
203
|
-
const payload = cloneDeep(prices);
|
|
204
|
-
payload.time = time;
|
|
205
|
-
let entryTime = DateTime.fromISO(payload.time);
|
|
206
|
-
payload.today.forEach((e) => {
|
|
207
|
-
e.start = entryTime.toISO();
|
|
208
|
-
entryTime = entryTime.plus({ milliseconds: 10 });
|
|
209
|
-
e.end = entryTime.toISO();
|
|
210
|
-
});
|
|
211
|
-
payload.tomorrow?.forEach((e) => {
|
|
212
|
-
e.start = entryTime.toISO();
|
|
213
|
-
entryTime = entryTime.plus({ milliseconds: 10 });
|
|
214
|
-
e.end = entryTime.toISO();
|
|
215
|
-
});
|
|
216
|
-
return payload;
|
|
217
|
-
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const expect = require("expect");
|
|
2
|
+
const { convertMsg } = require("../src/receive-price-functions");
|
|
3
|
+
|
|
4
|
+
describe("receive-price-functions", () => {
|
|
5
|
+
it("can convert input msg", () => {
|
|
6
|
+
const msgStd = {
|
|
7
|
+
payload: {
|
|
8
|
+
today: [
|
|
9
|
+
{ value: 1, start: "2021-06-21T00:00:00+02:00" },
|
|
10
|
+
{ value: 2, start: "2021-06-21T01:00:00+02:00" },
|
|
11
|
+
],
|
|
12
|
+
tomorrow: [
|
|
13
|
+
{ value: 3, start: "2021-06-22T00:00:00+02:00" },
|
|
14
|
+
{ value: 4, start: "2021-06-22T01:00:00+02:00" },
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const msgStdTodayOnly = {
|
|
19
|
+
payload: {
|
|
20
|
+
today: [
|
|
21
|
+
{ value: 1, start: "2021-06-21T00:00:00+02:00" },
|
|
22
|
+
{ value: 2, start: "2021-06-21T01:00:00+02:00" },
|
|
23
|
+
],
|
|
24
|
+
tomorrow: [],
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const msgNordpool = {
|
|
28
|
+
data: {
|
|
29
|
+
new_state: {
|
|
30
|
+
attributes: {
|
|
31
|
+
raw_today: [
|
|
32
|
+
{ value: 1, start: "2021-06-21T00:00:00+02:00" },
|
|
33
|
+
{ value: 2, start: "2021-06-21T01:00:00+02:00" },
|
|
34
|
+
],
|
|
35
|
+
raw_tomorrow: [
|
|
36
|
+
{ value: 3, start: "2021-06-22T00:00:00+02:00" },
|
|
37
|
+
{ value: 4, start: "2021-06-22T01:00:00+02:00" },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const msgTibber = {
|
|
44
|
+
payload: {
|
|
45
|
+
viewer: {
|
|
46
|
+
homes: [
|
|
47
|
+
{
|
|
48
|
+
currentSubscription: {
|
|
49
|
+
priceInfo: {
|
|
50
|
+
current: {
|
|
51
|
+
total: 0.6411,
|
|
52
|
+
energy: 0.505,
|
|
53
|
+
tax: 0.1361,
|
|
54
|
+
startsAt: "2021-06-21T00:00:00+02:00",
|
|
55
|
+
},
|
|
56
|
+
today: [
|
|
57
|
+
{
|
|
58
|
+
total: 1,
|
|
59
|
+
energy: 0.5051,
|
|
60
|
+
tax: 0.1361,
|
|
61
|
+
startsAt: "2021-06-21T00:00:00+02:00",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
total: 2,
|
|
65
|
+
energy: 0.5016,
|
|
66
|
+
tax: 0.1353,
|
|
67
|
+
startsAt: "2021-06-21T01:00:00+02:00",
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
tomorrow: [
|
|
71
|
+
{
|
|
72
|
+
total: 3,
|
|
73
|
+
energy: 0.4521,
|
|
74
|
+
tax: 0.1229,
|
|
75
|
+
startsAt: "2021-06-22T00:00:00+02:00",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
total: 4,
|
|
79
|
+
energy: 0.4488,
|
|
80
|
+
tax: 0.1221,
|
|
81
|
+
startsAt: "2021-06-22T01:00:00+02:00",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const msgTibberSingle = {
|
|
93
|
+
payload: {
|
|
94
|
+
viewer: {
|
|
95
|
+
home: {
|
|
96
|
+
currentSubscription: {
|
|
97
|
+
priceInfo: {
|
|
98
|
+
today: [
|
|
99
|
+
{
|
|
100
|
+
total: 1,
|
|
101
|
+
startsAt: "2021-06-21T00:00:00+02:00",
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
total: 2,
|
|
105
|
+
startsAt: "2021-06-21T01:00:00+02:00",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
tomorrow: [
|
|
109
|
+
{
|
|
110
|
+
total: 3,
|
|
111
|
+
startsAt: "2021-06-22T00:00:00+02:00",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
total: 4,
|
|
115
|
+
startsAt: "2021-06-22T01:00:00+02:00",
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
expect(convertMsg(msgStd)).toEqual({ source: "Other", ...msgStd.payload });
|
|
126
|
+
expect(convertMsg(msgTibber)).toEqual({
|
|
127
|
+
source: "Tibber",
|
|
128
|
+
...msgStd.payload,
|
|
129
|
+
});
|
|
130
|
+
expect(convertMsg(msgTibberSingle)).toEqual({
|
|
131
|
+
source: "Tibber",
|
|
132
|
+
...msgStd.payload,
|
|
133
|
+
});
|
|
134
|
+
expect(convertMsg(msgNordpool)).toEqual({
|
|
135
|
+
source: "Nordpool",
|
|
136
|
+
...msgStd.payload,
|
|
137
|
+
});
|
|
138
|
+
msgTibber.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow = [];
|
|
139
|
+
expect(convertMsg(msgTibber)).toEqual({
|
|
140
|
+
source: "Tibber",
|
|
141
|
+
...msgStdTodayOnly.payload,
|
|
142
|
+
});
|
|
143
|
+
msgNordpool.data.new_state.attributes.raw_tomorrow = [];
|
|
144
|
+
expect(convertMsg(msgNordpool)).toEqual({
|
|
145
|
+
source: "Nordpool",
|
|
146
|
+
...msgStdTodayOnly.payload,
|
|
147
|
+
});
|
|
148
|
+
expect(convertMsg(msgStdTodayOnly)).toEqual({
|
|
149
|
+
source: "Other",
|
|
150
|
+
...msgStdTodayOnly.payload,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const helper = require("node-red-node-test-helper");
|
|
2
|
+
const receivePrices = require("../src/receive-price.js");
|
|
3
|
+
const expect = require("expect");
|
|
4
|
+
|
|
5
|
+
helper.init(require.resolve("node-red"));
|
|
6
|
+
|
|
7
|
+
describe("receive-price node", function () {
|
|
8
|
+
beforeEach(function (done) {
|
|
9
|
+
helper.startServer(done);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(function (done) {
|
|
13
|
+
helper.unload().then(function () {
|
|
14
|
+
helper.stopServer(done);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should be loaded", function (done) {
|
|
19
|
+
const flow = [{ id: "n1", type: "ps-receive-price", name: "test name" }];
|
|
20
|
+
helper.load(receivePrices, flow, function () {
|
|
21
|
+
const n1 = helper.getNode("n1");
|
|
22
|
+
expect(n1).toHaveProperty("name", "test name");
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should convert tibber prices", function (done) {
|
|
28
|
+
const tibberPrices = require("./data/tibber-prices.json");
|
|
29
|
+
const convertedPrices = require("./data/converted-prices.json");
|
|
30
|
+
convertedPrices.priceData.source = "Tibber";
|
|
31
|
+
const flow = [
|
|
32
|
+
{
|
|
33
|
+
id: "n1",
|
|
34
|
+
type: "ps-receive-price",
|
|
35
|
+
name: "Receive prices",
|
|
36
|
+
wires: [["n2"]],
|
|
37
|
+
},
|
|
38
|
+
{ id: "n2", type: "helper" },
|
|
39
|
+
];
|
|
40
|
+
helper.load(receivePrices, flow, function () {
|
|
41
|
+
const n1 = helper.getNode("n1");
|
|
42
|
+
const n2 = helper.getNode("n2");
|
|
43
|
+
n2.on("input", function (msg) {
|
|
44
|
+
expect(msg).toHaveProperty("payload", convertedPrices);
|
|
45
|
+
done();
|
|
46
|
+
});
|
|
47
|
+
n1.receive(tibberPrices);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should convert tibber single home prices", function (done) {
|
|
52
|
+
const tibberPrices = require("./data/tibber-prices-single-home.json");
|
|
53
|
+
const convertedPrices = require("./data/converted-prices.json");
|
|
54
|
+
convertedPrices.priceData.source = "Tibber";
|
|
55
|
+
const flow = [
|
|
56
|
+
{
|
|
57
|
+
id: "n1",
|
|
58
|
+
type: "ps-receive-price",
|
|
59
|
+
name: "Receive prices",
|
|
60
|
+
wires: [["n2"]],
|
|
61
|
+
},
|
|
62
|
+
{ id: "n2", type: "helper" },
|
|
63
|
+
];
|
|
64
|
+
helper.load(receivePrices, flow, function () {
|
|
65
|
+
const n1 = helper.getNode("n1");
|
|
66
|
+
const n2 = helper.getNode("n2");
|
|
67
|
+
n2.on("input", function (msg) {
|
|
68
|
+
expect(msg).toHaveProperty("payload", convertedPrices);
|
|
69
|
+
done();
|
|
70
|
+
});
|
|
71
|
+
n1.receive(tibberPrices);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should convert nordpool event prices", function (done) {
|
|
76
|
+
const nordpoolPrices = require("./data/nordpool-event-prices.json");
|
|
77
|
+
const convertedPrices = require("./data/converted-prices.json");
|
|
78
|
+
convertedPrices.priceData.source = "Nordpool";
|
|
79
|
+
const flow = [
|
|
80
|
+
{
|
|
81
|
+
id: "n1",
|
|
82
|
+
type: "ps-receive-price",
|
|
83
|
+
name: "Receive prices",
|
|
84
|
+
wires: [["n2"]],
|
|
85
|
+
},
|
|
86
|
+
{ id: "n2", type: "helper" },
|
|
87
|
+
];
|
|
88
|
+
helper.load(receivePrices, flow, function () {
|
|
89
|
+
const n1 = helper.getNode("n1");
|
|
90
|
+
const n2 = helper.getNode("n2");
|
|
91
|
+
n2.on("input", function (msg) {
|
|
92
|
+
expect(msg).toHaveProperty("payload", convertedPrices);
|
|
93
|
+
done();
|
|
94
|
+
});
|
|
95
|
+
n1.receive(nordpoolPrices);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should convert nordpool current state prices", function (done) {
|
|
100
|
+
const nordpoolPrices = require("./data/nordpool-current-state-prices.json");
|
|
101
|
+
const convertedPrices = require("./data/converted-prices.json");
|
|
102
|
+
convertedPrices.priceData.source = "Nordpool";
|
|
103
|
+
const flow = [
|
|
104
|
+
{
|
|
105
|
+
id: "n1",
|
|
106
|
+
type: "ps-receive-price",
|
|
107
|
+
name: "Receive prices",
|
|
108
|
+
wires: [["n2"]],
|
|
109
|
+
},
|
|
110
|
+
{ id: "n2", type: "helper" },
|
|
111
|
+
];
|
|
112
|
+
helper.load(receivePrices, flow, function () {
|
|
113
|
+
const n1 = helper.getNode("n1");
|
|
114
|
+
const n2 = helper.getNode("n2");
|
|
115
|
+
n2.on("input", function (msg) {
|
|
116
|
+
expect(msg).toHaveProperty("payload", convertedPrices);
|
|
117
|
+
done();
|
|
118
|
+
});
|
|
119
|
+
n1.receive({ payload: nordpoolPrices });
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const expect = require("expect");
|
|
2
|
+
const helper = require("node-red-node-test-helper");
|
|
3
|
+
const bestSave = require("../src/strategy-best-save.js");
|
|
4
|
+
const { DateTime } = require("luxon");
|
|
5
|
+
const prices = require("./data/converted-prices.json");
|
|
6
|
+
const result = require("./data/best-save-result.json");
|
|
7
|
+
const reconfigResult = require("./data/reconfigResult");
|
|
8
|
+
const adjustedResult = require("./data/adjustedResult");
|
|
9
|
+
const { testPlan, equalPlan } = require("./test-utils");
|
|
10
|
+
const { makeFlow, makePayload } = require("./strategy-best-save-test-utils");
|
|
11
|
+
|
|
12
|
+
helper.init(require.resolve("node-red"));
|
|
13
|
+
|
|
14
|
+
describe("send config as input", () => {
|
|
15
|
+
beforeEach(function (done) {
|
|
16
|
+
helper.startServer(done);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(function (done) {
|
|
20
|
+
helper.unload().then(function () {
|
|
21
|
+
helper.stopServer(done);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should send new schedule on output 3", function (done) {
|
|
26
|
+
const flow = makeFlow(3, 2);
|
|
27
|
+
let pass = 1;
|
|
28
|
+
helper.load(bestSave, flow, function () {
|
|
29
|
+
const n1 = helper.getNode("n1");
|
|
30
|
+
const n2 = helper.getNode("n2");
|
|
31
|
+
n2.on("input", function (msg) {
|
|
32
|
+
switch (pass) {
|
|
33
|
+
case 1:
|
|
34
|
+
pass++;
|
|
35
|
+
expect(equalPlan(result, msg.payload)).toBeTruthy();
|
|
36
|
+
n1.receive({ payload: { config: { minSaving: 1.0 } } });
|
|
37
|
+
break;
|
|
38
|
+
case 2:
|
|
39
|
+
pass++;
|
|
40
|
+
expect(msg.payload.schedule.length).toEqual(1);
|
|
41
|
+
n1.receive({ payload: makePayload(prices, testPlan.time) });
|
|
42
|
+
break;
|
|
43
|
+
case 3:
|
|
44
|
+
pass++;
|
|
45
|
+
expect(msg.payload.schedule.length).toEqual(1);
|
|
46
|
+
done();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
n1.receive({ payload: makePayload(prices, testPlan.time) });
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it("should schedule only from selected time", function (done) {
|
|
53
|
+
const flow = makeFlow(3, 2);
|
|
54
|
+
flow[0].scheduleOnlyFromCurrentTime = false;
|
|
55
|
+
const changeTime = DateTime.fromISO("2021-06-20T01:50:00.045+02:00");
|
|
56
|
+
let pass = 1;
|
|
57
|
+
helper.load(bestSave, flow, function () {
|
|
58
|
+
const n1 = helper.getNode("n1");
|
|
59
|
+
const n2 = helper.getNode("n2");
|
|
60
|
+
n2.on("input", function (msg) {
|
|
61
|
+
switch (pass) {
|
|
62
|
+
case 1:
|
|
63
|
+
pass++;
|
|
64
|
+
expect(equalPlan(result, msg.payload)).toBeTruthy();
|
|
65
|
+
n1.receive({
|
|
66
|
+
payload: {
|
|
67
|
+
config: { scheduleOnlyFromCurrentTime: true },
|
|
68
|
+
time: changeTime,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
break;
|
|
72
|
+
case 2:
|
|
73
|
+
pass++;
|
|
74
|
+
reconfigResult.config.scheduleOnlyFromCurrentTime = true;
|
|
75
|
+
expect(equalPlan(reconfigResult, msg.payload)).toBeTruthy();
|
|
76
|
+
const payload = makePayload(prices, testPlan.time);
|
|
77
|
+
payload.time = changeTime;
|
|
78
|
+
n1.receive({ payload });
|
|
79
|
+
break;
|
|
80
|
+
case 3:
|
|
81
|
+
pass++;
|
|
82
|
+
expect(equalPlan(reconfigResult, msg.payload)).toBeTruthy();
|
|
83
|
+
done();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
n1.receive({ payload: makePayload(prices, testPlan.time) });
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
it("should correct savings for passed hours", function (done) {
|
|
90
|
+
const flow = makeFlow(3, 2);
|
|
91
|
+
const changeTime = DateTime.fromISO("2021-06-20T01:50:00.045+02:00");
|
|
92
|
+
let pass = 1;
|
|
93
|
+
helper.load(bestSave, flow, function () {
|
|
94
|
+
const n1 = helper.getNode("n1");
|
|
95
|
+
const n2 = helper.getNode("n2");
|
|
96
|
+
n2.on("input", function (msg) {
|
|
97
|
+
switch (pass) {
|
|
98
|
+
case 1:
|
|
99
|
+
pass++;
|
|
100
|
+
expect(equalPlan(result, msg.payload)).toBeTruthy();
|
|
101
|
+
n1.receive({
|
|
102
|
+
payload: {
|
|
103
|
+
config: {
|
|
104
|
+
maxHoursToSaveInSequence: 5,
|
|
105
|
+
minSaving: 0.25,
|
|
106
|
+
scheduleOnlyFromCurrentTime: true,
|
|
107
|
+
},
|
|
108
|
+
time: changeTime,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
case 2:
|
|
113
|
+
pass++;
|
|
114
|
+
expect(equalPlan(adjustedResult, msg.payload)).toBeTruthy();
|
|
115
|
+
done();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
n1.receive({ payload: makePayload(prices, testPlan.time) });
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const cloneDeep = require("lodash.clonedeep");
|
|
2
|
+
const { DateTime } = require("luxon");
|
|
3
|
+
|
|
4
|
+
function makeFlow(maxHoursToSaveInSequence, minHoursOnAfterMaxSequenceSaved) {
|
|
5
|
+
return [
|
|
6
|
+
{
|
|
7
|
+
id: "n1",
|
|
8
|
+
type: "ps-strategy-best-save",
|
|
9
|
+
name: "test name",
|
|
10
|
+
maxHoursToSaveInSequence,
|
|
11
|
+
minHoursOnAfterMaxSequenceSaved,
|
|
12
|
+
minSaving: 0.001,
|
|
13
|
+
wires: [["n3"], ["n4"], ["n2"]],
|
|
14
|
+
},
|
|
15
|
+
{ id: "n2", type: "helper" },
|
|
16
|
+
{ id: "n3", type: "helper" },
|
|
17
|
+
{ id: "n4", type: "helper" },
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function makePayload(prices, time) {
|
|
22
|
+
const payload = cloneDeep(prices);
|
|
23
|
+
payload.time = time;
|
|
24
|
+
let entryTime = DateTime.fromISO(payload.time);
|
|
25
|
+
payload.priceData.forEach((e) => {
|
|
26
|
+
e.start = entryTime.toISO();
|
|
27
|
+
entryTime = entryTime.plus({ milliseconds: 10 });
|
|
28
|
+
});
|
|
29
|
+
return payload;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { makeFlow, makePayload };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const cloneDeep = require("lodash.clonedeep");
|
|
2
|
+
const { DateTime } = require("luxon");
|
|
3
|
+
const expect = require("expect");
|
|
4
|
+
const helper = require("node-red-node-test-helper");
|
|
5
|
+
const bestSave = require("../src/strategy-best-save.js");
|
|
6
|
+
const prices = require("./data/converted-prices.json");
|
|
7
|
+
const result = require("./data/best-save-result.json");
|
|
8
|
+
const { testPlan: plan } = require("./test-utils");
|
|
9
|
+
const { makeFlow } = require("./strategy-best-save-test-utils");
|
|
10
|
+
|
|
11
|
+
helper.init(require.resolve("node-red"));
|
|
12
|
+
|
|
13
|
+
describe("ps-strategy-best-save node", function () {
|
|
14
|
+
beforeEach(function (done) {
|
|
15
|
+
helper.startServer(done);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(function (done) {
|
|
19
|
+
helper.unload().then(function () {
|
|
20
|
+
helper.stopServer(done);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should be loaded", function (done) {
|
|
25
|
+
const flow = [{ id: "n1", type: "ps-strategy-best-save", name: "test name" }];
|
|
26
|
+
helper.load(bestSave, flow, function () {
|
|
27
|
+
const n1 = helper.getNode("n1");
|
|
28
|
+
expect(n1).toHaveProperty("name", "test name");
|
|
29
|
+
done();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should log error when illegal data is received", function (done) {
|
|
34
|
+
const flow = [{ id: "n1", type: "ps-strategy-best-save", name: "test name" }];
|
|
35
|
+
helper.load(bestSave, flow, function () {
|
|
36
|
+
const n1 = helper.getNode("n1");
|
|
37
|
+
n1.receive({});
|
|
38
|
+
n1.warn.should.be.calledWithExactly("No payload");
|
|
39
|
+
n1.receive({ payload: "Error" });
|
|
40
|
+
n1.warn.should.be.calledWithExactly("Payload is not an object");
|
|
41
|
+
n1.receive({ payload: [] });
|
|
42
|
+
n1.warn.should.be.calledWithExactly("Payload is missing priceData");
|
|
43
|
+
n1.receive({ payload: { priceData: [] } });
|
|
44
|
+
n1.warn.should.be.calledWithExactly("priceData is empty");
|
|
45
|
+
n1.receive({ payload: { priceData: { today: [], tomorrow: [] } } });
|
|
46
|
+
n1.warn.should.be.calledWithExactly("Illegal priceData in payload. Did you use the receive-price node?");
|
|
47
|
+
|
|
48
|
+
["start", "value"].forEach((attr) => {
|
|
49
|
+
const testData1 = cloneDeep(prices);
|
|
50
|
+
delete testData1.priceData[3][attr];
|
|
51
|
+
n1.receive({ payload: testData1 });
|
|
52
|
+
n1.warn.should.be.calledWithExactly(
|
|
53
|
+
"Malformed entries in priceData. All entries must contain start and value."
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
n1.receive({ payload: cloneDeep(prices) });
|
|
58
|
+
n1.warn.should.not.be.called;
|
|
59
|
+
done();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it("should send new schedule on output 3", function (done) {
|
|
63
|
+
const flow = makeFlow(3, 2);
|
|
64
|
+
helper.load(bestSave, flow, function () {
|
|
65
|
+
const n1 = helper.getNode("n1");
|
|
66
|
+
const n2 = helper.getNode("n2");
|
|
67
|
+
const n3 = helper.getNode("n3");
|
|
68
|
+
const n4 = helper.getNode("n4");
|
|
69
|
+
let countOn = 0;
|
|
70
|
+
let countOff = 0;
|
|
71
|
+
n2.on("input", function (msg) {
|
|
72
|
+
expect(msg).toHaveProperty("payload", result);
|
|
73
|
+
n1.warn.should.not.be.called;
|
|
74
|
+
});
|
|
75
|
+
n3.on("input", function (msg) {
|
|
76
|
+
countOn++;
|
|
77
|
+
expect(msg).toHaveProperty("payload", true);
|
|
78
|
+
if (countOn === 7 && countOff === 7) {
|
|
79
|
+
done();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
n4.on("input", function (msg) {
|
|
83
|
+
countOff++;
|
|
84
|
+
expect(msg).toHaveProperty("payload", false);
|
|
85
|
+
if (countOn === 7 && countOff === 7) {
|
|
86
|
+
done();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
n1.receive({ payload: makePayload(prices, plan.time) });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
function makePayload(prices, time) {
|
|
95
|
+
const payload = cloneDeep(prices);
|
|
96
|
+
payload.time = time;
|
|
97
|
+
let entryTime = DateTime.fromISO(payload.time);
|
|
98
|
+
payload.priceData.forEach((e) => {
|
|
99
|
+
e.start = entryTime.toISO();
|
|
100
|
+
entryTime = entryTime.plus({ milliseconds: 10 });
|
|
101
|
+
});
|
|
102
|
+
return payload;
|
|
103
|
+
}
|