UNPKG

node-red-contrib-boolean-logic-ultimate

Version:

A set of Node-RED enhanced boolean logic and utility nodes, flow interruption, blinker, debouncer, invert, filter, toggle etc.., with persistent values after reboot. Compatible also with Homeassistant values.

56 lines (46 loc) 1.73 kB
'use strict'; const path = require('path'); const helper = require('node-red-node-test-helper'); helper.init(require.resolve('node-red')); // initialise with Node-RED runtime const nodes = { DebouncerUltimate: require(path.join('..', 'boolean-logic-ultimate', 'DebouncerUltimate.js')), RateLimiterUltimate: require(path.join('..', 'boolean-logic-ultimate', 'RateLimiterUltimate.js')), PresenceSimulatorUltimate: require(path.join('..', 'boolean-logic-ultimate', 'PresenceSimulatorUltimate.js')), RailwaySwitchUltimate: require(path.join('..', 'boolean-logic-ultimate', 'RailwaySwitchUltimate.js')), }; function loadNode(nodeDef, flow, credentials = {}) { const normalizedFlow = flow.map((node, index) => { if ( node && node.type && node.type !== 'tab' && node.type !== 'subflow' && node.type !== 'group' && node.z && !(Object.prototype.hasOwnProperty.call(node, 'x') && Object.prototype.hasOwnProperty.call(node, 'y')) ) { return { ...node, x: 100 + index * 10, y: 100 + index * 10 }; } return node; }); return helper.load(nodeDef, normalizedFlow, credentials); } function loadRateLimiter(flow, credentials = {}) { return loadNode(nodes.RateLimiterUltimate, flow, credentials); } function loadDebouncer(flow, credentials = {}) { return loadNode(nodes.DebouncerUltimate, flow, credentials); } function loadPresence(flow, credentials = {}) { return loadNode(nodes.PresenceSimulatorUltimate, flow, credentials); } function loadRailwaySwitch(flow, credentials = {}) { return loadNode(nodes.RailwaySwitchUltimate, flow, credentials); } module.exports = { helper, loadDebouncer, loadRateLimiter, loadPresence, loadRailwaySwitch, };