node-red-contrib-freya-nodes
Version:
Custom nodes for Freya Vivarium Control System
37 lines (36 loc) • 1.44 kB
JavaScript
;
const environment_sensor_1 = require("./environment-sensor");
const environmentSensor = (RED) => {
function EnvironmentSensorNode(config) {
RED.nodes.createNode(this, config);
const node = this;
const variable = config.variable;
const sampleinterval = parseFloat(config.sampleinterval);
const sensorDriver = new environment_sensor_1.SensorDriver();
sensorDriver.on('status', (status) => {
switch (status.level) {
case 'ok':
node.status({ fill: 'green', shape: 'dot', text: status.message });
break;
case 'warning':
node.status({ fill: 'yellow', shape: 'dot', text: status.message });
break;
default:
node.status({ fill: 'red', shape: 'dot', text: status.message });
break;
}
});
sensorDriver.on('measurement', (measurement) => {
if (Object.prototype.hasOwnProperty.call(measurement, variable) || variable === 'all') {
const msg = {
_msgid: '',
topic: "measurement",
payload: measurement
};
this.send(msg);
}
});
}
RED.nodes.registerType('environment sensor', EnvironmentSensorNode);
};
module.exports = environmentSensor;