node-red-contrib-power-saver 2.1.0 → 3.0.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.
Files changed (174) hide show
  1. package/CHANGELOG.md +1 -43
  2. package/README.md +3 -231
  3. package/docs/.vuepress/config.js +67 -0
  4. package/docs/.vuepress/dist/404.html +15 -0
  5. package/docs/.vuepress/dist/assets/css/styles.e835bef6.css +8 -0
  6. package/docs/.vuepress/dist/assets/img/back-to-top.8b37f773.svg +1 -0
  7. package/docs/.vuepress/dist/assets/img/elvia-config-no-config.b4bb972c.png +0 -0
  8. package/docs/.vuepress/dist/assets/img/elvia-config-no-tariff.3f89aba8.png +0 -0
  9. package/docs/.vuepress/dist/assets/img/elvia-config-select-tariff.0f73fd56.png +0 -0
  10. package/docs/.vuepress/dist/assets/img/elvia-config-subscription-key.8be8ab8a.png +0 -0
  11. package/docs/.vuepress/dist/assets/img/elvia-flow.bae2a4d5.png +0 -0
  12. package/docs/.vuepress/dist/assets/img/example-flow-1.3ff3e23f.png +0 -0
  13. package/docs/.vuepress/dist/assets/img/example-flow-2.b653b58d.png +0 -0
  14. package/docs/.vuepress/dist/assets/img/migrate-best-save.f73420f6.png +0 -0
  15. package/docs/.vuepress/dist/assets/img/migrate-power-saver.aae13f9d.png +0 -0
  16. package/docs/.vuepress/dist/assets/img/node-power-saver.51ff2e5d.png +0 -0
  17. package/docs/.vuepress/dist/assets/img/node-ps-elvia-add-tariff.94ea2b09.png +0 -0
  18. package/docs/.vuepress/dist/assets/img/node-ps-receive-price.76eaa418.png +0 -0
  19. package/docs/.vuepress/dist/assets/img/node-ps-strategy-best-save.392292d5.png +0 -0
  20. package/docs/.vuepress/dist/assets/img/node-ps-strategy-lowest-price.3a4ad347.png +0 -0
  21. package/docs/.vuepress/dist/assets/img/power-saver-nordpool-current-state.bf14afde.png +0 -0
  22. package/docs/.vuepress/dist/assets/img/power-saver-nordpool-events-state.8c392507.png +0 -0
  23. package/docs/.vuepress/dist/assets/img/power-saver-tibber-mqtt.16891dd2.png +0 -0
  24. package/docs/.vuepress/dist/assets/js/293.5e967839.js +1 -0
  25. package/docs/.vuepress/dist/assets/js/491.c183eba3.js +1 -0
  26. package/docs/.vuepress/dist/assets/js/812.79dad458.js +2 -0
  27. package/docs/.vuepress/dist/assets/js/812.79dad458.js.LICENSE.txt +8 -0
  28. package/docs/.vuepress/dist/assets/js/app.80d4373d.js +1 -0
  29. package/docs/.vuepress/dist/assets/js/runtime~app.665b411c.js +1 -0
  30. package/docs/.vuepress/dist/assets/js/v-08683c60.9edcaa60.js +1 -0
  31. package/docs/.vuepress/dist/assets/js/v-0aca7ba6.5eca5160.js +1 -0
  32. package/docs/.vuepress/dist/assets/js/v-0b5e3c8c.c02472fb.js +1 -0
  33. package/docs/.vuepress/dist/assets/js/v-1ad821fa.a628e907.js +1 -0
  34. package/docs/.vuepress/dist/assets/js/v-30acb564.80b4190d.js +1 -0
  35. package/docs/.vuepress/dist/assets/js/v-3706649a.d7f73384.js +1 -0
  36. package/docs/.vuepress/dist/assets/js/v-4637f9e4.df94c6ea.js +1 -0
  37. package/docs/.vuepress/dist/assets/js/v-510ed0d4.a78d8542.js +1 -0
  38. package/docs/.vuepress/dist/assets/js/v-5954bcb2.4f4712f3.js +1 -0
  39. package/docs/.vuepress/dist/assets/js/v-5db8da3a.2e49b81a.js +1 -0
  40. package/docs/.vuepress/dist/assets/js/v-61f728ca.7b545524.js +1 -0
  41. package/docs/.vuepress/dist/assets/js/v-677dfaed.756e0fb5.js +1 -0
  42. package/docs/.vuepress/dist/assets/js/v-7c87f26e.57507077.js +1 -0
  43. package/docs/.vuepress/dist/assets/js/v-8daa1a0e.1ea39527.js +1 -0
  44. package/docs/.vuepress/dist/assets/js/v-b4a42144.a812c440.js +1 -0
  45. package/docs/.vuepress/dist/assets/js/v-e8c55052.30f30acd.js +1 -0
  46. package/docs/.vuepress/dist/assets/js/v-fffb8e28.850019c1.js +1 -0
  47. package/docs/.vuepress/dist/changelog/index.html +15 -0
  48. package/docs/.vuepress/dist/contribute/index.html +15 -0
  49. package/docs/.vuepress/dist/euro.png +0 -0
  50. package/docs/.vuepress/dist/examples/example-nordpool-current-state.html +169 -0
  51. package/docs/.vuepress/dist/examples/example-nordpool-events-state.html +173 -0
  52. package/docs/.vuepress/dist/examples/example-tibber-mqtt.html +182 -0
  53. package/docs/.vuepress/dist/examples/index.html +15 -0
  54. package/docs/.vuepress/dist/guide/index.html +52 -0
  55. package/docs/.vuepress/dist/index.html +15 -0
  56. package/docs/.vuepress/dist/logo.png +0 -0
  57. package/docs/.vuepress/dist/nodes/index.html +15 -0
  58. package/docs/.vuepress/dist/nodes/old-power-saver-doc.html +97 -0
  59. package/docs/.vuepress/dist/nodes/power-saver.html +15 -0
  60. package/docs/.vuepress/dist/nodes/ps-elvia-add-tariff.html +15 -0
  61. package/docs/.vuepress/dist/nodes/ps-receive-price.html +80 -0
  62. package/docs/.vuepress/dist/nodes/ps-strategy-best-save.html +65 -0
  63. package/docs/.vuepress/dist/nodes/ps-strategy-lowest-price.html +89 -0
  64. package/docs/.vuepress/dist/nodes/strategy-input.html +40 -0
  65. package/docs/.vuepress/public/euro.png +0 -0
  66. package/docs/.vuepress/public/logo.png +0 -0
  67. package/docs/README.md +32 -0
  68. package/docs/changelog/README.md +55 -0
  69. package/docs/contribute/README.md +39 -0
  70. package/docs/examples/README.md +5 -0
  71. package/docs/examples/example-nordpool-current-state.md +166 -0
  72. package/docs/examples/example-nordpool-events-state.md +170 -0
  73. package/docs/examples/example-tibber-mqtt.md +179 -0
  74. package/docs/guide/README.md +193 -0
  75. package/docs/images/all-nodes.png +0 -0
  76. package/docs/images/best-save-config.png +0 -0
  77. package/docs/images/elvia-add-tariff-node-used.png +0 -0
  78. package/docs/images/elvia-config-no-config.png +0 -0
  79. package/docs/images/elvia-config-no-tariff.png +0 -0
  80. package/docs/images/elvia-config-select-tariff.png +0 -0
  81. package/docs/images/elvia-config-subscription-key.png +0 -0
  82. package/docs/images/elvia-flow.png +0 -0
  83. package/docs/images/elvia-tariff-config.png +0 -0
  84. package/docs/images/euro.png +0 -0
  85. package/docs/images/example-flow-1.png +0 -0
  86. package/docs/images/example-flow-2.png +0 -0
  87. package/docs/images/logo.png +0 -0
  88. package/docs/images/lowest-price-config.png +0 -0
  89. package/docs/images/migrate-best-save.png +0 -0
  90. package/docs/images/migrate-power-saver.png +0 -0
  91. package/docs/images/node-power-saver.png +0 -0
  92. package/docs/images/node-ps-elvia-add-tariff.png +0 -0
  93. package/docs/images/node-ps-elvia-tariff-types.png +0 -0
  94. package/docs/images/node-ps-elvia-tariff.png +0 -0
  95. package/docs/images/node-ps-receive-price.png +0 -0
  96. package/docs/images/node-ps-strategy-best-save.png +0 -0
  97. package/docs/images/node-ps-strategy-lowest-price.png +0 -0
  98. package/{doc → docs/images}/node-red-contrib-power-saver-flow.png +0 -0
  99. package/docs/images/power-saver-nordpool-current-state.png +0 -0
  100. package/docs/images/power-saver-nordpool-events-state.png +0 -0
  101. package/docs/images/power-saver-tibber-mqtt.png +0 -0
  102. package/docs/nodes/README.md +53 -0
  103. package/docs/nodes/old-power-saver-doc.md +231 -0
  104. package/docs/nodes/power-saver.md +23 -0
  105. package/docs/nodes/ps-elvia-add-tariff.md +52 -0
  106. package/docs/nodes/ps-receive-price.md +153 -0
  107. package/docs/nodes/ps-strategy-best-save.md +142 -0
  108. package/docs/nodes/ps-strategy-lowest-price.md +165 -0
  109. package/docs/nodes/strategy-input.md +39 -0
  110. package/package.json +16 -4
  111. package/src/elvia/elvia-add-tariff.html +70 -0
  112. package/src/elvia/elvia-add-tariff.js +47 -0
  113. package/src/elvia/elvia-api.js +61 -0
  114. package/src/elvia/elvia-config.html +44 -0
  115. package/src/elvia/elvia-config.js +25 -0
  116. package/src/elvia/elvia-tariff-types.html +34 -0
  117. package/src/elvia/elvia-tariff-types.js +23 -0
  118. package/src/elvia/elvia-tariff.html +89 -0
  119. package/src/elvia/elvia-tariff.js +26 -0
  120. package/src/elvia/icons/elvia_hvite.svg +4 -0
  121. package/src/elvia/icons/elvia_positive_4 copy.svg +4 -0
  122. package/src/handle-input.js +159 -0
  123. package/src/power-saver.html +116 -0
  124. package/{power-saver.js → src/power-saver.js} +9 -32
  125. package/src/receive-price-functions.js +99 -0
  126. package/src/receive-price.html +30 -0
  127. package/src/receive-price.js +21 -0
  128. package/src/strategy-best-save-functions.js +110 -0
  129. package/src/strategy-best-save.html +116 -0
  130. package/src/strategy-best-save.js +95 -0
  131. package/src/strategy-lowest-price-functions.js +35 -0
  132. package/src/strategy-lowest-price.html +168 -0
  133. package/src/strategy-lowest-price.js +125 -0
  134. package/{utils.js → src/utils.js} +44 -100
  135. package/test/data/adjustedResult.js +219 -71
  136. package/test/data/adjustedResult_old.js +154 -0
  137. package/test/data/best-save-result.json +357 -0
  138. package/test/data/converted-prices.json +196 -0
  139. package/test/data/elvia-input-grid-tariff.json +760 -0
  140. package/test/data/elvia-input-power-prices.json +194 -0
  141. package/test/data/elvia-output-add-tariff.json +290 -0
  142. package/test/data/lowest-price-result-cont.json +18 -0
  143. package/test/data/lowest-price-result-split-allday.json +21 -0
  144. package/test/data/lowest-price-result-split-allday10.json +20 -0
  145. package/test/data/lowest-price-result-split.json +20 -0
  146. package/test/data/nordpool-current-state-prices.json +283 -0
  147. package/test/data/nordpool-event-prices.json +574 -0
  148. package/test/data/reconfigResult.js +220 -67
  149. package/test/data/reconfigResult_old.js +141 -0
  150. package/test/data/tibber-prices-single-home.json +64 -0
  151. package/test/data/tibber-prices.json +124 -0
  152. package/test/data/{tibber_result.json → tibber-result.json} +0 -0
  153. package/test/elvia.test.js +26 -0
  154. package/test/mostSavedStrategy.test.js +22 -55
  155. package/test/power-saver.test.js +21 -5
  156. package/test/receive-price-functions.test.js +153 -0
  157. package/test/receive-price.test.js +122 -0
  158. package/test/send-config-input.test.js +8 -10
  159. package/test/strategy-best-save-test-utils.js +32 -0
  160. package/test/strategy-best-save.test.js +103 -0
  161. package/test/strategy-lowest-price-functions.test.js +40 -0
  162. package/test/strategy-lowest-price.test.js +338 -0
  163. package/test/test-utils.js +0 -18
  164. package/test/utils.test.js +22 -180
  165. package/doc/example-nordpool-current-state.md +0 -166
  166. package/doc/example-nordpool-events-state.md +0 -153
  167. package/doc/example-tibber-mqtt.md +0 -189
  168. package/doc/power-saver-nordpool-current-state.png +0 -0
  169. package/doc/power-saver-nordpool-events-state.png +0 -0
  170. package/doc/power-saver-tibber-mqtt.png +0 -0
  171. package/mostSavedStrategy.js +0 -84
  172. package/power-saver.html +0 -308
  173. package/test/data/tibber_data.json +0 -412
  174. package/test/data/tibber_prices.json +0 -412
