UNPKG

keyble-nodered

Version:

Node-RED nodes for controlling eQ-3 eqiva bluetooth smart locks

29 lines (28 loc) 893 B
module.exports = function(RED) { 'use strict'; const KeybleSendCommandNode = function(configuration) { const node = this; RED.nodes.createNode(node, configuration); node.connection = RED.nodes.getNode(configuration.connection); node.on('input', function(msg, send, done) { send = (send || ((...args) => {node.send.apply(node, args)})); const command = msg.payload.trim().toLowerCase(); const command_function = {'open':'open', 'lock':'lock', 'unlock':'unlock', 'toggle':'toggle'}[command]; node.connection.key_ble[command_function]().then(() => { if (done) { done(); } }); }); node.on('close', function(removed, done) { // tidy up any state if (removed) { // This node has been disabled/deleted } else { // This node is being restarted } done(); }); } RED.nodes.registerType('keyble-send_command', KeybleSendCommandNode); }