node-red-contrib-eskomsepush 0.0.9 → 0.0.10

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.9",
3
+ "version": "0.0.10",
4
4
  "description": "Node-RED interface for the Eskomsepush API",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -36,7 +36,8 @@
36
36
  licensekey: {value:"", validate: RED.validators.regex(/^[0-9A-F\-]{35}$/)},
37
37
  area: {value:""},
38
38
  statusselect: {value:"", validate: RED.validators.regex(/^(eskom|capetown)$/)},
39
- test: { value: false }
39
+ test: { value: false },
40
+ verbose: {value: false}
40
41
  },
41
42
  inputs:0,
42
43
  outputs:2,
@@ -130,6 +131,10 @@
130
131
  <button id="searchAreaId">Search</button><br />
131
132
  </p>
132
133
  </div>
134
+ <div class="form-row" style="margin-bottom:0px;">
135
+ <input type="checkbox" checked id="node-input-verbose" style="display:inline-block; margin-left:8px; width:auto; vertical-align:top;">
136
+ <label style="min-width:390px" for="node-input-verbose"><i class="fa fa-power"></i> Verbose: add extra logging when running</label>
137
+ </div>
133
138
  </script>
134
139
 
135
140
  <script type="text/html" data-help-name="eskomsepush">
@@ -216,11 +221,24 @@ This output is mainly useful when debugging or writing your own functions and lo
216
221
  how many are left. This updates every 10 minutes.</p>
217
222
 
218
223
  <p>
219
- The red color status can be either filled (dot) or not (ring). In case of a dot,
224
+ The yellow color status can be either filled (dot) or not (ring). In case of a dot,
220
225
  the load schedding is because of an <em>event</em>. When it is a ring, it is caused by
221
226
  a matching <em>schedule</em>.
222
227
  </p>
223
228
 
229
+ <div id="legend">
230
+ <ul>
231
+ <li><svg class="bullet" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><rect x="5" y="5" width="9" height="9" rx="2" ry="2" stroke-width="3" fill="#fff" stroke="#5a8"></rect>
232
+ </svg> - grid available, working properly</li>
233
+ <li><svg class="bullet" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><rect x="5" y="5" width="9" height="9" rx="2" ry="2" stroke-width="3" fill="#F9DF31" stroke="#F9DF31"></rect>
234
+ </svg> - no grid, load shedding because of an <strong>event</strong></li>
235
+ <li><svg class="bullet" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><rect x="5" y="5" width="9" height="9" rx="2" ry="2" stroke-width="3" fill="#fff" stroke="#F9DF31"></rect>
236
+ </svg> - no grid, load shedding because of a <strong>schedule</strong></li>
237
+ <li><svg class="bullet" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><rect x="5" y="5" width="9" height="9" rx="2" ry="2" stroke-width="3" fill="#fff" stroke="#c00"></rect>
238
+ </svg> - ran out of API calls</li>
239
+ </ul>
240
+ </div>
241
+
224
242
  <h1 id="documentation">Documentation</h1>
225
243
 
226
244
  <p>The GitHub site for the node can be found <a href="https://github.com/dirkjanfaber/node-red-contrib-eskomsepush">here</a>, while the documentation for the API can be found <a href="https://documenter.getpostman.com/view/1296288/UzQuNk3E">here</a>.
@@ -238,4 +256,21 @@ select#areaDropdown {
238
256
  #list-areas li {
239
257
  cursor: pointer;
240
258
  }
259
+
260
+ #legend ul {
261
+ list-style: none;
262
+ padding: 0;
263
+ }
264
+ #legend li {
265
+ margin-bottom: 10px;
266
+ position: relative;
267
+ padding-left: 25px;
268
+ }
269
+ .bullet {
270
+ position: absolute;
271
+ top: 2px;
272
+ left: 0;
273
+ width: 35px;
274
+ height: 35px;
275
+ }
241
276
  </style>
