node-red-contrib-power-saver 3.0.8 → 3.1.1

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 (112) hide show
  1. package/docs/.vuepress/config.js +9 -1
  2. package/docs/.vuepress/dist/404.html +3 -3
  3. package/docs/.vuepress/dist/assets/img/add-tariff-flow.eb700d4f.png +0 -0
  4. package/docs/.vuepress/dist/assets/img/best-save-config.93fa3c21.png +0 -0
  5. package/docs/.vuepress/dist/assets/img/lowest-price-config.6d66a8c2.png +0 -0
  6. package/docs/.vuepress/dist/assets/img/next-schedule-entity.4406856a.png +0 -0
  7. package/docs/.vuepress/dist/assets/img/next-schedule-flow.413ad62b.png +0 -0
  8. package/docs/.vuepress/dist/assets/img/next-schedule-sensor.eb896bdd.png +0 -0
  9. package/docs/.vuepress/dist/assets/img/node-ps-general-add-tariff.a3cf6f06.png +0 -0
  10. package/docs/.vuepress/dist/assets/js/app.8016111b.js +1 -0
  11. package/docs/.vuepress/dist/assets/js/runtime~app.0da14230.js +1 -0
  12. package/docs/.vuepress/dist/assets/js/v-0607240a.661e1808.js +1 -0
  13. package/docs/.vuepress/dist/assets/js/v-08683c60.a6b9cf5b.js +1 -0
  14. package/docs/.vuepress/dist/assets/js/v-0aca7ba6.b42fad7f.js +1 -0
  15. package/docs/.vuepress/dist/assets/js/v-0b5e3c8c.34230e16.js +1 -0
  16. package/docs/.vuepress/dist/assets/js/v-1ad821fa.6e2194d0.js +1 -0
  17. package/docs/.vuepress/dist/assets/js/v-1e2b191e.50b8fa18.js +1 -0
  18. package/docs/.vuepress/dist/assets/js/v-30acb564.f2fcd69f.js +1 -0
  19. package/docs/.vuepress/dist/assets/js/v-4637f9e4.38f66bbb.js +1 -0
  20. package/docs/.vuepress/dist/assets/js/v-510ed0d4.9f2a81c6.js +1 -0
  21. package/docs/.vuepress/dist/assets/js/v-5954bcb2.182daf70.js +1 -0
  22. package/docs/.vuepress/dist/assets/js/v-5db8da3a.f2de6cb9.js +1 -0
  23. package/docs/.vuepress/dist/assets/js/v-61f728ca.6fdbbb92.js +1 -0
  24. package/docs/.vuepress/dist/assets/js/v-677dfaed.0013f083.js +1 -0
  25. package/docs/.vuepress/dist/assets/js/v-7446a652.d05e2648.js +1 -0
  26. package/docs/.vuepress/dist/assets/js/v-7c87f26e.1127dcf5.js +1 -0
  27. package/docs/.vuepress/dist/assets/js/v-8daa1a0e.dde202c9.js +1 -0
  28. package/docs/.vuepress/dist/assets/js/v-b4a42144.9e5f9728.js +1 -0
  29. package/docs/.vuepress/dist/assets/js/v-e8c55052.8384b053.js +1 -0
  30. package/docs/.vuepress/dist/assets/js/v-fffb8e28.3406fd88.js +1 -0
  31. package/docs/.vuepress/dist/changelog/index.html +3 -3
  32. package/docs/.vuepress/dist/contribute/index.html +3 -3
  33. package/docs/.vuepress/dist/examples/example-next-schedule-entity.html +25 -0
  34. package/docs/.vuepress/dist/examples/example-nordpool-current-state.html +176 -156
  35. package/docs/.vuepress/dist/examples/example-nordpool-events-state.html +4 -4
  36. package/docs/.vuepress/dist/examples/example-tibber-mqtt.html +4 -4
  37. package/docs/.vuepress/dist/examples/index.html +3 -3
  38. package/docs/.vuepress/dist/faq/index.html +15 -0
  39. package/docs/.vuepress/dist/guide/index.html +4 -4
  40. package/docs/.vuepress/dist/index.html +3 -3
  41. package/docs/.vuepress/dist/logo.png +0 -0
  42. package/docs/.vuepress/dist/nodes/index.html +3 -3
  43. package/docs/.vuepress/dist/nodes/old-power-saver-doc.html +5 -5
  44. package/docs/.vuepress/dist/nodes/power-saver.html +3 -3
  45. package/docs/.vuepress/dist/nodes/ps-elvia-add-tariff.html +3 -3
  46. package/docs/.vuepress/dist/nodes/ps-general-add-tariff.html +15 -0
  47. package/docs/.vuepress/dist/nodes/ps-receive-price.html +6 -6
  48. package/docs/.vuepress/dist/nodes/ps-strategy-best-save.html +4 -4
  49. package/docs/.vuepress/dist/nodes/ps-strategy-lowest-price.html +4 -4
  50. package/docs/.vuepress/dist/nodes/strategy-input.html +4 -4
  51. package/docs/.vuepress/public/logo.png +0 -0
  52. package/docs/README.md +7 -5
  53. package/docs/changelog/README.md +22 -5
  54. package/docs/contribute/README.md +1 -1
  55. package/docs/examples/README.md +4 -0
  56. package/docs/examples/example-next-schedule-entity.md +41 -0
  57. package/docs/examples/example-nordpool-current-state.md +172 -152
  58. package/docs/faq/README.md +23 -0
  59. package/docs/guide/README.md +16 -15
  60. package/docs/images/add-tariff-flow.png +0 -0
  61. package/docs/images/logo copy.png +0 -0
  62. package/docs/images/logo.png +0 -0
  63. package/docs/images/logo.psd +0 -0
  64. package/docs/images/mysterious-plan.png +0 -0
  65. package/docs/images/next-schedule-entity.png +0 -0
  66. package/docs/images/next-schedule-flow.png +0 -0
  67. package/docs/images/next-schedule-sensor.png +0 -0
  68. package/docs/images/node-ps-general-add-tariff.png +0 -0
  69. package/docs/images/node-red-icon-2.svg +30 -0
  70. package/docs/nodes/README.md +6 -0
  71. package/docs/nodes/old-power-saver-doc.md +6 -6
  72. package/docs/nodes/ps-elvia-add-tariff.md +1 -1
  73. package/docs/nodes/ps-general-add-tariff.md +49 -0
  74. package/docs/nodes/ps-receive-price.md +9 -5
  75. package/docs/nodes/ps-strategy-best-save.md +5 -1
  76. package/docs/nodes/ps-strategy-lowest-price.md +3 -3
  77. package/docs/nodes/strategy-input.md +1 -1
  78. package/package.json +3 -2
  79. package/src/elvia/elvia-add-tariff.js +7 -6
  80. package/src/general-add-tariff-functions.js +46 -0
  81. package/src/general-add-tariff.html +186 -0
  82. package/src/general-add-tariff.js +35 -0
  83. package/src/handle-input.js +1 -1
  84. package/src/power-saver.js +1 -1
  85. package/src/receive-price-functions.js +8 -0
  86. package/src/strategy-lowest-price.js +6 -6
  87. package/test/data/nordpool-3-days-prices.json +293 -0
  88. package/test/data/nordpool-3-days-result.json +444 -0
  89. package/test/data/nordpool-prices-in-payload.json +287 -0
  90. package/test/elvia.test.js +16 -2
  91. package/test/general-add-tariff-functions.test.js +104 -0
  92. package/test/general-add-tariff.test.js +183 -0
  93. package/test/receive-price.test.js +22 -0
  94. package/test/strategy-lowest-price-3days.test.js +88 -0
  95. package/docs/.vuepress/dist/assets/js/app.8ccc81e3.js +0 -1
  96. package/docs/.vuepress/dist/assets/js/runtime~app.7653fe7e.js +0 -1
  97. package/docs/.vuepress/dist/assets/js/v-08683c60.07fe8291.js +0 -1
  98. package/docs/.vuepress/dist/assets/js/v-0aca7ba6.aec5ba75.js +0 -1
  99. package/docs/.vuepress/dist/assets/js/v-0b5e3c8c.d008d8bc.js +0 -1
  100. package/docs/.vuepress/dist/assets/js/v-1ad821fa.85407071.js +0 -1
  101. package/docs/.vuepress/dist/assets/js/v-30acb564.73b8e29f.js +0 -1
  102. package/docs/.vuepress/dist/assets/js/v-4637f9e4.22ab9413.js +0 -1
  103. package/docs/.vuepress/dist/assets/js/v-510ed0d4.e5215a83.js +0 -1
  104. package/docs/.vuepress/dist/assets/js/v-5954bcb2.be07962c.js +0 -1
  105. package/docs/.vuepress/dist/assets/js/v-5db8da3a.ac192f35.js +0 -1
  106. package/docs/.vuepress/dist/assets/js/v-61f728ca.802ab15e.js +0 -1
  107. package/docs/.vuepress/dist/assets/js/v-677dfaed.9bbbd037.js +0 -1
  108. package/docs/.vuepress/dist/assets/js/v-7c87f26e.457a1a60.js +0 -1
  109. package/docs/.vuepress/dist/assets/js/v-8daa1a0e.db8b59c6.js +0 -1
  110. package/docs/.vuepress/dist/assets/js/v-b4a42144.6e0c5aa0.js +0 -1
  111. package/docs/.vuepress/dist/assets/js/v-e8c55052.5f85b6cd.js +0 -1
  112. package/docs/.vuepress/dist/assets/js/v-fffb8e28.e815e852.js +0 -1
