UNPKG

@iotile/iotile-cloud

Version:

A typescript library for interfacing with the IOTile Cloud API

66 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var mdo_1 = require("./mdo"); var unit_1 = require("./unit"); ; var Variable = /** @class */ (function () { function Variable(data) { if (data === void 0) { data = {}; } this.inputUnit = null; this.outputUnit = null; this.id = data.id; this.slug = data.slug; this.lid = data.lid; this.name = data.name || data.slug; this.units = data.units; this.appOnly = data.app_only || false; this.webOnly = data.web_only || false; this.sysVar = data.project === null; this.about = data.about || ""; this.mdo = new mdo_1.Mdo(data); this.type = data.var_type; this.rawData = data; this.project = data.project; this.decimalPlaces = data.decimal_places || 0; if (data.input_unit) { this.inputUnit = new unit_1.Unit(data.input_unit); } if (data.output_unit) { this.outputUnit = new unit_1.Unit(data.output_unit); } } Variable.prototype.toJson = function () { return this.rawData; }; Variable.prototype.getHexLid = function () { if (this.slug) { var elements = this.slug.split("--"); if (elements.length === 3) { return elements[2]; } } return ""; }; Variable.prototype.getPatchPayload = function () { var basic = { name: this.name }; var payload = Object.assign(basic, this.mdo.getPatchPayload()); if (this.units) { payload['units'] = this.units; } if (this.inputUnit) { payload['input_unit'] = this.inputUnit.slug; } if (this.outputUnit) { payload['output_unit'] = this.outputUnit.slug; } if (this.about) { payload['about'] = this.about; } return payload; }; return Variable; }()); exports.Variable = Variable; //# sourceMappingURL=variable.js.map