@@ -14,12 +14,16 @@ module.exports = function (RED) {
14
14
  let fill = 'green'
15
15
  let shape = 'ring'
16
16
  let statusText = ''
17
+
18
+ if (node.config.verbose === true) {
19
+ node.warn('Running function updateStatus')
20
+ }
17
21
  if (Stage && Stage.status && Stage.status[node.config.statusselect].stage) {
18
- statusText += 'Stage ' + Stage.status[node.config.statusselect].stage
22
+ statusText += 'Stage ' + (Stage.active || Stage.status[node.config.statusselect].stage)
19
23
  }
20
24
  if (LoadShedding && LoadShedding.active && LoadShedding.next && LoadShedding.next.end) {
21
25
  statusText += ' - ' + new Date(LoadShedding.next.end).toLocaleTimeString()
22
- fill = 'red'
26
+ fill = 'yellow'
23
27
  if (LoadShedding.type === 'event') {
24
28
  shape = 'dot'
25
29
  }
@@ -42,6 +46,10 @@ module.exports = function (RED) {
42
46
  function checkAllowance (node) {
43
47
  const options = {}
44
48
  const headers = { token: node.config.licensekey }
49
+
50
+ if (node.config.verbose === true) {
51
+ node.warn('Running function checkAllowance')
52
+ }
45
53
  axios.get('https://developer.sepush.co.za/business/2.0/api_allowance',
46
54
  { params: options, headers }).then(function (response) {
47
55
  EskomSePushAPI = response.data
@@ -55,6 +63,10 @@ module.exports = function (RED) {
55
63
  function checkStage (node) {
56
64
  const options = {}
57
65
  const headers = { token: node.config.licensekey }
66
+
67
+ if (node.config.verbose === true) {
68
+ node.warn('Running function checkStage')
69
+ }
58
70
  axios.get('https://developer.sepush.co.za/business/2.0/status',
59
71
  { params: options, headers }).then(function (response) {
60
72
  Stage = response.data
@@ -69,6 +81,10 @@ module.exports = function (RED) {
69
81
  const options = { id: node.config.area }
70
82
  const headers = { token: node.config.licensekey }
71
83
  const url = 'https://developer.sepush.co.za/business/2.0/area'
84
+
85
+ if (node.config.verbose === true) {
86
+ node.warn('Running function checkSchedule')
87
+ }
72
88
  if (node.config.test) {
73
89
  options.test = 'current'
74
90
  }
@@ -86,6 +102,9 @@ module.exports = function (RED) {
86
102
  function updateSheddingStatus (node) {
87
103
  const now = new Date()
88
104
 
105
+ if (node.config.verbose === true) {
106
+ node.warn('Running function updateSheddingStatus')
107
+ }
89
108
  if (EskomSePushAPI === null || (now.getTime() - lastStatusUpdate.getTime()) > 600000) {
90
109
  checkAllowance(node)
91
110
  lastStatusUpdate = now
@@ -111,7 +130,7 @@ module.exports = function (RED) {
111
130
  }
112
131
 
113
132
  if (Stage && Schedule && EskomSePushAPI) {
114
- const stage = Stage.status[node.config.statusselect].stage
133
+ let stage = Stage.status[node.config.statusselect].stage
115
134
  const nowtime = now.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit' })
116
135
  LoadShedding = {
117
136
  schedule: {
@@ -124,7 +143,13 @@ module.exports = function (RED) {
124
143
  },
125
144
  checked: nowtime
126
145
  }
127
- for (const schedule of Schedule.schedule.days[0].stages[stage - 1]) {
146
+
147
+ if (!Array.isArray(Schedule.schedule.days[0].stages[stage])) {
148
+ node.warn(`No schedule defined for stage ${stage}`)
149
+ return
150
+ }
151
+
152
+ for (const schedule of Schedule.schedule.days[0].stages[stage]) {
128
153
  if (nowtime >= schedule.split('-')[0] && nowtime <= schedule.split('-')[1]) {
129
154
  LoadShedding.schedule = {
130
155
  active: true
@@ -168,6 +193,12 @@ module.exports = function (RED) {
168
193
  }
169
194
  if (now >= LoadShedding.event.next.start && now < LoadShedding.event.next.end) {
170
195
  LoadShedding.event.active = true
196
+ if (Schedule.events[0].note.match(/Stage (\d+)/i)) {
197
+ stage = Schedule.events[0].note.match(/Stage (\d+)/i)[1]
198
+ Stage.active = stage
199
+ }
200
+ } else {
201
+ Stage.active = stage
171
202
  }
172
203
 
173
204
  if (!LoadShedding.schedule | !LoadShedding.schedule.next ||