Hi! I'm trying to create my first custom node, but I get this weird error: "ReferenceError: done is not defined" when I try to run my custom node. The thing is I don't use "done" method anywhere in the code. The node is supposed to be simple hysteresis controller.
.js file:
module.exports = function (RED) {
function HysteresisNode(config) {
RED.nodes.createNode(this, config);
let node = this;
node.on("input", function (msg) {
const highPlus = msg.payload.high;
const lowPlus = msg.payload.low;
const threshold = msg.payload.threshold;
const current = msg.payload.current;
if (threshold + highPlus >= current) {
msg.payload = node.highOutput;
node.send(msg);
} else if (threshold - lowPlus <= current) {
msg.payload = node.lowOutput;
node.send(msg);
}
});
}
RED.nodes.registerType("hysteresis", HysteresisNode);
};
.html file:
<script type="text/javascript">
RED.nodes.registerType("hysteresis", {
label: "hysteresis",
category: "function",
color: "#a6bbcf",
inputs: 1,
outputs: 1,
icon: "font-awesome/fa-cogs",
defaults: {
highOutput: { value: false },
lowOutput: { value: false },
highOutputType: { value: "bool" },
lowOutputType: { value: "bool" },
},
oneditprepare: function () {
$("#node-input-highOutput").typedInput({
type: "bool",
types: ["bool", "num", "str"],
default: "bool",
typeField: "#node-input-highOutput-type",
});
$("#node-input-lowOutput").typedInput({
type: "bool",
types: ["bool", "num", "str"],
default: "bool",
typeField: "#node-input-lowOutput-type",
});
},
});
</script>
<script type="text/html" data-template-name="hysteresis">
<p>Output values:</p>
<div class="form-row">
<label for="node-input-highOutput"
><i class="fa fa-tag"></i>Upper Threshold</label
>
<input type="text" id="node-input-highOutput" />
<input type="hidden" id="node-input-highOutputType" />
</div>
<div class="form-row">
<label for="node-input-lowOutput"
><i class="fa fa-tag"></i>Lower Threshold</label
>
<input type="text" id="node-input-lowOutput" />
<input type="hidden" id="node-input-lowOutputType" />
</div>
<div class="form-tips"><b>Tip:</b> This is here to help.v</div>
</script>
package.json
{
"name": "node-red-contrib-easy-hysteresis",
"version": "1.0.3",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"node-red": {
"nodes": {
"hysteresis": "hysteresis.js"
}
}
}