Skip to content

Commit

Permalink
Support of mqtt notations for node-out: #370
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Dec 28, 2024
1 parent d47e1ea commit b021422
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
27 changes: 27 additions & 0 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"type": "ip",
"label": "IP",
"listenOnAllPorts": true,
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4
Expand All @@ -21,6 +22,7 @@
"type": "number",
"min": 1,
"max": 65535,
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -29,6 +31,7 @@
"secure": {
"newLine": true,
"type": "checkbox",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -38,6 +41,7 @@
"hidden": "!data.secure",
"type": "certificate",
"certType": "public",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -47,6 +51,7 @@
"hidden": "!data.secure",
"type": "certificate",
"certType": "private",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -55,6 +60,7 @@
"httpAdminRoot": {
"newLine": true,
"type": "text",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -63,6 +69,7 @@
},
"httpNodeRoot": {
"type": "text",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -71,6 +78,7 @@
},
"httpStatic": {
"type": "text",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -81,13 +89,15 @@
"newLine": true,
"type": "number",
"min": 32,
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
"label": "Max. allocated RAM"
},
"npmLibs": {
"type": "chips",
"xs": 12,
"sm": 12,
"md": 8,
"lg": 8,
Expand All @@ -97,6 +107,7 @@
"newLine": true,
"type": "header",
"size": 3,
"xs": 12,
"sm": 12,
"md": 12,
"lg": 12,
Expand All @@ -105,6 +116,7 @@
"valueConvert": {
"newLine": true,
"type": "checkbox",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -113,6 +125,7 @@
"palletmanagerEnabled": {
"newLine": true,
"type": "checkbox",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -130,13 +143,15 @@
"textAlign": "center",
"marginTop": "5px"
},
"xs": 12,
"sm": 12,
"md": 8,
"lg": 8
},
"projectsEnabled": {
"newLine": true,
"type": "checkbox",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -154,13 +169,15 @@
"textAlign": "center",
"marginTop": "5px"
},
"xs": 12,
"sm": 12,
"md": 8,
"lg": 8
},
"allowCreationOfForeignObjects": {
"newLine": true,
"type": "checkbox",
"xs": 12,
"sm": 12,
"md": 6,
"lg": 6,
Expand All @@ -169,6 +186,7 @@
"safeMode": {
"newLine": true,
"type": "checkbox",
"xs": 12,
"sm": 12,
"md": 6,
"lg": 6,
Expand Down Expand Up @@ -266,6 +284,7 @@
"value": "Extended"
}
],
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -274,6 +293,7 @@
"user": {
"hidden": "data.authType !== 'Simple'",
"type": "text",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -282,6 +302,7 @@
"pass": {
"hidden": "data.authType !== 'Simple'",
"type": "password",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -291,6 +312,7 @@
"newLine": true,
"hidden": "data.authType !== 'Extended'",
"type": "checkbox",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -299,6 +321,7 @@
"defaultPermissions": {
"hidden": "data.authType !== 'Extended' || !data.hasDefaultPermissions",
"type": "text",
"xs": 12,
"sm": 12,
"md": 6,
"lg": 6,
Expand All @@ -308,6 +331,7 @@
"newLine": true,
"hidden": "data.authType !== 'Extended'",
"type": "table",
"xs": 12,
"sm": 12,
"md": 12,
"lg": 12,
Expand Down Expand Up @@ -397,6 +421,7 @@
"value": "ace"
}
],
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -405,6 +430,7 @@
"theme": {
"newLine": true,
"type": "text",
"xs": 12,
"sm": 12,
"md": 4,
"lg": 4,
Expand All @@ -422,6 +448,7 @@
"envVars": {
"newLine": true,
"type": "table",
"xs": 12,
"sm": 12,
"md": 12,
"lg": 12,
Expand Down
34 changes: 18 additions & 16 deletions nodes/ioBroker.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function (RED) {
const checkStates = [];
const verifiedObjects = {};
const subscribedIds = {};
const isValidIDRegExp = new RegExp('^[_A-Za-z0-9ÄÖÜäöüа-яА-Я][-_A-Za-z0-9ÄÖÜäöüа-яА-Я]*\\.\\d+\\.');
const isValidIDRegExp = new RegExp('^[_A-Za-z0-9ÄÖÜäöüа-яА-Я][-_A-Za-z0-9ÄÖÜäöüа-яА-Я]+\\.\\d+\\.');
let ready = false;
const log = adapter && adapter.log && adapter.log.warn ? adapter.log.warn : console.log;

Expand Down Expand Up @@ -130,7 +130,7 @@ module.exports = function (RED) {
}

function isForeignState(id) {
return isValidId(id) && !id.startsWith(adapter.namespace + '.');
return isValidId(id) && !id.startsWith(`${adapter.namespace}.`);
}

// name is like system.state, pattern is like "*.state" or "*" or "*system*"
Expand All @@ -142,10 +142,10 @@ module.exports = function (RED) {
return null;
}
if (pattern[pattern.length - 1] !== '*') {
pattern = pattern + '$';
pattern = `${pattern}$`;
}
if (pattern[0] !== '*') {
pattern = '^' + pattern;
pattern = `^${pattern}`;
}
pattern = pattern.replace(/\./g, '\\.');
pattern = pattern.replace(/\*/g, '.*');
Expand Down Expand Up @@ -174,7 +174,7 @@ module.exports = function (RED) {

verifiedObjects[id] = true;
for (const part of idArr) {
idToCheck += '.' + part;
idToCheck += `.${part}`;
//adapter.log.debug(` check "${idToCheck}": ${verifiedObjects[idToCheck]}`);
if (verifiedObjects[idToCheck] === true) {
continue;
Expand Down Expand Up @@ -225,13 +225,13 @@ module.exports = function (RED) {
}

adapter.getObject(id, async (err, obj) => {
if (obj && obj._id && validIdForAutomaticFolderCreation(obj._id) && obj.type === 'folder' && obj.native && obj.native.autocreated === 'by automatic ensure logic') {
if (obj?._id && validIdForAutomaticFolderCreation(obj._id) && obj.type === 'folder' && obj.native && obj.native.autocreated === 'by automatic ensure logic') {
// ignore default created object because we now have a more defined one
obj = null;
}
if (!obj) {
adapter.getForeignObject(id, async (err, obj) => {
if (obj && obj._id && validIdForAutomaticFolderCreation(obj._id) && obj.type === 'folder' && obj.native && obj.native.autocreated === 'by automatic ensure logic') {
if (obj?._id && validIdForAutomaticFolderCreation(obj._id) && obj.type === 'folder' && obj.native && obj.native.autocreated === 'by automatic ensure logic') {
// ignore default created object because we now have a more defined one
obj = null;
}
Expand Down Expand Up @@ -359,7 +359,7 @@ module.exports = function (RED) {

// If no adapter prefix, add own adapter prefix
if (node.topic && !isValidId(node.topic) && !node.topic.startsWith(adapter.namespace)) {
node.topic = adapter.namespace + '.' + node.topic;
node.topic = `${adapter.namespace}.${node.topic}`;
}
node.subscribePattern = node.topic;

Expand Down Expand Up @@ -566,9 +566,12 @@ module.exports = function (RED) {
if (!id) {
id = msg.topic;
}
if (id) {
id = id.replace(/\//g, '.');
}
// if not starts with adapter.instance.
if (id && !isValidId(id) && !id.startsWith(adapter.namespace)) {
id = adapter.namespace + '.' + id;
id = `${adapter.namespace}.${id}`;
}

const msgAck = msg.ack !== undefined ? (msg.ack === 'true' || msg.ack === true) : node.ack;
Expand All @@ -577,7 +580,6 @@ module.exports = function (RED) {
//log('Message for "' + id + '" queued because ioBroker connection not initialized');
nodeSets.push({ node, msg });
} else if (id) {
id = id.replace(/\//g, '.');
// Create variable if not exists
if (node.autoCreate && !node.idChecked) {
if (!id.includes('*') && isValidId(id)) {
Expand Down Expand Up @@ -616,7 +618,7 @@ module.exports = function (RED) {
node.status({
fill: 'green',
shape: 'dot',
text: _id + ': ' + (msg.payload === null || msg.payload === undefined ? '' : msg.payload.toString())
text: `${_id}: ${msg.payload === null || msg.payload === undefined ? '' : msg.payload.toString()}`
});
}
done();
Expand Down Expand Up @@ -653,7 +655,7 @@ module.exports = function (RED) {
node.status({
fill: 'green',
shape: 'dot',
text: _id + ': ' + (msg.payload === null || msg.payload === undefined ? '' : msg.payload.toString())
text: `${_id}: ${msg.payload === null || msg.payload === undefined ? '' : msg.payload.toString()}`
});
}
done();
Expand Down Expand Up @@ -686,7 +688,7 @@ module.exports = function (RED) {

// If no adapter prefix, add own adapter prefix
if (node.topic && !isValidId(node.topic) && !node.topic.startsWith(adapter.namespace)) {
node.topic = adapter.namespace + '.' + node.topic;
node.topic = `${adapter.namespace}.${node.topic}`;
}

node.errOnInvalidState = n.errOnInvalidState;
Expand Down Expand Up @@ -787,7 +789,7 @@ module.exports = function (RED) {

// If no adapter prefix, add own adapter prefix
if (node.topic && !isValidId(node.topic) && !node.topic.startsWith(adapter.namespace)) {
node.topic = adapter.namespace + '.' + node.topic;
node.topic = `${adapter.namespace}.${node.topic}`;
}
node.attrname = n.attrname;

Expand Down Expand Up @@ -856,7 +858,7 @@ module.exports = function (RED) {

// If no adapter prefix, add own adapter prefix
if (node.topic && !isValidId(node.topic) && !node.topic.startsWith(adapter.namespace)) {
node.topic = adapter.namespace + '.' + node.topic;
node.topic = `${adapter.namespace}.${node.topic}`;
}
node.objType = n.objType;
node.regex = n.regex;
Expand Down Expand Up @@ -964,7 +966,7 @@ module.exports = function (RED) {
}
} catch (err) {
/* ignore, we'll return what we get till now */
log('Error while requesting metas: ' + err);
log(`Error while requesting metas: ${err}`);
}
try {
if (!node.objType || node.objType === 'instance') {
Expand Down

0 comments on commit b021422

Please sign in to comment.