Skip to content

Commit c695945

Browse files
committed
Supported new RTU Status Endpoints
1 parent 342846f commit c695945

File tree

3 files changed

+274
-3
lines changed

3 files changed

+274
-3
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ricado/api-client",
3-
"version": "2.5.14",
3+
"version": "2.5.15",
44
"description": "RICADO Gen 4 API Client Library for NodeJS and Browsers",
55
"author": {
66
"name": "Ash Neilson"

src/Controllers/RTUController.js

+271
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,126 @@ class RTUController
8080
});
8181
}
8282

83+
/**
84+
* Retrieve the Status of an RTU [GET /rtus/{id}/status]
85+
*
86+
* @static
87+
* @public
88+
* @param {number} id The RTU ID
89+
* @return {Promise<RTUController.RTUStatusItem>}
90+
*/
91+
static getOneStatus(id)
92+
{
93+
return new Promise((resolve, reject) => {
94+
RequestHelper.getRequest(`/rtus/${id}/status`)
95+
.then((result) => {
96+
let resolveValue = (function(){
97+
let resultObject = {};
98+
99+
if(typeof result === 'object' && 'id' in result)
100+
{
101+
resultObject.id = (function(){
102+
if(typeof result.id !== 'number')
103+
{
104+
return Number.isInteger(Number(result.id)) ? Number(result.id) : Math.floor(Number(result.id));
105+
}
106+
107+
return Number.isInteger(result.id) ? result.id : Math.floor(result.id);
108+
}());
109+
}
110+
else
111+
{
112+
resultObject.id = 0;
113+
}
114+
115+
if(typeof result === 'object' && 'latency' in result)
116+
{
117+
resultObject.latency = (function(){
118+
if(result.latency === null)
119+
{
120+
return null;
121+
}
122+
123+
if(typeof result.latency !== 'number')
124+
{
125+
return Number(result.latency);
126+
}
127+
128+
return result.latency;
129+
}());
130+
}
131+
else
132+
{
133+
resultObject.latency = null;
134+
}
135+
136+
if(typeof result === 'object' && 'latencyTimestamp' in result)
137+
{
138+
resultObject.latencyTimestamp = (function(){
139+
if(result.latencyTimestamp === null)
140+
{
141+
return null;
142+
}
143+
144+
if(typeof result.latencyTimestamp !== 'string')
145+
{
146+
return new Date(String(result.latencyTimestamp));
147+
}
148+
149+
return new Date(result.latencyTimestamp);
150+
}());
151+
}
152+
else
153+
{
154+
resultObject.latencyTimestamp = null;
155+
}
156+
157+
if(typeof result === 'object' && 'lastSeenTimestamp' in result)
158+
{
159+
resultObject.lastSeenTimestamp = (function(){
160+
if(result.lastSeenTimestamp === null)
161+
{
162+
return null;
163+
}
164+
165+
if(typeof result.lastSeenTimestamp !== 'string')
166+
{
167+
return new Date(String(result.lastSeenTimestamp));
168+
}
169+
170+
return new Date(result.lastSeenTimestamp);
171+
}());
172+
}
173+
else
174+
{
175+
resultObject.lastSeenTimestamp = null;
176+
}
177+
178+
if(typeof result === 'object' && 'onlineStatus' in result)
179+
{
180+
resultObject.onlineStatus = (function(){
181+
if(typeof result.onlineStatus !== 'boolean')
182+
{
183+
return Boolean(result.onlineStatus);
184+
}
185+
186+
return result.onlineStatus;
187+
}());
188+
}
189+
else
190+
{
191+
resultObject.onlineStatus = false;
192+
}
193+
194+
return resultObject;
195+
}());
196+
197+
resolve(resolveValue);
198+
})
199+
.catch(error => reject(error));
200+
});
201+
}
202+
83203
/**
84204
* List all RTUs [GET /rtus]
85205
*
@@ -134,6 +254,137 @@ class RTUController
134254
.catch(error => reject(error));
135255
});
136256
}
257+
258+
/**
259+
* Retrieve the Statuses of all RTUs [GET /rtus/statuses]
260+
*
261+
* An Array of Statuses for all RTUs
262+
*
263+
* @static
264+
* @public
265+
* @param {RTUController.GetAllStatusesQueryParameters} [queryParameters] The Optional Query Parameters
266+
* @return {Promise<Array<RTUController.RTUStatusItem>>}
267+
*/
268+
static getAllStatuses(queryParameters = {})
269+
{
270+
return new Promise((resolve, reject) => {
271+
RequestHelper.getRequest(`/rtus/statuses`, queryParameters)
272+
.then((result) => {
273+
let resolveValue = (function(){
274+
if(Array.isArray(result) !== true)
275+
{
276+
return [];
277+
}
278+
279+
return result.map((resultItem) => {
280+
return (function(){
281+
let resultItemObject = {};
282+
283+
if(typeof resultItem === 'object' && 'id' in resultItem)
284+
{
285+
resultItemObject.id = (function(){
286+
if(typeof resultItem.id !== 'number')
287+
{
288+
return Number.isInteger(Number(resultItem.id)) ? Number(resultItem.id) : Math.floor(Number(resultItem.id));
289+
}
290+
291+
return Number.isInteger(resultItem.id) ? resultItem.id : Math.floor(resultItem.id);
292+
}());
293+
}
294+
else
295+
{
296+
resultItemObject.id = 0;
297+
}
298+
299+
if(typeof resultItem === 'object' && 'latency' in resultItem)
300+
{
301+
resultItemObject.latency = (function(){
302+
if(resultItem.latency === null)
303+
{
304+
return null;
305+
}
306+
307+
if(typeof resultItem.latency !== 'number')
308+
{
309+
return Number(resultItem.latency);
310+
}
311+
312+
return resultItem.latency;
313+
}());
314+
}
315+
else
316+
{
317+
resultItemObject.latency = null;
318+
}
319+
320+
if(typeof resultItem === 'object' && 'latencyTimestamp' in resultItem)
321+
{
322+
resultItemObject.latencyTimestamp = (function(){
323+
if(resultItem.latencyTimestamp === null)
324+
{
325+
return null;
326+
}
327+
328+
if(typeof resultItem.latencyTimestamp !== 'string')
329+
{
330+
return new Date(String(resultItem.latencyTimestamp));
331+
}
332+
333+
return new Date(resultItem.latencyTimestamp);
334+
}());
335+
}
336+
else
337+
{
338+
resultItemObject.latencyTimestamp = null;
339+
}
340+
341+
if(typeof resultItem === 'object' && 'lastSeenTimestamp' in resultItem)
342+
{
343+
resultItemObject.lastSeenTimestamp = (function(){
344+
if(resultItem.lastSeenTimestamp === null)
345+
{
346+
return null;
347+
}
348+
349+
if(typeof resultItem.lastSeenTimestamp !== 'string')
350+
{
351+
return new Date(String(resultItem.lastSeenTimestamp));
352+
}
353+
354+
return new Date(resultItem.lastSeenTimestamp);
355+
}());
356+
}
357+
else
358+
{
359+
resultItemObject.lastSeenTimestamp = null;
360+
}
361+
362+
if(typeof resultItem === 'object' && 'onlineStatus' in resultItem)
363+
{
364+
resultItemObject.onlineStatus = (function(){
365+
if(typeof resultItem.onlineStatus !== 'boolean')
366+
{
367+
return Boolean(resultItem.onlineStatus);
368+
}
369+
370+
return resultItem.onlineStatus;
371+
}());
372+
}
373+
else
374+
{
375+
resultItemObject.onlineStatus = false;
376+
}
377+
378+
return resultItemObject;
379+
}());
380+
});
381+
}());
382+
383+
resolve(resolveValue);
384+
})
385+
.catch(error => reject(error));
386+
});
387+
}
137388
}
138389

