UNPKG

node-red-contrib-mysensors

Version:

Mysensors related nodes, for decoding / encoding mysensors serial protocol and MQTT topic, and wrapping arbitrary messages into mysensors compatible messages

25 lines (24 loc) 864 B
"use strict"; const mysensors_mqtt_1 = require("../lib/decoder/mysensors-mqtt"); const mysensors_serial_1 = require("../lib/decoder/mysensors-serial"); const mysensors_msg_1 = require("../lib/mysensors-msg"); module.exports = (RED) => { RED.nodes.registerType('mysencode', function (props) { RED.nodes.createNode(this, props); if (props.mqtt) { this.decoder = new mysensors_mqtt_1.MysensorsMqtt(); } else { this.decoder = new mysensors_serial_1.MysensorsSerial(); } this.on('input', (msg, send, done) => { if (props.mqtttopic !== '') { msg.topicRoot = props.mqtttopic; } if ((0, mysensors_msg_1.validateStrongMysensorsMsg)(msg)) { send(this.decoder.encode(msg)); } done(); }); }); };