From b02142287ae68b8093830d004718fda4e237bc0a Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Sat, 28 Dec 2024 18:44:47 +0000 Subject: [PATCH] Support of mqtt notations for node-out: https://github.com/ioBroker/ioBroker.node-red/issues/370 --- admin/jsonConfig.json | 27 +++++++++++++++++++++++++++ nodes/ioBroker.js | 34 ++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index 8b141f2..7cee505 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -13,6 +13,7 @@ "type": "ip", "label": "IP", "listenOnAllPorts": true, + "xs": 12, "sm": 12, "md": 4, "lg": 4 @@ -21,6 +22,7 @@ "type": "number", "min": 1, "max": 65535, + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -29,6 +31,7 @@ "secure": { "newLine": true, "type": "checkbox", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -38,6 +41,7 @@ "hidden": "!data.secure", "type": "certificate", "certType": "public", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -47,6 +51,7 @@ "hidden": "!data.secure", "type": "certificate", "certType": "private", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -55,6 +60,7 @@ "httpAdminRoot": { "newLine": true, "type": "text", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -63,6 +69,7 @@ }, "httpNodeRoot": { "type": "text", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -71,6 +78,7 @@ }, "httpStatic": { "type": "text", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -81,6 +89,7 @@ "newLine": true, "type": "number", "min": 32, + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -88,6 +97,7 @@ }, "npmLibs": { "type": "chips", + "xs": 12, "sm": 12, "md": 8, "lg": 8, @@ -97,6 +107,7 @@ "newLine": true, "type": "header", "size": 3, + "xs": 12, "sm": 12, "md": 12, "lg": 12, @@ -105,6 +116,7 @@ "valueConvert": { "newLine": true, "type": "checkbox", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -113,6 +125,7 @@ "palletmanagerEnabled": { "newLine": true, "type": "checkbox", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -130,6 +143,7 @@ "textAlign": "center", "marginTop": "5px" }, + "xs": 12, "sm": 12, "md": 8, "lg": 8 @@ -137,6 +151,7 @@ "projectsEnabled": { "newLine": true, "type": "checkbox", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -154,6 +169,7 @@ "textAlign": "center", "marginTop": "5px" }, + "xs": 12, "sm": 12, "md": 8, "lg": 8 @@ -161,6 +177,7 @@ "allowCreationOfForeignObjects": { "newLine": true, "type": "checkbox", + "xs": 12, "sm": 12, "md": 6, "lg": 6, @@ -169,6 +186,7 @@ "safeMode": { "newLine": true, "type": "checkbox", + "xs": 12, "sm": 12, "md": 6, "lg": 6, @@ -266,6 +284,7 @@ "value": "Extended" } ], + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -274,6 +293,7 @@ "user": { "hidden": "data.authType !== 'Simple'", "type": "text", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -282,6 +302,7 @@ "pass": { "hidden": "data.authType !== 'Simple'", "type": "password", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -291,6 +312,7 @@ "newLine": true, "hidden": "data.authType !== 'Extended'", "type": "checkbox", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -299,6 +321,7 @@ "defaultPermissions": { "hidden": "data.authType !== 'Extended' || !data.hasDefaultPermissions", "type": "text", + "xs": 12, "sm": 12, "md": 6, "lg": 6, @@ -308,6 +331,7 @@ "newLine": true, "hidden": "data.authType !== 'Extended'", "type": "table", + "xs": 12, "sm": 12, "md": 12, "lg": 12, @@ -397,6 +421,7 @@ "value": "ace" } ], + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -405,6 +430,7 @@ "theme": { "newLine": true, "type": "text", + "xs": 12, "sm": 12, "md": 4, "lg": 4, @@ -422,6 +448,7 @@ "envVars": { "newLine": true, "type": "table", + "xs": 12, "sm": 12, "md": 12, "lg": 12, diff --git a/nodes/ioBroker.js b/nodes/ioBroker.js index ee51a31..dcd186e 100644 --- a/nodes/ioBroker.js +++ b/nodes/ioBroker.js @@ -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; @@ -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*" @@ -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, '.*'); @@ -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; @@ -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; } @@ -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; @@ -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; @@ -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)) { @@ -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(); @@ -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(); @@ -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; @@ -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; @@ -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; @@ -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') {