mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Handle weird variable crossover bug
This commit is contained in:
parent
23ebff7770
commit
ea13342c7b
@ -27,7 +27,7 @@ function HeatmiserNode(n) {
|
|||||||
this.pin = n.pin || "1234";
|
this.pin = n.pin || "1234";
|
||||||
this.pollTime = n.pollTime*60*1000 || 30*60*1000
|
this.pollTime = n.pollTime*60*1000 || 30*60*1000
|
||||||
this.multiWriteFunc = undefined;
|
this.multiWriteFunc = undefined;
|
||||||
node = this;
|
hmnode = this;
|
||||||
|
|
||||||
this.hm = new Heatmiser(this.ip, this.pin);
|
this.hm = new Heatmiser(this.ip, this.pin);
|
||||||
|
|
||||||
@ -35,24 +35,24 @@ function HeatmiserNode(n) {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
util.log(JSON.stringify(data));
|
util.log(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
node.currentStatus = data.dcb;
|
hmnode.currentStatus = data.dcb;
|
||||||
if (node.multiWriteFunc) {
|
if (hmnode.multiWriteFunc) {
|
||||||
node.multiWriteFunc();
|
hmnode.multiWriteFunc();
|
||||||
node.multiWriteFunc = undefined;
|
hmnode.multiWriteFunc = undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node.send({topic: "", payload:JSON.stringify(data.dcb)});
|
hmnode.send({topic: "", payload:JSON.stringify(data.dcb)});
|
||||||
});
|
});
|
||||||
this.hm.on('error', function(data) {
|
this.hm.on('error', function(data) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
console.log(JSON.stringify(data));
|
console.log(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
node.send(data);
|
hmnode.send(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.read = function() {
|
this.read = function() {
|
||||||
if (node.hm) {
|
if (hmnode.hm) {
|
||||||
node.hm.read_device();
|
hmnode.hm.read_device();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,7 +62,9 @@ function HeatmiserNode(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.write = function(dcb) {
|
this.write = function(dcb) {
|
||||||
node.hm.write_device(dcb);
|
if (hmnode.hm) {
|
||||||
|
hmnode.hm.write_device(dcb);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.validateAndWrite = function(message) {
|
this.validateAndWrite = function(message) {
|
||||||
@ -88,7 +90,7 @@ function HeatmiserNode(n) {
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// var time = message.payload[key].time;
|
// var time = message.payload[key].time;
|
||||||
// // Ensure node time is a date
|
// // Ensure hmnode time is a date
|
||||||
// if (typeof(time) == "string") {
|
// if (typeof(time) == "string") {
|
||||||
// util.log("Typeof time was " +typeof(message.payload[key].time));
|
// util.log("Typeof time was " +typeof(message.payload[key].time));
|
||||||
// // message.payload[key].time = new Date(message.payload[key].time);
|
// // message.payload[key].time = new Date(message.payload[key].time);
|
||||||
@ -131,13 +133,13 @@ function HeatmiserNode(n) {
|
|||||||
(target <= 10.0) ? message.payload[key].target = 10.0 : message.payload[key].target = target;
|
(target <= 10.0) ? message.payload[key].target = 10.0 : message.payload[key].target = target;
|
||||||
(hold <= 0) ? message.payload[key].hold = 0 : message.payload[key].hold = hold;
|
(hold <= 0) ? message.payload[key].hold = 0 : message.payload[key].hold = hold;
|
||||||
|
|
||||||
// Ensure node runmode == heating first
|
// Ensure hmnode runmode == heating first
|
||||||
if (node.currentStatus.run_mode === "frost_protection") {
|
if (hmnode.currentStatus.run_mode === "frost_protection") {
|
||||||
// Use the multiWriteFunc as a callback in our success case
|
// Use the multiWriteFunc as a callback in our success case
|
||||||
node.multiWriteFunc = function() {
|
hmnode.multiWriteFunc = function() {
|
||||||
node.write(message.payload);
|
hmnode.write(message.payload);
|
||||||
}
|
}
|
||||||
node.write({"runmode" : "heating"});
|
hmnode.write({"runmode" : "heating"});
|
||||||
// End the flow here to ensure no double-writing
|
// End the flow here to ensure no double-writing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -147,7 +149,7 @@ function HeatmiserNode(n) {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
util.log("[100-heatmiser.js] Hit the default case");
|
util.log("[100-heatmiser.js] Hit the default case");
|
||||||
}
|
}
|
||||||
node.read();
|
hmnode.read();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Valid set of key messages, construct DCB and write
|
// Valid set of key messages, construct DCB and write
|
||||||
@ -155,16 +157,21 @@ function HeatmiserNode(n) {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
util.log("[100-heatmiser.js] Injecting " + JSON.stringify(dcb));
|
util.log("[100-heatmiser.js] Injecting " + JSON.stringify(dcb));
|
||||||
}
|
}
|
||||||
node.write(dcb);
|
hmnode.write(dcb);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.on("input", function(message) {
|
this.on("input", function(message) {
|
||||||
// Valid inputs are heating:{target:, hold:}, read:, runmode:frost/heating, holiday:{enabled:, time:}, hotwater:{'on':1/0 / 'boost':1/0}
|
// Valid inputs are heating:{target:, hold:}, read:, runmode:frost/heating, holiday:{enabled:, time:}, hotwater:{'on':1/0 / 'boost':1/0}
|
||||||
|
console.log("msg.payload="+message.payload);
|
||||||
|
if (message.payload == "undefined" || !message.payload) {
|
||||||
|
message.payload = {read : true};
|
||||||
|
}
|
||||||
if (typeof(message.payload) == "string") {
|
if (typeof(message.payload) == "string") {
|
||||||
message.payload = JSON.parse(message.payload);
|
message.payload = JSON.parse(message.payload);
|
||||||
}
|
}
|
||||||
|
console.log("msg.payload now = "+JSON.stringify(message.payload));
|
||||||
if (message.payload.read) {
|
if (message.payload.read) {
|
||||||
node.hm.read_device();
|
hmnode.read();
|
||||||
}
|
}
|
||||||
else if (message.payload) {
|
else if (message.payload) {
|
||||||
// Compare message.payload data to confirm valid and send to thermostat
|
// Compare message.payload data to confirm valid and send to thermostat
|
||||||
@ -177,7 +184,7 @@ function HeatmiserNode(n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.validateAndWrite(message);
|
hmnode.validateAndWrite(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user