node-red-contrib-power-saver 1.0.3 → 1.0.7
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/LICENSE +1 -0
- package/package.json +5 -1
- package/power-saver.js +5 -14
- package/test/mostSavedStrategy.test.js +11 -7
- package/test/power-saver.test.js +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-power-saver",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A module for Node-RED that you can use to turn on and off a switch based on power prices",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"power-saver": "power-saver.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/ottopaulsen/node-red-contrib-power-saver.git"
|
|
22
|
+
},
|
|
19
23
|
"devDependencies": {
|
|
20
24
|
"expect": "^27.0.2",
|
|
21
25
|
"lodash.clonedeep": "^4.5.0",
|
package/power-saver.js
CHANGED
|
@@ -4,17 +4,6 @@ const mostSavedStrategy = require("./mostSavedStrategy");
|
|
|
4
4
|
|
|
5
5
|
let schedulingTimeout = null;
|
|
6
6
|
|
|
7
|
-
// TODO
|
|
8
|
-
|
|
9
|
-
// Round savings
|
|
10
|
-
// Add min saving
|
|
11
|
-
// Put all output in one array with price, start, saving and onOff.
|
|
12
|
-
|
|
13
|
-
// Accept input directly from tibber, nordpool and payload with converted values.
|
|
14
|
-
// Make tests for all these.
|
|
15
|
-
// Update doc with Tibber.
|
|
16
|
-
// Make examples.
|
|
17
|
-
|
|
18
7
|
module.exports = function (RED) {
|
|
19
8
|
function PowerSaverNode(config) {
|
|
20
9
|
RED.nodes.createNode(this, config);
|
|
@@ -46,6 +35,7 @@ module.exports = function (RED) {
|
|
|
46
35
|
|
|
47
36
|
const today = input.today;
|
|
48
37
|
const tomorrow = input.tomorrow;
|
|
38
|
+
const source = input.source;
|
|
49
39
|
|
|
50
40
|
clearTimeout(schedulingTimeout);
|
|
51
41
|
|
|
@@ -63,13 +53,13 @@ module.exports = function (RED) {
|
|
|
63
53
|
const startTimesToday = today.map((d) => d.start);
|
|
64
54
|
const startTimesTomorrow = tomorrow.map((d) => d.start);
|
|
65
55
|
|
|
66
|
-
planToday = makePlan(
|
|
56
|
+
const planToday = makePlan(
|
|
67
57
|
node,
|
|
68
58
|
valuesToday,
|
|
69
59
|
startTimesToday,
|
|
70
60
|
dataYesterday.onOff
|
|
71
61
|
);
|
|
72
|
-
planTomorrow = makePlan(
|
|
62
|
+
const planTomorrow = makePlan(
|
|
73
63
|
node,
|
|
74
64
|
valuesTomorrow,
|
|
75
65
|
startTimesTomorrow,
|
|
@@ -91,6 +81,7 @@ module.exports = function (RED) {
|
|
|
91
81
|
payload: {
|
|
92
82
|
schedule,
|
|
93
83
|
hours,
|
|
84
|
+
source,
|
|
94
85
|
},
|
|
95
86
|
};
|
|
96
87
|
|
|
@@ -193,7 +184,7 @@ function validateMsg(node, msg) {
|
|
|
193
184
|
validationFailure(node, "Payload missing");
|
|
194
185
|
return false;
|
|
195
186
|
}
|
|
196
|
-
const payload = msg.
|
|
187
|
+
const payload = msg.data?.new_state?.attributes ?? msg.payload;
|
|
197
188
|
if (typeof payload !== "object") {
|
|
198
189
|
validationFailure(node, "Payload must be an object");
|
|
199
190
|
return false;
|
|
@@ -6,7 +6,7 @@ const prices = require("./data/prices");
|
|
|
6
6
|
describe("mostSavedStrategy", () => {
|
|
7
7
|
it("saves correct hours", () => {
|
|
8
8
|
const values = prices.today.map((p) => p.value);
|
|
9
|
-
expect(mostSavedStrategy.calculate(values, 6, 3, 1)).toEqual([
|
|
9
|
+
expect(mostSavedStrategy.calculate(values, 6, 3, 1, 0.001)).toEqual([
|
|
10
10
|
true,
|
|
11
11
|
true,
|
|
12
12
|
false,
|
|
@@ -18,7 +18,7 @@ describe("mostSavedStrategy", () => {
|
|
|
18
18
|
true,
|
|
19
19
|
true,
|
|
20
20
|
]);
|
|
21
|
-
expect(mostSavedStrategy.calculate(values, 4, 3, 1)).toEqual([
|
|
21
|
+
expect(mostSavedStrategy.calculate(values, 4, 3, 1, 0.001)).toEqual([
|
|
22
22
|
true,
|
|
23
23
|
true,
|
|
24
24
|
true,
|
|
@@ -30,7 +30,7 @@ describe("mostSavedStrategy", () => {
|
|
|
30
30
|
true,
|
|
31
31
|
true,
|
|
32
32
|
]);
|
|
33
|
-
expect(mostSavedStrategy.calculate(values, 5, 2, 1)).toEqual([
|
|
33
|
+
expect(mostSavedStrategy.calculate(values, 5, 2, 1, 0.001)).toEqual([
|
|
34
34
|
true,
|
|
35
35
|
true,
|
|
36
36
|
false,
|
|
@@ -42,7 +42,7 @@ describe("mostSavedStrategy", () => {
|
|
|
42
42
|
true,
|
|
43
43
|
true,
|
|
44
44
|
]);
|
|
45
|
-
expect(mostSavedStrategy.calculate(values, 5, 2, 3)).toEqual([
|
|
45
|
+
expect(mostSavedStrategy.calculate(values, 5, 2, 3, 0.001)).toEqual([
|
|
46
46
|
true,
|
|
47
47
|
true,
|
|
48
48
|
true,
|
|
@@ -54,7 +54,7 @@ describe("mostSavedStrategy", () => {
|
|
|
54
54
|
true,
|
|
55
55
|
true,
|
|
56
56
|
]);
|
|
57
|
-
expect(mostSavedStrategy.calculate(values, 5, 2, 0)).toEqual([
|
|
57
|
+
expect(mostSavedStrategy.calculate(values, 5, 2, 0, 0.001)).toEqual([
|
|
58
58
|
true,
|
|
59
59
|
true,
|
|
60
60
|
false,
|
|
@@ -67,7 +67,9 @@ describe("mostSavedStrategy", () => {
|
|
|
67
67
|
true,
|
|
68
68
|
]);
|
|
69
69
|
const values2 = prices.tomorrow.map((p) => p.value);
|
|
70
|
-
expect(
|
|
70
|
+
expect(
|
|
71
|
+
mostSavedStrategy.calculate(values2, 5, 2, 1, 0.001, true, 1)
|
|
72
|
+
).toEqual([
|
|
71
73
|
false,
|
|
72
74
|
false,
|
|
73
75
|
true,
|
|
@@ -79,7 +81,9 @@ describe("mostSavedStrategy", () => {
|
|
|
79
81
|
true,
|
|
80
82
|
true,
|
|
81
83
|
]);
|
|
82
|
-
expect(
|
|
84
|
+
expect(
|
|
85
|
+
mostSavedStrategy.calculate(values2, 5, 2, 1, 0.001, false, 1)
|
|
86
|
+
).toEqual([
|
|
83
87
|
true,
|
|
84
88
|
false,
|
|
85
89
|
true,
|
package/test/power-saver.test.js
CHANGED
|
@@ -72,6 +72,7 @@ describe("power-saver Node", function () {
|
|
|
72
72
|
id: "n1",
|
|
73
73
|
type: "power-saver",
|
|
74
74
|
name: "test name",
|
|
75
|
+
minSaving: 0.001,
|
|
75
76
|
wires: [["n3"], ["n4"], ["n2"]],
|
|
76
77
|
},
|
|
77
78
|
{ id: "n2", type: "helper" },
|
|
@@ -84,6 +85,8 @@ describe("power-saver Node", function () {
|
|
|
84
85
|
const n3 = helper.getNode("n3");
|
|
85
86
|
const n4 = helper.getNode("n4");
|
|
86
87
|
n2.on("input", function (msg) {
|
|
88
|
+
console.log(JSON.stringify(msg, null, 2));
|
|
89
|
+
console.log(JSON.stringify(plan.schedule, null, 2));
|
|
87
90
|
expect(msg.payload).toHaveProperty("schedule", plan.schedule);
|
|
88
91
|
n1.warn.should.not.be.called;
|
|
89
92
|
// done();
|