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

27 lines (26 loc) 951 B
"use strict"; const mysensors_mqtt_1 = require("../lib/decoder/mysensors-mqtt"); const mysensors_serial_1 = require("../lib/decoder/mysensors-serial"); module.exports = (RED) => { RED.nodes.registerType('mysdecode', function (props) { const config = props; if (props.database) { this.database = RED.nodes.getNode(props.database); } this.enrich = props.enrich; if (config.mqtt) { this.decoder = new mysensors_mqtt_1.MysensorsMqtt(props.enrich, this.database?.database); } else { this.decoder = new mysensors_serial_1.MysensorsSerial(props.enrich, this.database?.database); } RED.nodes.createNode(this, config); this.on('input', async (msg, send, done) => { const message = await this.decoder.decode(msg); if (message) { send(message); } done(); }); }); };