RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

DataItems/PointValueItem.js

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

/**
 * A PointValueItem Class
 * 
 * @class
 * @hideconstructor
 */
class PointValueItem
{
    /**
     * PointValueItem Constructor
     * 
     * @protected
     */
    constructor()
    {
        /**
         * The Point ID
         * 
         * @type {number}
         * @private
         */
        this._id = 0;
        
        /**
         * The Point Value
         * 
         * @type {any}
         * @private
         */
        this._value = null;
        
        /**
         * When the Point Value last changed
         * 
         * @type {Date}
         * @private
         */
        this._timestamp = new Date();
    }

    /**
     * The Point ID
     * 
     * @public
     * @type {number}
     */
    get id()
    {
        return this._id;
    }

    /**
     * The Point ID
     * 
     * @public
     * @type {number}
     */
    set id(value)
    {
        this._id = value;
    }

    /**
     * The Point Value
     * 
     * @public
     * @type {any}
     */
    get value()
    {
        return this._value;
    }

    /**
     * The Point Value
     * 
     * @public
     * @type {any}
     */
    set value(value)
    {
        this._value = value;
    }

    /**
     * When the Point Value last changed
     * 
     * @public
     * @type {Date}
     */
    get timestamp()
    {
        return this._timestamp;
    }

    /**
     * When the Point Value last changed
     * 
     * @public
     * @type {Date}
     */
    set timestamp(value)
    {
        this._timestamp = value;
    }

    /**
     * Convert this **PointValueItem** to a JSON Object
     * 
     * @public
     * @return {Object<string, any>}
     */
    toJSON()
    {
        return {
            id: this._id,
            value: this._value,
            timestamp: this._timestamp,
        };
    }

    /**
     * Create a new **PointValueItem** from a JSON Object or JSON String
     * 
     * @static
     * @public
     * @param {Object<string, any>|string} json A JSON Object or JSON String
     * @return {PointValueItem}
     */
    static fromJSON(json)
    {
        let dataItem = new PointValueItem();
        
        /**
         * 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)
        {
            dataItem._id = (function(){
                if(typeof jsonObject['id'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['id'])) ? Number(jsonObject['id']) : Math.floor(Number(jsonObject['id']));
                }
        
                return Number.isInteger(jsonObject['id']) ? jsonObject['id'] : Math.floor(jsonObject['id']);
            }());
        }
        
        if('value' in jsonObject)
        {
            dataItem._value = (function(){
                return jsonObject['value'];
            }());
        }
        
        if('timestamp' in jsonObject)
        {
            dataItem._timestamp = (function(){
                if(typeof jsonObject['timestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['timestamp']));
                }
        
                return new Date(jsonObject['timestamp']);
            }());
        }
        
        return dataItem;
    }
}

export default PointValueItem;