@@ -0,0 +1,287 @@
1
+ {
2
+ "_msgid": "45d6a7a32390154a",
3
+ "payload": {
4
+ "entity_id": "sensor.nordpool_kwh_oslo_nok_3_10_025",
5
+ "state": "2.171",
6
+ "attributes": {
7
+ "current_price": 2.171,
8
+ "average": 1.868,
9
+ "off peak 1": 1.619,
10
+ "off peak 2": 2.199,
11
+ "peak": 1.849,
12
+ "min": 1.605,
13
+ "max": 2.22,
14
+ "unit": "kWh",
15
+ "currency": "NOK",
16
+ "country": "Norway",
17
+ "region": "Oslo",
18
+ "low price": false,
19
+ "tomorrow_valid": true,
20
+ "today": [
21
+ 1.639, 1.619, 1.609, 1.605, 1.605, 1.61, 1.641, 1.627, 1.685, 1.772, 1.794, 1.778, 1.812, 1.846, 1.873, 1.943,
22
+ 1.972, 2.171, 2.22, 2.21, 2.22, 2.213, 2.192, 2.168
23
+ ],
24
+ "tomorrow": [
25
+ 2.086, 1.992, 1.951, 1.911, 2.058, 2.221, 2.875, 4.838, 5.338, 5.05, 4.603, 4.186, 3.567, 4.335, 4.987, 5.281,
26
+ 5.424, 5.672, 5.739, 5.418, 3.303, 4.581, 3.114, 2.751
27
+ ],
28
+ "raw_today": [
29
+ {
30
+ "start": "2021-12-19T00:00:00+01:00",
31
+ "end": "2021-12-19T01:00:00+01:00",
32
+ "value": 1.639
33
+ },
34
+ {
35
+ "start": "2021-12-19T01:00:00+01:00",
36
+ "end": "2021-12-19T02:00:00+01:00",
37
+ "value": 1.619
38
+ },
39
+ {
40
+ "start": "2021-12-19T02:00:00+01:00",
41
+ "end": "2021-12-19T03:00:00+01:00",
42
+ "value": 1.609
43
+ },
44
+ {
45
+ "start": "2021-12-19T03:00:00+01:00",
46
+ "end": "2021-12-19T04:00:00+01:00",
47
+ "value": 1.605
48
+ },
49
+ {
50
+ "start": "2021-12-19T04:00:00+01:00",
51
+ "end": "2021-12-19T05:00:00+01:00",
52
+ "value": 1.605
53
+ },
54
+ {
55
+ "start": "2021-12-19T05:00:00+01:00",
56
+ "end": "2021-12-19T06:00:00+01:00",
57
+ "value": 1.61
58
+ },
59
+ {
60
+ "start": "2021-12-19T06:00:00+01:00",
61
+ "end": "2021-12-19T07:00:00+01:00",
62
+ "value": 1.641
63
+ },
64
+ {
65
+ "start": "2021-12-19T07:00:00+01:00",
66
+ "end": "2021-12-19T08:00:00+01:00",
67
+ "value": 1.627
68
+ },
69
+ {
70
+ "start": "2021-12-19T08:00:00+01:00",
71
+ "end": "2021-12-19T09:00:00+01:00",
72
+ "value": 1.685
73
+ },
74
+ {
75
+ "start": "2021-12-19T09:00:00+01:00",
76
+ "end": "2021-12-19T10:00:00+01:00",
77
+ "value": 1.772
78
+ },
79
+ {
80
+ "start": "2021-12-19T10:00:00+01:00",
81
+ "end": "2021-12-19T11:00:00+01:00",
82
+ "value": 1.794
83
+ },
84
+ {
85
+ "start": "2021-12-19T11:00:00+01:00",
86
+ "end": "2021-12-19T12:00:00+01:00",
87
+ "value": 1.778
88
+ },
89
+ {
90
+ "start": "2021-12-19T12:00:00+01:00",
91
+ "end": "2021-12-19T13:00:00+01:00",
92
+ "value": 1.812
93
+ },
94
+ {
95
+ "start": "2021-12-19T13:00:00+01:00",
96
+ "end": "2021-12-19T14:00:00+01:00",
97
+ "value": 1.846
98
+ },
99
+ {
100
+ "start": "2021-12-19T14:00:00+01:00",
101
+ "end": "2021-12-19T15:00:00+01:00",
102
+ "value": 1.873
103
+ },
104
+ {
105
+ "start": "2021-12-19T15:00:00+01:00",
106
+ "end": "2021-12-19T16:00:00+01:00",
107
+ "value": 1.943
108
+ },
109
+ {
110
+ "start": "2021-12-19T16:00:00+01:00",
111
+ "end": "2021-12-19T17:00:00+01:00",
112
+ "value": 1.972
113
+ },
114
+ {
115
+ "start": "2021-12-19T17:00:00+01:00",
116
+ "end": "2021-12-19T18:00:00+01:00",
117
+ "value": 2.171
118
+ },
119
+ {
120
+ "start": "2021-12-19T18:00:00+01:00",
121
+ "end": "2021-12-19T19:00:00+01:00",
122
+ "value": 2.22
123
+ },
124
+ {
125
+ "start": "2021-12-19T19:00:00+01:00",
126
+ "end": "2021-12-19T20:00:00+01:00",
127
+ "value": 2.21
128
+ },
129
+ {
130
+ "start": "2021-12-19T20:00:00+01:00",
131
+ "end": "2021-12-19T21:00:00+01:00",
132
+ "value": 2.22
133
+ },
134
+ {
135
+ "start": "2021-12-19T21:00:00+01:00",
136
+ "end": "2021-12-19T22:00:00+01:00",
137
+ "value": 2.213
138
+ },
139
+ {
140
+ "start": "2021-12-19T22:00:00+01:00",
141
+ "end": "2021-12-19T23:00:00+01:00",
142
+ "value": 2.192
143
+ },
144
+ {
145
+ "start": "2021-12-19T23:00:00+01:00",
146
+ "end": "2021-12-20T00:00:00+01:00",
147
+ "value": 2.168
148
+ }
149
+ ],
150
+ "raw_tomorrow": [
151
+ {
152
+ "start": "2021-12-20T00:00:00+01:00",
153
+ "end": "2021-12-20T01:00:00+01:00",
154
+ "value": 2.086
155
+ },
156
+ {
157
+ "start": "2021-12-20T01:00:00+01:00",
158
+ "end": "2021-12-20T02:00:00+01:00",
159
+ "value": 1.992
160
+ },
161
+ {
162
+ "start": "2021-12-20T02:00:00+01:00",
163
+ "end": "2021-12-20T03:00:00+01:00",
164
+ "value": 1.951
165
+ },
166
+ {
167
+ "start": "2021-12-20T03:00:00+01:00",
168
+ "end": "2021-12-20T04:00:00+01:00",
169
+ "value": 1.911
170
+ },
171
+ {
172
+ "start": "2021-12-20T04:00:00+01:00",
173
+ "end": "2021-12-20T05:00:00+01:00",
174
+ "value": 2.058
175
+ },
176
+ {
177
+ "start": "2021-12-20T05:00:00+01:00",
178
+ "end": "2021-12-20T06:00:00+01:00",
179
+ "value": 2.221
180
+ },
181
+ {
182
+ "start": "2021-12-20T06:00:00+01:00",
183
+ "end": "2021-12-20T07:00:00+01:00",
184
+ "value": 2.875
185
+ },
186
+ {
187
+ "start": "2021-12-20T07:00:00+01:00",
188
+ "end": "2021-12-20T08:00:00+01:00",
189
+ "value": 4.838
190
+ },
191
+ {
192
+ "start": "2021-12-20T08:00:00+01:00",
193
+ "end": "2021-12-20T09:00:00+01:00",
194
+ "value": 5.338
195
+ },
196
+ {
197
+ "start": "2021-12-20T09:00:00+01:00",
198
+ "end": "2021-12-20T10:00:00+01:00",
199
+ "value": 5.05
200
+ },
201
+ {
202
+ "start": "2021-12-20T10:00:00+01:00",
203
+ "end": "2021-12-20T11:00:00+01:00",
204
+ "value": 4.603
205
+ },
206
+ {
207
+ "start": "2021-12-20T11:00:00+01:00",
208
+ "end": "2021-12-20T12:00:00+01:00",
209
+ "value": 4.186
210
+ },
211
+ {
212
+ "start": "2021-12-20T12:00:00+01:00",
213
+ "end": "2021-12-20T13:00:00+01:00",
214
+ "value": 3.567
215
+ },
216
+ {
217
+ "start": "2021-12-20T13:00:00+01:00",
218
+ "end": "2021-12-20T14:00:00+01:00",
219
+ "value": 4.335
220
+ },
221
+ {
222
+ "start": "2021-12-20T14:00:00+01:00",
223
+ "end": "2021-12-20T15:00:00+01:00",
224
+ "value": 4.987
225
+ },
226
+ {
227
+ "start": "2021-12-20T15:00:00+01:00",
228
+ "end": "2021-12-20T16:00:00+01:00",
229
+ "value": 5.281
230
+ },
231
+ {
232
+ "start": "2021-12-20T16:00:00+01:00",
233
+ "end": "2021-12-20T17:00:00+01:00",
234
+ "value": 5.424
235
+ },
236
+ {
237
+ "start": "2021-12-20T17:00:00+01:00",
238
+ "end": "2021-12-20T18:00:00+01:00",
239
+ "value": 5.672
240
+ },
241
+ {
242
+ "start": "2021-12-20T18:00:00+01:00",
243
+ "end": "2021-12-20T19:00:00+01:00",
244
+ "value": 5.739
245
+ },
246
+ {
247
+ "start": "2021-12-20T19:00:00+01:00",
248
+ "end": "2021-12-20T20:00:00+01:00",
249
+ "value": 5.418
250
+ },
251
+ {
252
+ "start": "2021-12-20T20:00:00+01:00",
253
+ "end": "2021-12-20T21:00:00+01:00",
254
+ "value": 3.303
255
+ },
256
+ {
257
+ "start": "2021-12-20T21:00:00+01:00",
258
+ "end": "2021-12-20T22:00:00+01:00",
259
+ "value": 4.581
260
+ },
261
+ {
262
+ "start": "2021-12-20T22:00:00+01:00",
263
+ "end": "2021-12-20T23:00:00+01:00",
264
+ "value": 3.114
265
+ },
266
+ {
267
+ "start": "2021-12-20T23:00:00+01:00",
268
+ "end": "2021-12-21T00:00:00+01:00",
269
+ "value": 2.751
270
+ }
271
+ ],
272
+ "unit_of_measurement": "NOK/kWh",
273
+ "icon": "mdi:flash",
274
+ "friendly_name": "nordpool_kwh_oslo_nok_3_10_025"
275
+ },
276
+ "last_changed": "2021-12-19T16:00:00.099173+00:00",
277
+ "last_updated": "2021-12-19T16:00:00.099173+00:00",
278
+ "context": {
279
+ "id": "bd31b337e9271ec5ee5b8c1c170840c2",
280
+ "parent_id": null,
281
+ "user_id": null
282
+ },
283
+ "timeSinceChangedMs": 815634,
284
+ "original_state": "2.171"
285
+ },
286
+ "topic": ""
287
+ }
@@ -1,5 +1,6 @@
1
1
  const helper = require("node-red-node-test-helper");