@@ -0,0 +1,124 @@
1
+ {
2
+ "payload": {
3
+ "viewer": {
4
+ "homes": [
5
+ {
6
+ "currentSubscription": {
7
+ "priceInfo": {
8
+ "today": [
9
+ { "total": 0.2494, "startsAt": "2021-10-11T00:00:00.000+02:00" },
10
+ { "total": 0.2209, "startsAt": "2021-10-11T01:00:00.000+02:00" },
11
+ { "total": 0.2099, "startsAt": "2021-10-11T02:00:00.000+02:00" },
12
+ { "total": 0.219, "startsAt": "2021-10-11T03:00:00.000+02:00" },
13
+ { "total": 0.2614, "startsAt": "2021-10-11T04:00:00.000+02:00" },
14
+ { "total": 0.4426, "startsAt": "2021-10-11T05:00:00.000+02:00" },
15
+ { "total": 0.5433, "startsAt": "2021-10-11T06:00:00.000+02:00" },
16
+ { "total": 0.5667, "startsAt": "2021-10-11T07:00:00.000+02:00" },
17
+ { "total": 0.5847, "startsAt": "2021-10-11T08:00:00.000+02:00" },
18
+ { "total": 0.5762, "startsAt": "2021-10-11T09:00:00.000+02:00" },
19
+ { "total": 0.5391, "startsAt": "2021-10-11T10:00:00.000+02:00" },
20
+ { "total": 0.5124, "startsAt": "2021-10-11T11:00:00.000+02:00" },
21
+ { "total": 0.504, "startsAt": "2021-10-11T12:00:00.000+02:00" },
22
+ { "total": 0.5057, "startsAt": "2021-10-11T13:00:00.000+02:00" },
23
+ { "total": 0.5066, "startsAt": "2021-10-11T14:00:00.000+02:00" },
24
+ { "total": 0.5136, "startsAt": "2021-10-11T15:00:00.000+02:00" },
25
+ { "total": 0.5143, "startsAt": "2021-10-11T16:00:00.000+02:00" },
26
+ { "total": 0.5306, "startsAt": "2021-10-11T17:00:00.000+02:00" },
27
+ { "total": 0.5534, "startsAt": "2021-10-11T18:00:00.000+02:00" },
28
+ { "total": 0.5511, "startsAt": "2021-10-11T19:00:00.000+02:00" },
29
+ { "total": 0.5491, "startsAt": "2021-10-11T20:00:00.000+02:00" },
30
+ { "total": 0.5485, "startsAt": "2021-10-11T21:00:00.000+02:00" },
31
+ { "total": 0.5481, "startsAt": "2021-10-11T22:00:00.000+02:00" },
32
+ { "total": 0.5218, "startsAt": "2021-10-11T23:00:00.000+02:00" }
33
+ ],
34
+ "tomorrow": [
35
+ { "total": 0.4533, "startsAt": "2021-10-12T00:00:00.000+02:00" },
36
+ { "total": 0.4196, "startsAt": "2021-10-12T01:00:00.000+02:00" },
37
+ { "total": 0.4037, "startsAt": "2021-10-12T02:00:00.000+02:00" },
38
+ { "total": 0.3829, "startsAt": "2021-10-12T03:00:00.000+02:00" },
39
+ { "total": 0.4555, "startsAt": "2021-10-12T04:00:00.000+02:00" },
40
+ { "total": 0.4721, "startsAt": "2021-10-12T05:00:00.000+02:00" },
41
+ { "total": 0.4903, "startsAt": "2021-10-12T06:00:00.000+02:00" },
42
+ { "total": 0.5028, "startsAt": "2021-10-12T07:00:00.000+02:00" },
43
+ { "total": 0.5163, "startsAt": "2021-10-12T08:00:00.000+02:00" },
44
+ { "total": 0.5264, "startsAt": "2021-10-12T09:00:00.000+02:00" },
45
+ { "total": 0.5346, "startsAt": "2021-10-12T10:00:00.000+02:00" },
46
+ { "total": 0.5224, "startsAt": "2021-10-12T11:00:00.000+02:00" },
47
+ { "total": 0.5071, "startsAt": "2021-10-12T12:00:00.000+02:00" },
48
+ { "total": 0.5045, "startsAt": "2021-10-12T13:00:00.000+02:00" },
49
+ { "total": 0.5024, "startsAt": "2021-10-12T14:00:00.000+02:00" },
50
+ { "total": 0.5038, "startsAt": "2021-10-12T15:00:00.000+02:00" },
51
+ { "total": 0.5118, "startsAt": "2021-10-12T16:00:00.000+02:00" },
52
+ { "total": 0.5111, "startsAt": "2021-10-12T17:00:00.000+02:00" },
53
+ { "total": 0.5108, "startsAt": "2021-10-12T18:00:00.000+02:00" },
54
+ { "total": 0.5055, "startsAt": "2021-10-12T19:00:00.000+02:00" },
55
+ { "total": 0.5042, "startsAt": "2021-10-12T20:00:00.000+02:00" },
56
+ { "total": 0.5259, "startsAt": "2021-10-12T21:00:00.000+02:00" },
57
+ { "total": 0.5282, "startsAt": "2021-10-12T22:00:00.000+02:00" },
58
+ { "total": 0.5252, "startsAt": "2021-10-12T23:00:00.000+02:00" }
59
+ ]
60
+ }
61
+ }
62
+ },
63
+ {
64
+ "currentSubscription": {
65
+ "priceInfo": {
66
+ "today": [
67
+ { "total": 0.2494, "startsAt": "2021-10-11T00:00:00.000+02:00" },
68
+ { "total": 0.2209, "startsAt": "2021-10-11T01:00:00.000+02:00" },
69
+ { "total": 0.2099, "startsAt": "2021-10-11T02:00:00.000+02:00" },
70
+ { "total": 0.219, "startsAt": "2021-10-11T03:00:00.000+02:00" },
71
+ { "total": 0.2614, "startsAt": "2021-10-11T04:00:00.000+02:00" },
72
+ { "total": 0.4426, "startsAt": "2021-10-11T05:00:00.000+02:00" },
73
+ { "total": 0.5433, "startsAt": "2021-10-11T06:00:00.000+02:00" },
74
+ { "total": 0.5667, "startsAt": "2021-10-11T07:00:00.000+02:00" },
75
+ { "total": 0.5847, "startsAt": "2021-10-11T08:00:00.000+02:00" },
76
+ { "total": 0.5762, "startsAt": "2021-10-11T09:00:00.000+02:00" },
77
+ { "total": 0.5391, "startsAt": "2021-10-11T10:00:00.000+02:00" },
78
+ { "total": 0.5124, "startsAt": "2021-10-11T11:00:00.000+02:00" },
79
+ { "total": 0.504, "startsAt": "2021-10-11T12:00:00.000+02:00" },
80
+ { "total": 0.5057, "startsAt": "2021-10-11T13:00:00.000+02:00" },
81
+ { "total": 0.5066, "startsAt": "2021-10-11T14:00:00.000+02:00" },
82
+ { "total": 0.5136, "startsAt": "2021-10-11T15:00:00.000+02:00" },
83
+ { "total": 0.5143, "startsAt": "2021-10-11T16:00:00.000+02:00" },
84
+ { "total": 0.5306, "startsAt": "2021-10-11T17:00:00.000+02:00" },
85
+ { "total": 0.5534, "startsAt": "2021-10-11T18:00:00.000+02:00" },
86
+ { "total": 0.5511, "startsAt": "2021-10-11T19:00:00.000+02:00" },
87
+ { "total": 0.5491, "startsAt": "2021-10-11T20:00:00.000+02:00" },
88
+ { "total": 0.5485, "startsAt": "2021-10-11T21:00:00.000+02:00" },
89
+ { "total": 0.5481, "startsAt": "2021-10-11T22:00:00.000+02:00" },
90
+ { "total": 0.5218, "startsAt": "2021-10-11T23:00:00.000+02:00" }
91
+ ],
92
+ "tomorrow": [
93
+ { "total": 0.4533, "startsAt": "2021-10-12T00:00:00.000+02:00" },
94
+ { "total": 0.4196, "startsAt": "2021-10-12T01:00:00.000+02:00" },
95
+ { "total": 0.4037, "startsAt": "2021-10-12T02:00:00.000+02:00" },
96
+ { "total": 0.3829, "startsAt": "2021-10-12T03:00:00.000+02:00" },
97
+ { "total": 0.4555, "startsAt": "2021-10-12T04:00:00.000+02:00" },
98
+ { "total": 0.4721, "startsAt": "2021-10-12T05:00:00.000+02:00" },
99
+ { "total": 0.4903, "startsAt": "2021-10-12T06:00:00.000+02:00" },
100
+ { "total": 0.5028, "startsAt": "2021-10-12T07:00:00.000+02:00" },
101
+ { "total": 0.5163, "startsAt": "2021-10-12T08:00:00.000+02:00" },
102
+ { "total": 0.5264, "startsAt": "2021-10-12T09:00:00.000+02:00" },
103
+ { "total": 0.5346, "startsAt": "2021-10-12T10:00:00.000+02:00" },
104
+ { "total": 0.5224, "startsAt": "2021-10-12T11:00:00.000+02:00" },
105
+ { "total": 0.5071, "startsAt": "2021-10-12T12:00:00.000+02:00" },
106
+ { "total": 0.5045, "startsAt": "2021-10-12T13:00:00.000+02:00" },
107
+ { "total": 0.5024, "startsAt": "2021-10-12T14:00:00.000+02:00" },
108
+ { "total": 0.5038, "startsAt": "2021-10-12T15:00:00.000+02:00" },
109
+ { "total": 0.5118, "startsAt": "2021-10-12T16:00:00.000+02:00" },
110
+ { "total": 0.5111, "startsAt": "2021-10-12T17:00:00.000+02:00" },
111
+ { "total": 0.5108, "startsAt": "2021-10-12T18:00:00.000+02:00" },
112
+ { "total": 0.5055, "startsAt": "2021-10-12T19:00:00.000+02:00" },
113
+ { "total": 0.5042, "startsAt": "2021-10-12T20:00:00.000+02:00" },
114
+ { "total": 0.5259, "startsAt": "2021-10-12T21:00:00.000+02:00" },
115
+ { "total": 0.5282, "startsAt": "2021-10-12T22:00:00.000+02:00" },
116
+ { "total": 0.5252, "startsAt": "2021-10-12T23:00:00.000+02:00" }
117
+ ]
118
+ }
119
+ }
120
+ }
121
+ ]
122
+ }
123
+ }
124
+ }
@@ -0,0 +1,26 @@
1
+ const helper = require("node-red-node-test-helper");
2
+ const elviaAddTariff = require("../src/elvia/elvia-add-tariff.js");
3
+ const expect = require("expect");
4
+
5
+ helper.init(require.resolve("node-red"));
6
+
7
+ describe("ps-elvia-add-tariff 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-elvia-add-tariff", name: "test name" }];
20
+ helper.load(elviaAddTariff, flow, function () {
21
+ const n1 = helper.getNode("n1");
22
+ expect(n1).toHaveProperty("name", "test name");
23
+ done();
24
+ });
25
+ });
26
+ });
@@ -1,74 +1,44 @@
1
1
  const expect = require("expect");
