diff --git a/README.md b/README.md index 2410daa..42203c9 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ iobroker add lametric Placeholder for the next version (at the beginning of the line): ### **WORK IN PROGRESS** --> +### **WORK IN PROGRESS** + +* (klein0r) Fixed issue with foreign states of version 3.1.0 + ### 3.1.0 (2023-10-25) NodeJS 16.x is required diff --git a/main.js b/main.js index 35948da..9407b41 100644 --- a/main.js +++ b/main.js @@ -1488,14 +1488,14 @@ class LaMetric extends utils.Adapter { // Collect all IDs in texts frames.forEach((f) => { f.text.replace(this.myDataDiyRegex, (m, id) => { - if (foreignStates.includes(id)) { + if (!foreignStates.includes(id)) { this.log.debug(`[mydatadiy] found dynamic state with id "${id}" in text`); foreignStates.push(id); } }); f.icon.replace(this.myDataDiyRegex, (m, id) => { - if (foreignStates.includes(id)) { + if (!foreignStates.includes(id)) { this.log.debug(`[mydatadiy] found dynamic state with id "${id}" in icon`); foreignStates.push(id); } @@ -1559,11 +1559,16 @@ class LaMetric extends utils.Adapter { const newFrames = clonedFrames .map((f) => { let replacedText = f.text.replace(this.myDataDiyRegex, (m, id) => { - const newVal = this.myDataDiyForeignStates.find((item) => item.id === id).val; + const foreignState = this.myDataDiyForeignStates.find((item) => item.id === id); + if (foreignState) { + const newVal = foreignState.val; - this.log.debug(`[mydatadiy] replacing "${id}" in frame text with "${newVal}"`); + this.log.debug(`[mydatadiy] replacing "${id}" in frame text with "${newVal}"`); - return newVal; + return newVal; + } else { + return ``; + } }); if (f?.hideif && f.hideif == replacedText) {