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
22 lines (21 loc) • 691 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoDecode = void 0;
const mysensors_msg_1 = require("../mysensors-msg");
const mysensors_mqtt_1 = require("./mysensors-mqtt");
const mysensors_serial_1 = require("./mysensors-serial");
async function AutoDecode(msg) {
if ((0, mysensors_msg_1.validateStrongMysensorsMsg)(msg)) {
return {
...msg,
origin: mysensors_msg_1.MsgOrigin.decoded,
};
}
if (!msg.topic) {
return new mysensors_serial_1.MysensorsSerial().decode(msg);
}
else {
return new mysensors_mqtt_1.MysensorsMqtt().decode(msg);
}
}
exports.AutoDecode = AutoDecode;