node-red-contrib-eskomsepush 0.0.12 → 0.0.14
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/nodes/eskomsepush.js +11 -5
- package/test/three-anchor-bay.js +0 -26
package/package.json
CHANGED
package/src/nodes/eskomsepush.js
CHANGED
|
@@ -163,14 +163,16 @@ module.exports = function (RED) {
|
|
|
163
163
|
|
|
164
164
|
// Are there any events going on?
|
|
165
165
|
if (Object.entries(EskomSePushInfo.area.info.events).length > 0) {
|
|
166
|
-
EskomSePushInfo.calc.type = 'event'
|
|
167
166
|
const EventStart = Date.parse(EskomSePushInfo.area.info.events[0].start)
|
|
168
167
|
const EventEnd = Date.parse(EskomSePushInfo.area.info.events[0].end)
|
|
169
168
|
if (now >= EventStart && now < EventEnd) {
|
|
169
|
+
EskomSePushInfo.calc.type = 'event'
|
|
170
170
|
EskomSePushInfo.calc.active = true
|
|
171
171
|
if (EskomSePushInfo.area.info.events[0].note.match(/Stage (\d+)/i)) {
|
|
172
172
|
EskomSePushInfo.calc.stage = EskomSePushInfo.area.info.events[0].note.match(/Stage (\d+)/i)[1]
|
|
173
173
|
}
|
|
174
|
+
EskomSePushInfo.calc.start = EventStart
|
|
175
|
+
EskomSePushInfo.calc.end = EventEnd
|
|
174
176
|
} else {
|
|
175
177
|
EskomSePushInfo.calc.next = {
|
|
176
178
|
type: 'event',
|
|
@@ -185,7 +187,7 @@ module.exports = function (RED) {
|
|
|
185
187
|
// So not just like events, where they are in UTC with an offset
|
|
186
188
|
let BreakLoop = false
|
|
187
189
|
for (const dates of EskomSePushInfo.area.info.schedule.days) {
|
|
188
|
-
for (const schedule of dates.stages[EskomSePushInfo.calc.stage]) {
|
|
190
|
+
for (const schedule of dates.stages[EskomSePushInfo.calc.stage-1]) {
|
|
189
191
|
const ScheduleStart = Date.parse(dates.date + ' ' + schedule.split('-')[0])
|
|
190
192
|
let ScheduleEnd = Date.parse(dates.date + ' ' + schedule.split('-')[1])
|
|
191
193
|
if (ScheduleEnd < ScheduleStart) {
|
|
@@ -203,7 +205,8 @@ module.exports = function (RED) {
|
|
|
203
205
|
EskomSePushInfo.calc.next = {
|
|
204
206
|
type: 'schedule',
|
|
205
207
|
start: ScheduleStart,
|
|
206
|
-
end: ScheduleEnd
|
|
208
|
+
end: ScheduleEnd,
|
|
209
|
+
stage: EskomSePushInfo.calc.stage
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
}
|
|
@@ -216,6 +219,7 @@ module.exports = function (RED) {
|
|
|
216
219
|
EskomSePushInfo.calc.next.duration = (EskomSePushInfo.calc.next.end - EskomSePushInfo.calc.next.start) / 1000
|
|
217
220
|
EskomSePushInfo.calc.next.islong = EskomSePushInfo.calc.next.duration >= (4 * 3600)
|
|
218
221
|
EskomSePushInfo.calc.secondstostatechange = parseInt((EskomSePushInfo.calc.next.start - now) / 1000)
|
|
222
|
+
EskomSePushInfo.calc.next.isHigherStage = EskomSePushInfo.calc.next.stage > EskomSePushInfo.calc.next.stage
|
|
219
223
|
}
|
|
220
224
|
|
|
221
225
|
if (EskomSePushInfo.calc.active) {
|
|
@@ -253,8 +257,10 @@ module.exports = function (RED) {
|
|
|
253
257
|
if (EskomSePushInfo.calc.type === 'event') {
|
|
254
258
|
shape = 'dot'
|
|
255
259
|
}
|
|
256
|
-
|
|
257
|
-
|
|
260
|
+
if ( EskomSePushInfo.calc.start ) {
|
|
261
|
+
statusText += new Date(EskomSePushInfo.calc.start).toLocaleTimeString([], {timeStyle: 'short'})
|
|
262
|
+
statusText += ' - ' + new Date(EskomSePushInfo.calc.end).toLocaleTimeString([], {timeStyle: 'short'})
|
|
263
|
+
}
|
|
258
264
|
} else {
|
|
259
265
|
if (new Date(EskomSePushInfo.calc.next.start).getUTCDay() !== now.getUTCDate) {
|
|
260
266
|
statusText += new Date(EskomSePushInfo.calc.next.start).toLocaleString([], {weekday: 'short'}) + ' '
|
package/test/three-anchor-bay.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const EskomSePushInfo = { stage: { lastUpdate: '2023-06-16T07:18:37.847Z', info: { status: { capetown: { name: 'Cape Town', next_stages: [{ stage: '1', stage_start_timestamp: '2023-06-16T16:00:00+02:00' }, { stage: '0', stage_start_timestamp: '2023-06-17T00:00:00+02:00' }, { stage: '1', stage_start_timestamp: '2023-06-17T16:00:00+02:00' }, { stage: '0', stage_start_timestamp: '2023-06-18T00:00:00+02:00' }, { stage: '1', stage_start_timestamp: '2023-06-18T16:00:00+02:00' }], stage: '0', stage_updated: '2023-06-16T00:00:00.742510+02:00' }, eskom: { name: 'Eskom', next_stages: [{ stage: '3', stage_start_timestamp: '2023-06-16T16:00:00+02:00' }, { stage: '0', stage_start_timestamp: '2023-06-17T00:00:00+02:00' }, { stage: '3', stage_start_timestamp: '2023-06-17T16:00:00+02:00' }, { stage: '0', stage_start_timestamp: '2023-06-18T00:00:00+02:00' }, { stage: '3', stage_start_timestamp: '2023-06-18T16:00:00+02:00' }], stage: '0', stage_updated: '2023-06-16T00:00:00.742510+02:00' } } } }, schedule: { lastUpdate: '2023-06-16T07:18:38.957Z', info: { events: [{ end: '2023-06-17T00:30:00+02:00', note: 'Stage 1', start: '2023-06-16T22:00:00+02:00' }], info: { name: 'Helderberg Village (3)', region: 'City of Cape Town' }, schedule: { days: [{ date: '2023-06-16', name: 'Friday', stages: [['22:00-00:30'], ['06:00-08:30', '22:00-00:30'], ['06:00-08:30', '22:00-00:30'], ['06:00-08:30', '14:00-16:30', '22:00-00:30'], ['06:00-08:30', '14:00-16:30', '22:00-00:30'], ['06:00-08:30', '12:00-16:30', '22:00-00:30'], ['04:00-08:30', '12:00-16:30', '22:00-00:30'], ['04:00-08:30', '12:00-16:30', '20:00-00:30']] }, { date: '2023-06-17', name: 'Saturday', stages: [['04:00-06:30'], ['04:00-06:30', '20:00-22:30'], ['04:00-06:30', '12:00-14:30', '20:00-22:30'], ['04:00-06:30', '12:00-14:30', '20:00-22:30'], ['02:00-06:30', '12:00-14:30', '20:00-22:30'], ['02:00-06:30', '12:00-14:30', '18:00-22:30'], ['02:00-06:30', '10:00-14:30', '18:00-22:30'], ['02:00-06:30', '10:00-14:30', '18:00-22:30']] }, { date: '2023-06-18', name: 'Sunday', stages: [['12:00-14:30'], ['12:00-14:30'], ['12:00-14:30', '20:00-22:30'], ['04:00-06:30', '12:00-14:30', '20:00-22:30'], ['04:00-06:30', '10:00-14:30', '20:00-22:30'], ['04:00-06:30', '10:00-14:30', '20:00-22:30'], ['04:00-06:30', '10:00-14:30', '18:00-22:30'], ['02:00-06:30', '10:00-14:30', '18:00-22:30']] }, { date: '2023-06-19', name: 'Monday', stages: [['20:00-22:30'], ['04:00-06:30', '20:00-22:30'], ['04:00-06:30', '20:00-22:30'], ['04:00-06:30', '12:00-14:30', '20:00-22:30'], ['04:00-06:30', '12:00-14:30', '18:00-22:30'], ['02:00-06:30', '12:00-14:30', '18:00-22:30'], ['02:00-06:30', '12:00-14:30', '18:00-22:30'], ['02:00-06:30', '10:00-14:30', '18:00-22:30']] }, { date: '2023-06-20', name: 'Tuesday', stages: [[], ['12:00-14:30'], ['04:00-06:30', '12:00-14:30'], ['04:00-06:30', '12:00-14:30', '20:00-22:30'], ['04:00-06:30', '12:00-14:30', '20:00-22:30'], ['04:00-06:30', '10:00-14:30', '20:00-22:30'], ['02:00-06:30', '10:00-14:30', '20:00-22:30'], ['02:00-06:30', '10:00-14:30', '18:00-22:30']] }, { date: '2023-06-21', name: 'Wednesday', stages: [['02:00-04:30'], ['02:00-04:30', '18:00-20:30'], ['02:00-04:30', '10:00-12:30', '18:00-20:30'], ['02:00-04:30', '10:00-12:30', '18:00-20:30'], ['00:00-04:30', '10:00-12:30', '18:00-20:30'], ['00:00-04:30', '10:00-12:30', '16:00-20:30'], ['00:00-04:30', '08:00-12:30', '16:00-20:30'], ['00:00-04:30', '08:00-12:30', '16:00-20:30']] }, { date: '2023-06-22', name: 'Thursday', stages: [['10:00-12:30'], ['10:00-12:30'], ['10:00-12:30', '18:00-20:30'], ['02:00-04:30', '10:00-12:30', '18:00-20:30'], ['02:00-04:30', '08:00-12:30', '18:00-20:30'], ['02:00-04:30', '08:00-12:30', '18:00-20:30'], ['02:00-04:30', '08:00-12:30', '16:00-20:30'], ['00:00-04:30', '08:00-12:30', '16:00-20:30']] }], source: 'https://www.capetown.gov.za/loadshedding/' } } }, _msgid: 'e5eceed861704158' }
|
|
2
|
-
|
|
3
|
-
const now = new Date()
|
|
4
|
-
let BreakLoop = false
|
|
5
|
-
for (const dates of EskomSePushInfo.schedule.info.schedule.days) {
|
|
6
|
-
for (const schedule of dates.stages['0']) {
|
|
7
|
-
const ScheduleStart = Date.parse(dates.date + ' ' + schedule.split('-')[0])
|
|
8
|
-
let ScheduleEnd = Date.parse(dates.date + ' ' + schedule.split('-')[1])
|
|
9
|
-
if (ScheduleEnd < ScheduleStart) {
|
|
10
|
-
ScheduleEnd += (24 * 60 * 60 * 1000)
|
|
11
|
-
}
|
|
12
|
-
console.log('check: ' + new Date(ScheduleEnd))
|
|
13
|
-
if (now < new Date(ScheduleEnd)) {
|
|
14
|
-
BreakLoop = true
|
|
15
|
-
// This schedule is either active or will be next
|
|
16
|
-
if (now >= ScheduleStart) {
|
|
17
|
-
console.log('match')
|
|
18
|
-
} else {
|
|
19
|
-
console.log('next found')
|
|
20
|
-
console.log(new Date(ScheduleStart).toLocaleString())
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (BreakLoop) { break }
|
|
24
|
-
}
|
|
25
|
-
if (BreakLoop) { break }
|
|
26
|
-
}
|