Skip to content

Commit

Permalink
Fixed issue with foreign states of version 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Oct 27, 2023
1 parent 5a2bfaa commit 4be7ceb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 `<error ${id}: not found>`;
}
});

if (f?.hideif && f.hideif == replacedText) {
Expand Down

0 comments on commit 4be7ceb

Please sign in to comment.