2
- const mostSavedStrategy = require("../mostSavedStrategy");
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(mostSavedStrategy.calculate(values, 3, 1, 0.001)).toEqual([
10
- true,
11
- true,
12
- false,
13
- false,
14
- true,
15
- false,
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(mostSavedStrategy.calculate(values, 2, 0, 0.001)).toEqual([
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
  });
@@ -1,12 +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
- const { testPlan: plan, makeFlow, makePayload } = require("./test-utils");
8
+ const { testPlan: plan, makePayload } = require("./test-utils");
10
9
 
11
10
  helper.init(require.resolve("node-red"));
12
11
 
@@ -151,8 +150,8 @@ describe("power-saver Node", function () {
151
150
  });
152
151
  });
153
152
  it("works for Tibber data", function (done) {
154
- const tibberData = require("./data/tibber_prices.json");
155
- const tibberResult = require("./data/tibber_result.json");
153
+ const tibberData = require("./data/tibber-prices.json");
154
+ const tibberResult = require("./data/tibber-result.json");
156
155
  const flow = makeFlow(4, 2);
157
156
  helper.load(powerSaver, flow, function () {
158
157
  const n1 = helper.getNode("n1");
@@ -165,3 +164,20 @@ describe("power-saver Node", function () {
165
164
  });
166
165
  });
167
166
  });
