UNPKG

node-red-contrib-smartnora

Version:

Google Smart Home integration via Smart Nora https://smart-nora.eu/

44 lines (43 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("./util"); module.exports = function (RED) { RED.nodes.registerType('noraf-config', function (config) { var _a, _b, _c, _d, _e, _f, _g, _h; RED.nodes.createNode(this, config); this.email = this.credentials && this.credentials.email; this.password = this.credentials && this.credentials.password; this.sso = this.credentials && this.credentials.sso; this.group = ((0, util_1.escapeFirebasePath)((_a = config.group) === null || _a === void 0 ? void 0 : _a.trim()) || (0, util_1.getId)(config)); this.valid = !!((_b = this.email) === null || _b === void 0 ? void 0 : _b.length) && (!!((_c = this.password) === null || _c === void 0 ? void 0 : _c.length) || !!((_d = this.sso) === null || _d === void 0 ? void 0 : _d.length)); this.localExecution = (_e = config.localexecution) !== null && _e !== void 0 ? _e : true; this.storeStateInContext = (_f = config.storeStateInContext) !== null && _f !== void 0 ? _f : false; this.disableValidationErrors = (_g = config.disableValidationErrors) !== null && _g !== void 0 ? _g : false; this.sendDeviceNameAndLocation = (_h = config.sendDeviceNameAndLocation) !== null && _h !== void 0 ? _h : false; let structureHint; if (typeof config.structure === 'string') { structureHint = config.structure.trim() || undefined; } this.setCommon = (device, deviceConfig) => { var _a; device.structureHint = structureHint; device.noraSpecific.twoFactor = (_a = getTwoFactor(config)) !== null && _a !== void 0 ? _a : getTwoFactor(deviceConfig); return device; }; }, { credentials: { email: { type: 'text' }, password: { type: 'text' }, sso: { type: 'text' }, }, }); }; function getTwoFactor(config) { var _a; if (config.twofactor === 'pin' || config.twofactor === 'ack') { return { type: config.twofactor, pin: config.twofactor === 'pin' ? (_a = config.twofactorpin) === null || _a === void 0 ? void 0 : _a.trim() : undefined, }; } }