2
2
  const elviaAddTariff = require("../src/elvia/elvia-add-tariff.js");
3
+ const elviaConfig = require("../src/elvia/elvia-config.js");
3
4
  const expect = require("expect");
4
5
 
5
6
  helper.init(require.resolve("node-red"));
@@ -16,8 +17,21 @@ describe("ps-elvia-add-tariff node", function () {
16
17
  });
17
18
 
18
19
  it("should be loaded", function (done) {
19
- const flow = [{ id: "n1", type: "ps-elvia-add-tariff", name: "test name" }];
20
- helper.load(elviaAddTariff, flow, function () {
20
+ const flow = [
21
+ // elviaConfig.credentials.elviaSubscriptionKey
22
+ {
23
+ id: "n1",
24
+ type: "ps-elvia-add-tariff",
25
+ name: "test name",
26
+ elviaConfig: "n2",
27
+ },
28
+ {
29
+ id: "n2",
30
+ type: "ps-elvia-config",
31
+ name: "test name",
32
+ },
33
+ ];
34
+ helper.load([elviaAddTariff, elviaConfig], flow, function () {
21
35
  const n1 = helper.getNode("n1");
22
36
  expect(n1).toHaveProperty("name", "test name");
23
37
  done();
@@ -0,0 +1,104 @@
1
+ const expect = require("expect");
2
+ const { DateTime } = require("luxon");
3
+ const { addTariffToPrices, buildAllHours } = require("../src/general-add-tariff-functions");
4
+
5
+ describe("general-add-tariff-functions", () => {
6
+ it("can build all hours 6-22", () => {
7
+ const periods = [
8
+ { start: "06", value: 10 },
9
+ { start: "22", value: 11 },
10
+ ];
11
+ const result = [];
12
+ fillResult(result, 0, 5, 11);
13
+ fillResult(result, 6, 21, 10);
14
+ fillResult(result, 22, 23, 11);
15
+
16
+ expect(buildAllHours(console, periods)).toEqual(result);
17
+ });
18
+ it("can build all hours 0-22", () => {
19
+ const periods = [
20
+ { start: "00", value: 10 },
21
+ { start: "22", value: 11 },
22
+ ];
23
+ const result = [];
24
+ fillResult(result, 0, 21, 10);
25
+ fillResult(result, 22, 23, 11);
26
+
27
+ expect(buildAllHours(console, periods)).toEqual(result);
28
+ });
29
+ it("can build all hours 22-23", () => {
30
+ const periods = [
31
+ { start: "00", value: 10 },
32
+ { start: "23", value: 11 },
33
+ ];
34
+ const result = [];
35
+ fillResult(result, 0, 22, 10);
36
+ fillResult(result, 23, 23, 11);
37
+
38
+ expect(buildAllHours(console, periods)).toEqual(result);
39
+ });
40
+ it("can add tariff to prices", () => {
41
+ const config = {
42
+ validFrom: "2021-12-01",
43
+ validTo: "2021-12-10",
44
+ periods: [
45
+ { start: "06", value: 10 },
46
+ { start: "22", value: 11 },
47
+ ],
48
+ };
49
+ const values = [];
50
+ fillResult(values, 0, 5, 21);
51
+ fillResult(values, 6, 21, 20);
52
+ fillResult(values, 22, 23, 21);
53
+ const prices = values.map((_, i) => {
54
+ const start = DateTime.fromISO(config.validFrom).plus({ hours: i }).toISO();
55
+ return {
56
+ start,
57
+ value: 10,
58
+ };
59
+ });
60
+ const result = values.map((v, i) => {
61
+ const start = DateTime.fromISO(config.validFrom).plus({ hours: i }).toISO();
62
+ return {
63
+ start,
64
+ value: v,
65
+ };
66
+ });
67
+ addTariffToPrices(console, config, prices);
68
+ expect(prices).toEqual(result);
69
+ });
70
+ it("pass through when out of period", () => {
71
+ const config = {
72
+ validFrom: "2021-12-01",
73
+ validTo: "2021-12-10",
74
+ periods: [
75
+ { start: "06", value: 10 },
76
+ { start: "22", value: 11 },
77
+ ],
78
+ };
79
+ const values = [];
80
+ fillResult(values, 0, 23, 10);
81
+ const prices = values.map((_, i) => {
82
+ const start = DateTime.fromISO(config.validFrom).plus({ days: 20, hours: i }).toISO();
83
+ return {
84
+ start,
85
+ value: 10,
86
+ };
87
+ });
88
+ const result = values.map((v, i) => {
89
+ const start = DateTime.fromISO(config.validFrom).plus({ days: 20, hours: i }).toISO();
90
+ return {
91
+ start,
92
+ value: v,
93
+ };
94
+ });
95
+ addTariffToPrices(console, config, prices);
96
+ expect(prices).toEqual(result);
97
+ });
98
+ });
99
+
100
+ function fillResult(arr, from, to, value) {
101
+ for (let start = from; start <= to; start++) {
102
+ arr[start] = value;
103
+ }
104
+ }
@@ -0,0 +1,183 @@
1
+ const helper = require("node-red-node-test-helper");
2
+ const addTariff = require("../src/general-add-tariff.js");
3
+ const expect = require("expect");
4
+ const cloneDeep = require("lodash.clonedeep");
5
+
6
+ const prices = {
7
+ source: "Test",
8
+ priceData: [
9
+ {
10
+ value: 0.2,
11
+ start: "2021-10-11T00:00:00.000+02:00",
12
+ },
13
+ {
14
+ value: 0.3,
15
+ start: "2021-10-11T01:00:00.000+02:00",
16
+ },
17
+ {
18
+ value: 0.1,
19
+ start: "2021-10-11T02:00:00.000+02:00",
20
+ },
21
+ {
22
+ value: 1.2345,
23
+ start: "2021-10-11T03:00:00.000+02:00",
24
+ },
25
+ {
26
+ value: 2.1,
27
+ start: "2021-10-12T00:00:00.000+02:00",
28
+ },
29
+ {
30
+ value: 2.2,
31
+ start: "2021-10-12T01:00:00.000+02:00",
32
+ },
33
+ ],
34
+ };
35
+
36
+ helper.init(require.resolve("node-red"));
37
+
38
+ describe("general-add-tariff node", function () {
39
+ beforeEach(function (done) {
40
+ helper.startServer(done);
41
+ });
42
+
43
+ afterEach(function (done) {
44
+ helper.unload().then(function () {
45
+ helper.stopServer(done);
46
+ });
47
+ });
48
+
49
+ it("should be loaded", function (done) {
50
+ const flow = [{ id: "n1", type: "ps-general-add-tariff", name: "test name" }];
51
+ helper.load(addTariff, flow, function () {
52
+ const n1 = helper.getNode("n1");
53
+ expect(n1).toHaveProperty("name", "test name");
54
+ done();
55
+ });
56
+ });
57
+
58
+ it("should add to price", function (done) {
59
+ const flow = [
60
+ {
61
+ id: "n1",
62
+ type: "ps-general-add-tariff",
63
+ name: "Add tariff",
64
+ wires: [["n2"]],
65
+ periods: [
66
+ { start: "01", value: "0.50" },
67
+ { start: "03", value: "0.80" },
68
+ ],
69
+ },
70
+ { id: "n2", type: "helper" },
71
+ ];
72
+ const result = cloneDeep(prices);
73
+ result.priceData[0].value = 1.0;
74
+ result.priceData[1].value = 0.8;
75
+ result.priceData[2].value = 0.6;
76
+ result.priceData[3].value = 2.0345;
77
+ result.priceData[4].value = 2.9;
78
+ result.priceData[5].value = 2.7;
79
+ helper.load(addTariff, flow, function () {
80
+ const n1 = helper.getNode("n1");
81
+ const n2 = helper.getNode("n2");
82
+ n2.on("input", function (msg) {
83
+ expect(msg).toHaveProperty("payload", result);
84
+ done();
85
+ });
86
+ n1.receive({ payload: prices });
87
+ });
88
+ });
89
+ it("should add to price when only first day is valid", function (done) {
90
+ const flow = [
91
+ {
92
+ id: "n1",
93
+ type: "ps-general-add-tariff",
94
+ name: "Add tariff",
95
+ wires: [["n2"]],
96
+ periods: [
97
+ { start: "01", value: "0.50" },
98
+ { start: "03", value: "0.80" },
99
+ ],
100
+ validFrom: "2021-10-11",
101
+ validTo: "2021-10-11",
102
+ },
103
+ { id: "n2", type: "helper" },
104
+ ];
105
+ const result = cloneDeep(prices);
106
+ console.log(JSON.stringify(result, null, 2));
107
+ result.priceData[0].value = 1.0;
108
+ result.priceData[1].value = 0.8;
109
+ result.priceData[2].value = 0.6;
110
+ result.priceData[3].value = 2.0345;
111
+ result.priceData[4].value = 2.1;
112
+ result.priceData[5].value = 2.2;
113
+ helper.load(addTariff, flow, function () {
114
+ const n1 = helper.getNode("n1");
115
+ const n2 = helper.getNode("n2");
116
+ n2.on("input", function (msg) {
117
+ expect(msg).toHaveProperty("payload", result);
118
+ done();
119
+ });
120
+ n1.receive({ payload: prices });
121
+ });
122
+ });
123
+ it("should add to price when only last day is valid", function (done) {
124
+ const flow = [
125
+ {
126
+ id: "n1",
127
+ type: "ps-general-add-tariff",
128
+ name: "Add tariff",
129
+ wires: [["n2"]],
130
+ periods: [
131
+ { start: "01", value: "0.50" },
132
+ { start: "03", value: "0.80" },
133
+ ],
134
+ validFrom: "2021-10-12",
135
+ },
136
+ { id: "n2", type: "helper" },
137
+ ];
138
+ const result = cloneDeep(prices);
139
+ result.priceData[0].value = 0.2;
140
+ result.priceData[1].value = 0.3;
141
+ result.priceData[2].value = 0.1;
142
+ result.priceData[3].value = 1.2345;
143
+ result.priceData[4].value = 2.9;
144
+ result.priceData[5].value = 2.7;
145
+ helper.load(addTariff, flow, function () {
146
+ const n1 = helper.getNode("n1");
147
+ const n2 = helper.getNode("n2");
148
+ n2.on("input", function (msg) {
149
+ expect(msg).toHaveProperty("payload", result);
150
+ done();
151
+ });
152
+ n1.receive({ payload: prices });
153
+ });
154
+ });
155
+ it("should add to price when only one period", function (done) {
156
+ const flow = [
157
+ {
158
+ id: "n1",
159
+ type: "ps-general-add-tariff",
160
+ name: "Add tariff",
161
+ wires: [["n2"]],
162
+ periods: [{ start: "01", value: "0.50" }],
163
+ },
164
+ { id: "n2", type: "helper" },
165
+ ];
166
+ const result = cloneDeep(prices);
167
+ result.priceData[0].value = 0.7;
168
+ result.priceData[1].value = 0.8;
169
+ result.priceData[2].value = 0.6;
170
+ result.priceData[3].value = 1.7345;
171
+ result.priceData[4].value = 2.6;
172
+ result.priceData[5].value = 2.7;
173
+ helper.load(addTariff, flow, function () {
174
+ const n1 = helper.getNode("n1");
175
+ const n2 = helper.getNode("n2");
176
+ n2.on("input", function (msg) {
177
+ expect(msg).toHaveProperty("payload", result);
178
+ done();
179
+ });
180
+ n1.receive({ payload: prices });
181
+ });
182
+ });
183
+ });
@@ -120,4 +120,26 @@ describe("receive-price node", function () {
120
120
  n1.receive({ payload: nordpoolPrices.payload, data: nordpoolPrices.data });
121
121
  });
122
122
  });
123
+ it("should convert nordpool data in payload", function (done) {
124
+ const nordpoolPrices = require("./data/nordpool-prices-in-payload.json");
125
+ const flow = [
126
+ {
127
+ id: "n1",
128
+ type: "ps-receive-price",
129
+ name: "Receive prices",
130
+ wires: [["n2"]],
131
+ },
132
+ { id: "n2", type: "helper" },
133
+ ];
134
+ helper.load(receivePrices, flow, function () {
135
+ const n1 = helper.getNode("n1");
136
+ const n2 = helper.getNode("n2");
137
+ n2.on("input", function (msg) {
138
+ expect(msg.payload.priceData.length).toEqual(48);
139
+ expect(msg.payload.source).toEqual("Nordpool");
140
+ done();
141
+ });
142
+ n1.receive({ payload: nordpoolPrices.payload });
143
+ });
144
+ });
123
145
  });