node-red-contrib-power-saver 5.1.0 → 5.1.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/package.json +1 -1
- package/src/handle-input.js +15 -1
- package/src/handle-output.js +10 -10
- package/src/light-saver-functions.js +246 -196
- package/src/light-saver.js +255 -219
- package/src/receive-price-functions.js +1 -1
- package/src/schedule-merger-functions.js +3 -3
- package/src/utils.js +1 -1
package/package.json
CHANGED
package/src/handle-input.js
CHANGED
|
@@ -82,7 +82,8 @@ function makePlanFromPriceData(node, msg, config, doPlanning, calcSavings) {
|
|
|
82
82
|
onOff: onOff[i],
|
|
83
83
|
saving: savings[i],
|
|
84
84
|
}));
|
|
85
|
-
const
|
|
85
|
+
const fullSchedule = makeSchedule(onOff, startTimes, endTime);
|
|
86
|
+
const schedule = trimScheduleToStart(fullSchedule, priceData[0].start);
|
|
86
87
|
addLastSwitchIfNoSchedule(schedule, minutes, config);
|
|
87
88
|
|
|
88
89
|
plan = {
|
|
@@ -158,6 +159,19 @@ function loadDataJustBefore(node, dateDayBefore) {
|
|
|
158
159
|
};
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
function trimScheduleToStart(schedule, startTime) {
|
|
163
|
+
const startDT = DateTime.fromISO(startTime);
|
|
164
|
+
const idx = schedule.findIndex((e) => DateTime.fromISO(e.time) >= startDT);
|
|
165
|
+
if (idx === -1) return schedule;
|
|
166
|
+
const trimmed = schedule.slice(idx);
|
|
167
|
+
if (DateTime.fromISO(trimmed[0].time) > startDT) {
|
|
168
|
+
const initialState = (idx > 0 ? schedule[idx - 1] : schedule[0]).value;
|
|
169
|
+
const countMinutes = DateTime.fromISO(trimmed[0].time).diff(startDT, "minutes").minutes;
|
|
170
|
+
trimmed.unshift({ time: startDT.toISO(), value: initialState, countMinutes });
|
|
171
|
+
}
|
|
172
|
+
return trimmed;
|
|
173
|
+
}
|
|
174
|
+
|
|
161
175
|
function deleteSavedScheduleBefore(node, day, checkDays = 0) {
|
|
162
176
|
let date = day;
|
|
163
177
|
let data = null;
|
package/src/handle-output.js
CHANGED
|
@@ -123,30 +123,30 @@ function collapseMinutes(minutes) {
|
|
|
123
123
|
|
|
124
124
|
const result = [];
|
|
125
125
|
let currentValue = minutes[0];
|
|
126
|
-
let count = 1;
|
|
127
126
|
let startIndex = 0;
|
|
128
127
|
|
|
129
128
|
for (let i = 1; i < minutes.length; i++) {
|
|
130
|
-
if (itemsEqual(minutes[i], currentValue)) {
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
if (!itemsEqual(minutes[i], currentValue)) {
|
|
130
|
+
const groupStartMs = new Date(currentValue.start).getTime();
|
|
131
|
+
const nextStartMs = new Date(minutes[i].start).getTime();
|
|
132
|
+
const count = Math.round((nextStartMs - groupStartMs) / 60000);
|
|
133
133
|
result.push({ ...currentValue, count, startIndex });
|
|
134
134
|
currentValue = minutes[i];
|
|
135
|
-
count = 1;
|
|
136
135
|
startIndex = i;
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
const lastRecord = minutes[minutes.length - 1];
|
|
140
|
+
const lastCount = lastRecord.end
|
|
141
|
+
? Math.round((new Date(lastRecord.end).getTime() - new Date(currentValue.start).getTime()) / 60000)
|
|
142
|
+
: null;
|
|
143
|
+
result.push({ ...currentValue, count: lastCount, startIndex });
|
|
142
144
|
return result;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
145
|
}
|
|
147
146
|
|
|
148
147
|
module.exports = {
|
|
149
148
|
handleOutput,
|
|
150
149
|
shallSendOutput,
|
|
151
150
|
strategyShallSendSchedule,
|
|
151
|
+
collapseMinutes,
|
|
152
152
|
};
|