167
+
168
+ function makeFlow(maxHoursToSaveInSequence, minHoursOnAfterMaxSequenceSaved) {
169
+ return [
170
+ {
171
+ id: "n1",
172
+ type: "power-saver",
173
+ name: "test name",
174
+ maxHoursToSaveInSequence,
175
+ minHoursOnAfterMaxSequenceSaved,
176
+ minSaving: 0.001,
177
+ wires: [["n3"], ["n4"], ["n2"]],
178
+ },
179
+ { id: "n2", type: "helper" },
180
+ { id: "n3", type: "helper" },
181
+ { id: "n4", type: "helper" },
182
+ ];
183
+ }
@@ -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
+ });
@@ -1,13 +1,13 @@
1
- const cloneDeep = require("lodash.clonedeep");
2
1
  const expect = require("expect");
3
2
  const helper = require("node-red-node-test-helper");
4
- const powerSaver = require("../power-saver.js");
3
+ const bestSave = require("../src/strategy-best-save.js");
5
4
  const { DateTime } = require("luxon");
6
- const prices = require("./data/prices");
7
- const result = require("./data/result");
5
+ const prices = require("./data/converted-prices.json");
6
+ const result = require("./data/best-save-result.json");
8
7
  const reconfigResult = require("./data/reconfigResult");
