domotz-remote-pawn
Version:
Domotz Agent
58 lines (53 loc) • 2.12 kB
JavaScript
/**
* This file is part of Domotz Agent.
*
* @license
* Domotz Agent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Domotz Agent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright (C) Domotz Inc
*/
/**
* Library for handling parameters passed to the sandbox during execution.
* Needs to be instantiated with an object that holds the parameters as key-value pairs
* @private
* */
/**
* Creates a custom driver parameters library sandbox object.
* @constructor
* @private
* @readonly
* @param {Object} myConsole - The Domotz Sandbox console
* @param {Object} parameters - Parameters for the context
*/
function parameterLibrary(myConsole, parameters) {
const _parameters = parameters === undefined || parameters === null ? {} : parameters;
return {
/**
* Get the value of a parameter by its name. Returns undefined in case the parameter was not provided to the context.
* @memberof D.parameters
* @param {string} parameterName - name of the parameter to fetch
* @readonly
* @function
* @return {string|number|Object|undefined} - the value associated with the provided parameter name
*/
getParameter: function (parameterName) {
const value = _parameters[parameterName];
if (value === undefined) {
myConsole.warn('Missing parameter name ' + parameterName + ', returning undefined');
}
return value;
},
};
}
module.exports.parameterLibrary = parameterLibrary;