UNPKG

node-red-contrib-uhppoted

Version:

A set of nodes for the UHPPOTE Wiegand Access Controller

55 lines (45 loc) 1.36 kB
module.exports = function (RED) { const common = require('./common.js') const uhppoted = require('./uhppoted.js') const opcodes = require('../nodes/opcodes.js') function GetEventIndexNode(config) { RED.nodes.createNode(this, config) const node = this const topic = config.topic const uhppote = RED.nodes.getNode(config.config) common.ok(node) this.on('input', function (msg, send, done) { const t = topic && topic !== '' ? topic : msg.topic const controller = common.resolve(msg.payload) const emit = function (object) { common.emit(node, t, object) } const error = function (err) { common.error(node, err) } try { const context = { config: uhppote, translator: (k) => { return RED._('uhppoted-get-event-index.' + k) }, logger: (m) => { node.log(m) }, } uhppoted .get(context, controller.id, opcodes.GetEventIndex, {}, controller.address, controller.protocol) .then((object) => { emit(object) }) .then(done()) .catch((err) => { error(err) }) } catch (err) { error(err) } }) } RED.nodes.registerType('uhppoted-get-event-index', GetEventIndexNode) }