/**
* File Auto-Generated by the RICADO Gen 4 PHP API Project
*
* Do Not Edit this File Manually!
*/
import RequestHelper from '../../RequestHelper';
import AlarmModel from '../../Models/Site/AlarmModel';
/**
* Controller Class for Alarms
*
* @class
*/
class AlarmController
{
/**
* Retrieve a Alarm [GET /sites/{siteId}/alarms/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Alarm ID
* @return {Promise<AlarmModel>}
*/
static getOne(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/sites/${siteId}/alarms/${id}`)
.then((result) => {
let resolveValue = (function(){
return AlarmModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Update a Alarm [PATCH /sites/{siteId}/alarms/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Alarm ID
* @param {AlarmController.UpdateData} updateData The Alarm Update Data
* @return {Promise<AlarmModel>}
*/
static update(siteId, id, updateData)
{
return new Promise((resolve, reject) => {
RequestHelper.patchRequest(`/sites/${siteId}/alarms/${id}`, updateData)
.then((result) => {
let resolveValue = (function(){
return AlarmModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Delete a Alarm [DELETE /sites/{siteId}/alarms/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Alarm ID
* @return {Promise<boolean>}
*/
static delete(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.deleteRequest(`/sites/${siteId}/alarms/${id}`)
.then((result) => {
resolve(result ?? true);
})
.catch(error => reject(error));
});
}
/**
* Retrieve the History of an Alarm [GET /sites/{siteId}/alarms/{id}/history]
*
* Retrieves History (Logged Events) for a Single Alarm
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Alarm ID
* @param {AlarmController.GetOneHistoryQueryParameters} [queryParameters] The Optional Query Parameters
* @return {Promise<Array<AlarmController.AlarmHistoryItem>>}
*/
static getOneHistory(siteId, id, queryParameters = {})
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/sites/${siteId}/alarms/${id}/history`, queryParameters)
.then((result) => {
let resolveValue = (function(){
if(Array.isArray(result) !== true)
{
return [];
}
return result.map((resultItem) => {
return (function(){
let resultItemObject = {};
if(typeof resultItem === 'object' && 'id' in resultItem)
{
resultItemObject.id = (function(){
if(typeof resultItem.id !== 'string')
{
return String(resultItem.id);
}
return resultItem.id;
}());
}
else
{
resultItemObject.id = "";
}
if(typeof resultItem === 'object' && 'tripTimestamp' in resultItem)
{
resultItemObject.tripTimestamp = (function(){
if(typeof resultItem.tripTimestamp !== 'string')
{
return new Date(String(resultItem.tripTimestamp));
}
return new Date(resultItem.tripTimestamp);
}());
}
else
{
resultItemObject.tripTimestamp = new Date();
}
if(typeof resultItem === 'object' && 'resetTimestamp' in resultItem)
{
resultItemObject.resetTimestamp = (function(){
if(resultItem.resetTimestamp === null)
{
return null;
}
if(typeof resultItem.resetTimestamp !== 'string')
{
return new Date(String(resultItem.resetTimestamp));
}
return new Date(resultItem.resetTimestamp);
}());
}
else
{
resultItemObject.resetTimestamp = null;
}
if(typeof resultItem === 'object' && 'trippedDuration' in resultItem)
{
resultItemObject.trippedDuration = (function(){
if(typeof resultItem.trippedDuration !== 'number')
{
return Number.isInteger(Number(resultItem.trippedDuration)) ? Number(resultItem.trippedDuration) : Math.floor(Number(resultItem.trippedDuration));
}
return Number.isInteger(resultItem.trippedDuration) ? resultItem.trippedDuration : Math.floor(resultItem.trippedDuration);
}());
}
else
{
resultItemObject.trippedDuration = 0;
}
return resultItemObject;
}());
});
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* List all Alarms [GET /sites/{siteId}/alarms]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {AlarmController.GetAllQueryParameters} [queryParameters] The Optional Query Parameters
* @return {Promise<AlarmModel[]>}
*/
static getAll(siteId, queryParameters = {})
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/sites/${siteId}/alarms`, queryParameters)
.then((result) => {
let resolveValue = (function(){
if(Array.isArray(result) !== true)
{
return [];
}
return result.map((resultItem) => {
return (function(){
return AlarmModel.fromJSON(resultItem, siteId);
}());
});
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Create a Alarm [POST /sites/{siteId}/alarms]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {AlarmController.CreateData} createData The Alarm Create Data
* @return {Promise<AlarmModel>}
*/
static create(siteId, createData)
{
return new Promise((resolve, reject) => {
RequestHelper.postRequest(`/sites/${siteId}/alarms`, createData)
.then((result) => {
let resolveValue = (function(){
return AlarmModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Retrieve the History of all Alarms [GET /sites/{siteId}/alarms/history]
*
* Retrieves History (Logged Events) for all Alarms
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {AlarmController.GetAllHistoryQueryParameters} [queryParameters] The Optional Query Parameters
* @return {Promise<Array<AlarmController.AlarmHistoryItem>>}
*/
static getAllHistory(siteId, queryParameters = {})
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/sites/${siteId}/alarms/history`, queryParameters)
.then((result) => {
let resolveValue = (function(){
if(Array.isArray(result) !== true)
{
return [];
}
return result.map((resultItem) => {
return (function(){
let resultItemObject = {};
if(typeof resultItem === 'object' && 'id' in resultItem)
{
resultItemObject.id = (function(){
if(typeof resultItem.id !== 'string')
{
return String(resultItem.id);
}
return resultItem.id;
}());
}
else
{
resultItemObject.id = "";
}
if(typeof resultItem === 'object' && 'tripTimestamp' in resultItem)
{
resultItemObject.tripTimestamp = (function(){
if(typeof resultItem.tripTimestamp !== 'string')
{
return new Date(String(resultItem.tripTimestamp));
}
return new Date(resultItem.tripTimestamp);
}());
}
else
{
resultItemObject.tripTimestamp = new Date();
}
if(typeof resultItem === 'object' && 'resetTimestamp' in resultItem)
{
resultItemObject.resetTimestamp = (function(){
if(resultItem.resetTimestamp === null)
{
return null;
}
if(typeof resultItem.resetTimestamp !== 'string')
{
return new Date(String(resultItem.resetTimestamp));
}
return new Date(resultItem.resetTimestamp);
}());
}
else
{
resultItemObject.resetTimestamp = null;
}
if(typeof resultItem === 'object' && 'trippedDuration' in resultItem)
{
resultItemObject.trippedDuration = (function(){
if(typeof resultItem.trippedDuration !== 'number')
{
return Number.isInteger(Number(resultItem.trippedDuration)) ? Number(resultItem.trippedDuration) : Math.floor(Number(resultItem.trippedDuration));
}
return Number.isInteger(resultItem.trippedDuration) ? resultItem.trippedDuration : Math.floor(resultItem.trippedDuration);
}());
}
else
{
resultItemObject.trippedDuration = 0;
}
return resultItemObject;
}());
});
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
}
export default AlarmController;
/**
* The Optional Query Parameters for the getOneHistory Function
*
* @typedef {Object} AlarmController.GetOneHistoryQueryParameters
* @property {Date} [timestampBegin] The Beginning Timestamp of the Alarm History Results. Defaults to 24 Hours ago
* @property {Date} [timestampEnd] The End Timestamp of the Alarm History Results. Defaults to Now
* @memberof Controllers.Site
*/
/**
* The Optional Query Parameters for the getAll Function
*
* @typedef {Object} AlarmController.GetAllQueryParameters
* @property {?number} [rtuId] The RTU this Alarm belongs to
* @property {string} [groupId] The Alarm Group this Alarm is a part of
* @property {string} [name] The Alarm Name
* @property {boolean} [critical] Whether the Alarm is Critical or not
* @property {boolean} [autoReset] Whether the Alarm should Automatically Reset
* @property {number} [trippedStatePoint] The Point used to store the Alarm Tripped State
* @property {number} [trippedTimestampPoint] The Point used to store the Alarm Tripped Timestamp
* @property {number} [internalTripStartPoint] The Point used to store the Alarm's Internal Trip Start
* @property {number} [internalResetStartPoint] The Point used to store the Alarm's Internal Reset Start
* @memberof Controllers.Site
*/
/**
* The Optional Query Parameters for the getAllHistory Function
*
* @typedef {Object} AlarmController.GetAllHistoryQueryParameters
* @property {string[]} [alarmIds] A List of Alarm IDs to Filter by
* @property {string[]} [groupIds] A List of Alarm Group IDs to Filter by
* @property {Date} [timestampBegin] The Beginning Timestamp of the Alarm History Results. Defaults to 24 Hours ago
* @property {Date} [timestampEnd] The End Timestamp of the Alarm History Results. Defaults to Now
* @memberof Controllers.Site
*/
/**
* The Create Data for a Alarm
*
* @typedef {Object} AlarmController.CreateData
* @property {?number} [rtuId] The RTU this Alarm belongs to
* @property {string} groupId The Alarm Group this Alarm is a part of
* @property {string} name The Alarm Name
* @property {boolean} critical Whether the Alarm is Critical or not
* @property {string} tripScript The Python Script with the Conditions to Trip this Alarm
* @property {?string} [resetScript] The Python Script with the Conditions to Reset this Alarm
* @property {number} [tripDelay] The Delay before this Alarm will Trip in Milliseconds
* @property {number} [resetDelay] The Delay before this Alarm will Reset in Milliseconds
* @property {boolean} [autoReset] Whether the Alarm should Automatically Reset
* @property {number} [autoResetDelay] The Delay before this Alarm should Auto Reset in Milliseconds
* @property {number} trippedStatePoint The Point used to store the Alarm Tripped State
* @property {number} trippedTimestampPoint The Point used to store the Alarm Tripped Timestamp
* @property {number} internalTripStartPoint The Point used to store the Alarm's Internal Trip Start
* @property {number} internalResetStartPoint The Point used to store the Alarm's Internal Reset Start
* @memberof Controllers.Site
*/
/**
* The Update Data for a Alarm
*
* @typedef {Object} AlarmController.UpdateData
* @property {string} [groupId] The Alarm Group this Alarm is a part of
* @property {string} [name] The Alarm Name
* @property {boolean} [critical] Whether the Alarm is Critical or not
* @property {string} [tripScript] The Python Script with the Conditions to Trip this Alarm
* @property {?string} [resetScript] The Python Script with the Conditions to Reset this Alarm
* @property {number} [tripDelay] The Delay before this Alarm will Trip in Milliseconds
* @property {number} [resetDelay] The Delay before this Alarm will Reset in Milliseconds
* @property {boolean} [autoReset] Whether the Alarm should Automatically Reset
* @property {number} [autoResetDelay] The Delay before this Alarm should Auto Reset in Milliseconds
* @property {number} [trippedStatePoint] The Point used to store the Alarm Tripped State
* @property {number} [trippedTimestampPoint] The Point used to store the Alarm Tripped Timestamp
* @property {number} [internalTripStartPoint] The Point used to store the Alarm's Internal Trip Start
* @property {number} [internalResetStartPoint] The Point used to store the Alarm's Internal Reset Start
* @memberof Controllers.Site
*/
/**
* A **AlarmHistoryItem** Type
*
* @typedef {Object} AlarmController.AlarmHistoryItem
* @property {string} id The Alarm ID
* @property {Date} tripTimestamp When the Alarm Tripped
* @property {?Date} resetTimestamp When the Alarm Reset
* @property {number} trippedDuration The Duration in Seconds that the Alarm was Tripped
* @memberof Controllers.Site
*/
source