node-red-contrib-uhppoted
Version:
A set of nodes for the UHPPOTE Wiegand Access Controller
56 lines (46 loc) • 1.4 kB
JavaScript
module.exports = function (RED) {
const common = require('./common.js')
const uhppoted = require('./uhppoted.js')
const opcodes = require('../nodes/opcodes.js')
function SetEventIndexNode(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 index = msg.payload.index
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-set-event-index.' + k)
},
logger: (m) => {
node.log(m)
},
}
uhppoted
.set(context, controller.id, opcodes.SetEventIndex, { index }, controller.address, controller.protocol)
.then((object) => {
emit(object)
})
.then(done())
.catch((err) => {
error(err)
})
} catch (err) {
error(err)
}
})
}
RED.nodes.registerType('uhppoted-set-event-index', SetEventIndexNode)
}