Skip to content

Commit

Permalink
Fixed Error when multiple messages over one node (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob-Gliwa authored Jan 10, 2023
1 parent 777dd54 commit e4534c9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions loxone/loxone.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ module.exports = function (RED) {
const wsNode = node._webserviceNodeQueue[i];
const handler = wsNode.handler;
const nodeMsg = wsNode.msg;
if (handler.uri === 'j' + message.control) {
const uri = wsNode.uri;
if (uri === 'j' + message.control) {
let msg = Object.assign(nodeMsg, {
'payload': message.value,
'topic': message.control,
Expand Down Expand Up @@ -252,7 +253,7 @@ module.exports = function (RED) {
handler.send(msg);

//unregister node from queue
node.removeWebserviceNodeFromQueue(handler);
node.removeWebserviceNodeFromQueue(handler, uri);
break;
}
}
Expand Down Expand Up @@ -346,10 +347,11 @@ module.exports = function (RED) {
this._streamAllNodes.push(handler);
};

LoxoneMiniserver.prototype.addWebserviceNodeToQueue = function (handler, msg) {
LoxoneMiniserver.prototype.addWebserviceNodeToQueue = function (handler, msg, uri) {
this._webserviceNodeQueue.push({
'handler': handler,
'msg': msg
'msg': msg,
'uri': uri
});
};

Expand Down Expand Up @@ -401,9 +403,9 @@ module.exports = function (RED) {
});
};

LoxoneMiniserver.prototype.removeWebserviceNodeFromQueue = function (handler) {
LoxoneMiniserver.prototype.removeWebserviceNodeFromQueue = function (handler, uri) {
this._webserviceNodeQueue.forEach(function (node, i, outputNodes) {
if (node.handler === handler) {
if (node.handler === handler && node.uri === uri) {
outputNodes.splice(i, 1);
}
});
Expand Down Expand Up @@ -699,7 +701,7 @@ module.exports = function (RED) {

//add node to the queue for waiting messages and send the URI
if (node.miniserver.connected && node.miniserver.connection) {
node.miniserver.addWebserviceNodeToQueue(node, msg);
node.miniserver.addWebserviceNodeToQueue(node, msg, node.uri);
node.miniserver.connection.send_command(node.uri);
} else {
node.status({
Expand Down

0 comments on commit e4534c9

Please sign in to comment.