node-red-contrib-eskomsepush 0.0.12 → 0.0.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-eskomsepush",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Node-RED interface for the Eskomsepush API",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -171,6 +171,8 @@ module.exports = function (RED) {
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) {
@@ -253,8 +255,10 @@ module.exports = function (RED) {
253
255
  if (EskomSePushInfo.calc.type === 'event') {
254
256
  shape = 'dot'
255
257
  }
256
- statusText += new Date(EskomSePushInfo.calc.start).toLocaleTimeString([], {timeStyle: 'short'})
257
- statusText += ' - ' + new Date(EskomSePushInfo.calc.end).toLocaleTimeString([], {timeStyle: 'short'})
258
+ if ( EskomSePushInfo.calc.start ) {
259
+ statusText += new Date(EskomSePushInfo.calc.start).toLocaleTimeString([], {timeStyle: 'short'})
260
+ statusText += ' - ' + new Date(EskomSePushInfo.calc.end).toLocaleTimeString([], {timeStyle: 'short'})
261
+ }
258
262
  } else {
259
263
  if (new Date(EskomSePushInfo.calc.next.start).getUTCDay() !== now.getUTCDate) {
260
264
  statusText += new Date(EskomSePushInfo.calc.next.start).toLocaleString([], {weekday: 'short'}) + ' '
@@ -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
- }