9
8
  const adjustedResult = require("./data/adjustedResult");
10
- const { testPlan, makeFlow, makePayload, equalPlan } = require("./test-utils");
9
+ const { testPlan, equalPlan } = require("./test-utils");
10
+ const { makeFlow, makePayload } = require("./strategy-best-save-test-utils");
11
11
 
12
12
  helper.init(require.resolve("node-red"));
13
13
 
@@ -25,12 +25,10 @@ describe("send config as input", () => {
25
25
  it("should send new schedule on output 3", function (done) {
26
26
  const flow = makeFlow(3, 2);
27
27
  let pass = 1;
28
- helper.load(powerSaver, flow, function () {
28
+ helper.load(bestSave, flow, function () {
29
29
  const n1 = helper.getNode("n1");
30
30
  const n2 = helper.getNode("n2");
31
31
  n2.on("input", function (msg) {
32
- console.log("Pass " + pass);
33
- console.log(JSON.stringify(msg, null, 2));
34
32
  switch (pass) {
35
33
  case 1:
36
34
  pass++;
@@ -56,7 +54,7 @@ describe("send config as input", () => {
56
54
  flow[0].scheduleOnlyFromCurrentTime = false;
57
55
  const changeTime = DateTime.fromISO("2021-06-20T01:50:00.045+02:00");
58
56
  let pass = 1;
59
- helper.load(powerSaver, flow, function () {
57
+ helper.load(bestSave, flow, function () {
60
58
  const n1 = helper.getNode("n1");
61
59
  const n2 = helper.getNode("n2");
62
60
  n2.on("input", function (msg) {
@@ -92,7 +90,7 @@ describe("send config as input", () => {
92
90
  const flow = makeFlow(3, 2);
93
91
  const changeTime = DateTime.fromISO("2021-06-20T01:50:00.045+02:00");
94
92
  let pass = 1;
95
- helper.load(powerSaver, flow, function () {
93
+ helper.load(bestSave, flow, function () {
96
94
  const n1 = helper.getNode("n1");
97
95
  const n2 = helper.getNode("n2");
98
96
  n2.on("input", function (msg) {
@@ -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 };