139390
export default RTUController;
@@ -148,6 +399,14 @@ export default RTUController;
148399
* @memberof Controllers
149400
*/
150401

402+
/**
403+
* The Optional Query Parameters for the getAllStatuses Function
404+
*
405+
* @typedef {Object} RTUController.GetAllStatusesQueryParameters
406+
* @property {number[]} [rtuIds] A List of RTU IDs to Filter by
407+
* @memberof Controllers
408+
*/
409+
151410
/**
152411
* The Create Data for a RTU
153412
*
@@ -165,4 +424,16 @@ export default RTUController;
165424
* @property {string} [name] The RTU Name
166425
* @property {boolean} [enabled] Whether the RTU is Enabled
167426
* @memberof Controllers
427+
*/
428+
429+
/**
430+
* A **RTUStatusItem** Type
431+
*
432+
* @typedef {Object} RTUController.RTUStatusItem
433+
* @property {number} id ID of the RTU
434+
* @property {?number} latency Round-Trip Latency of the RTU represented in milliseconds
435+
* @property {?Date} latencyTimestamp When the Latency was last Updated
436+
* @property {?Date} lastSeenTimestamp When the Last Message was Received from the RTU
437+
* @property {boolean} onlineStatus Whether the RTU is considered as Online
438+
* @memberof Controllers
168439
*/

0 commit comments

Comments
 (0)