RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/Site/AlarmModel.js

/**
 * File Auto-Generated by the RICADO Gen 4 PHP API Project
 * 
 * Do Not Edit this File Manually!
 */

import BaseModel from '../../Models/BaseModel';

/**
 * Model Class for a Alarm
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class AlarmModel extends BaseModel
{
    /**
     * AlarmModel Constructor
     * 
     * @protected
     * @param {number} siteId The Site ID associated with this Alarm
     */
    constructor(siteId)
    {
        super();
        
        /**
         * The Alarm ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The RTU this Alarm belongs to
         * 
         * @type {?number}
         * @public
         */
        this.rtuId = null;
        
        /**
         * The Alarm Group this Alarm is a part of
         * 
         * @type {string}
         * @public
         */
        this.groupId = "";
        
        /**
         * The Alarm Name
         * 
         * @type {string}
         * @public
         */
        this.name = "";
        
        /**
         * Whether the Alarm is Critical or not
         * 
         * @type {boolean}
         * @public
         */
        this.critical = false;
        
        /**
         * The Python Script with the Conditions to Trip this Alarm
         * 
         * @type {string}
         * @public
         */
        this.tripScript = "";
        
        /**
         * The Python Script with the Conditions to Reset this Alarm
         * 
         * @type {?string}
         * @public
         */
        this.resetScript = null;
        
        /**
         * The Delay before this Alarm will Trip in Milliseconds
         * 
         * @type {number}
         * @public
         */
        this.tripDelay = 0;
        
        /**
         * The Delay before this Alarm will Reset in Milliseconds
         * 
         * @type {number}
         * @public
         */
        this.resetDelay = 0;
        
        /**
         * Whether the Alarm should Automatically Reset
         * 
         * @type {boolean}
         * @public
         */
        this.autoReset = false;
        
        /**
         * The Delay before this Alarm should Auto Reset in Milliseconds
         * 
         * @type {number}
         * @public
         */
        this.autoResetDelay = 0;
        
        /**
         * The Point used to store the Alarm Tripped State
         * 
         * @type {number}
         * @public
         */
        this.trippedStatePoint = 0;
        
        /**
         * The Point used to store the Alarm Tripped Timestamp
         * 
         * @type {number}
         * @public
         */
        this.trippedTimestampPoint = 0;
        
        /**
         * The Point used to store the Alarm's Internal Trip Start
         * 
         * @type {number}
         * @public
         */
        this.internalTripStartPoint = 0;
        
        /**
         * The Point used to store the Alarm's Internal Reset Start
         * 
         * @type {number}
         * @public
         */
        this.internalResetStartPoint = 0;
        
        /**
         * Whether the Alarm has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the Alarm was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
        
        /**
         * The Site ID associated with this Alarm
         * 
         * @type {number}
         * @public
         */
        this.siteId = siteId;
    }

    /**
     * Create a new **AlarmModel** from a JSON Object or JSON String
     * 
     * @static
     * @public
     * @param {Object<string, any>|string} json A JSON Object or JSON String
     * @param {number} siteId The Site ID associated with this Alarm
     * @return {AlarmModel}
     */
    static fromJSON(json, siteId)
    {
        let model = new AlarmModel(siteId);
        
        /**
         * The JSON Object
         * 
         * @type {Object<string, any>}
         */
        let jsonObject = {};
        
        if(typeof json === 'string')
        {
            jsonObject = JSON.parse(json);
        }
        else if(typeof json === 'object')
        {
            jsonObject = json;
        }
        
        if('id' in jsonObject)
        {
            model.id = (function(){
                if(typeof jsonObject['id'] !== 'string')
                {
                    return String(jsonObject['id']);
                }
        
                return jsonObject['id'];
            }());
        }
        
        if('rtuId' in jsonObject)
        {
            model.rtuId = (function(){
                if(jsonObject['rtuId'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['rtuId'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['rtuId'])) ? Number(jsonObject['rtuId']) : Math.floor(Number(jsonObject['rtuId']));
                }
        
                return Number.isInteger(jsonObject['rtuId']) ? jsonObject['rtuId'] : Math.floor(jsonObject['rtuId']);
            }());
        }
        
        if('groupId' in jsonObject)
        {
            model.groupId = (function(){
                if(typeof jsonObject['groupId'] !== 'string')
                {
                    return String(jsonObject['groupId']);
                }
        
                return jsonObject['groupId'];
            }());
        }
        
        if('name' in jsonObject)
        {
            model.name = (function(){
                if(typeof jsonObject['name'] !== 'string')
                {
                    return String(jsonObject['name']);
                }
        
                return jsonObject['name'];
            }());
        }
        
        if('critical' in jsonObject)
        {
            model.critical = (function(){
                if(typeof jsonObject['critical'] !== 'boolean')
                {
                    return Boolean(jsonObject['critical']);
                }
        
                return jsonObject['critical'];
            }());
        }
        
        if('tripScript' in jsonObject)
        {
            model.tripScript = (function(){
                if(typeof jsonObject['tripScript'] !== 'string')
                {
                    return String(jsonObject['tripScript']);
                }
        
                return jsonObject['tripScript'];
            }());
        }
        
        if('resetScript' in jsonObject)
        {
            model.resetScript = (function(){
                if(jsonObject['resetScript'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['resetScript'] !== 'string')
                {
                    return String(jsonObject['resetScript']);
                }
        
                return jsonObject['resetScript'];
            }());
        }
        
        if('tripDelay' in jsonObject)
        {
            model.tripDelay = (function(){
                if(typeof jsonObject['tripDelay'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['tripDelay'])) ? Number(jsonObject['tripDelay']) : Math.floor(Number(jsonObject['tripDelay']));
                }
        
                return Number.isInteger(jsonObject['tripDelay']) ? jsonObject['tripDelay'] : Math.floor(jsonObject['tripDelay']);
            }());
        }
        
        if('resetDelay' in jsonObject)
        {
            model.resetDelay = (function(){
                if(typeof jsonObject['resetDelay'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['resetDelay'])) ? Number(jsonObject['resetDelay']) : Math.floor(Number(jsonObject['resetDelay']));
                }
        
                return Number.isInteger(jsonObject['resetDelay']) ? jsonObject['resetDelay'] : Math.floor(jsonObject['resetDelay']);
            }());
        }
        
        if('autoReset' in jsonObject)
        {
            model.autoReset = (function(){
                if(typeof jsonObject['autoReset'] !== 'boolean')
                {
                    return Boolean(jsonObject['autoReset']);
                }
        
                return jsonObject['autoReset'];
            }());
        }
        
        if('autoResetDelay' in jsonObject)
        {
            model.autoResetDelay = (function(){
                if(typeof jsonObject['autoResetDelay'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['autoResetDelay'])) ? Number(jsonObject['autoResetDelay']) : Math.floor(Number(jsonObject['autoResetDelay']));
                }
        
                return Number.isInteger(jsonObject['autoResetDelay']) ? jsonObject['autoResetDelay'] : Math.floor(jsonObject['autoResetDelay']);
            }());
        }
        
        if('trippedStatePoint' in jsonObject)
        {
            model.trippedStatePoint = (function(){
                if(typeof jsonObject['trippedStatePoint'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['trippedStatePoint'])) ? Number(jsonObject['trippedStatePoint']) : Math.floor(Number(jsonObject['trippedStatePoint']));
                }
        
                return Number.isInteger(jsonObject['trippedStatePoint']) ? jsonObject['trippedStatePoint'] : Math.floor(jsonObject['trippedStatePoint']);
            }());
        }
        
        if('trippedTimestampPoint' in jsonObject)
        {
            model.trippedTimestampPoint = (function(){
                if(typeof jsonObject['trippedTimestampPoint'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['trippedTimestampPoint'])) ? Number(jsonObject['trippedTimestampPoint']) : Math.floor(Number(jsonObject['trippedTimestampPoint']));
                }
        
                return Number.isInteger(jsonObject['trippedTimestampPoint']) ? jsonObject['trippedTimestampPoint'] : Math.floor(jsonObject['trippedTimestampPoint']);
            }());
        }
        
        if('internalTripStartPoint' in jsonObject)
        {
            model.internalTripStartPoint = (function(){
                if(typeof jsonObject['internalTripStartPoint'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['internalTripStartPoint'])) ? Number(jsonObject['internalTripStartPoint']) : Math.floor(Number(jsonObject['internalTripStartPoint']));
                }
        
                return Number.isInteger(jsonObject['internalTripStartPoint']) ? jsonObject['internalTripStartPoint'] : Math.floor(jsonObject['internalTripStartPoint']);
            }());
        }
        
        if('internalResetStartPoint' in jsonObject)
        {
            model.internalResetStartPoint = (function(){
                if(typeof jsonObject['internalResetStartPoint'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['internalResetStartPoint'])) ? Number(jsonObject['internalResetStartPoint']) : Math.floor(Number(jsonObject['internalResetStartPoint']));
                }
        
                return Number.isInteger(jsonObject['internalResetStartPoint']) ? jsonObject['internalResetStartPoint'] : Math.floor(jsonObject['internalResetStartPoint']);
            }());
        }
        
        if('deleted' in jsonObject)
        {
            model.deleted = (function(){
                if(typeof jsonObject['deleted'] !== 'boolean')
                {
                    return Boolean(jsonObject['deleted']);
                }
        
                return jsonObject['deleted'];
            }());
        }
        
        if('updateTimestamp' in jsonObject)
        {
            model.updateTimestamp = (function(){
                if(typeof jsonObject['updateTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['updateTimestamp']));
                }
        
                return new Date(jsonObject['updateTimestamp']);
            }());
        }
        
        return model;
    }
}

export default AlarmModel;