Skip to content

Commit

Permalink
Allow dynamic states for icon property in My Data (DIY) - fixes klein…
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Jan 28, 2021
1 parent 9050db9 commit 9551c75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ show();

* (klein0r) Added hide if value for My Data (DIY)
* (klein0r) Remove frames without text from My Data (DIY)
* (klein0r) Allow dynamic states for My Data (DIY) icons

### 1.1.3

Expand Down
4 changes: 2 additions & 2 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
<table class="table-values">
<thead>
<tr>
<th data-name="icon" style="width: 10%" class="translate">icon</th>
<th data-name="text" style="width: 60%" class="translate">text</th>
<th data-name="icon" style="width: 20%" class="translate">icon</th>
<th data-name="text" style="width: 50%" class="translate">text</th>
<th data-name="hideif" style="width: 25%" class="translate">hide if</th>
<th data-buttons="delete" style="width: 5%"></th>
</tr>
Expand Down
23 changes: 20 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,17 @@ class LaMetric extends utils.Adapter {
this.myDataDiyRegex,
(m, id) => {
if (foreignStates.indexOf(id) === -1) {
this.log.debug('My Data (DIY) found dynamic state: ' + id);
this.log.debug('My Data (DIY) found dynamic state in text: ' + id);
foreignStates.push(id);
}
}
);

f.icon.replace(
this.myDataDiyRegex,
(m, id) => {
if (foreignStates.indexOf(id) === -1) {
this.log.debug('My Data (DIY) found dynamic state in icon: ' + id);
foreignStates.push(id);
}
}
Expand Down Expand Up @@ -965,7 +975,7 @@ class LaMetric extends utils.Adapter {
let replacedText = f.text.replace(
this.myDataDiyRegex,
(m, id) => {
this.log.debug('My Data (DIY) replacing {' + id + '} in frame');
this.log.debug('My Data (DIY) replacing {' + id + '} in frame text');

return this.myDataDiyForeignStates.filter(item => { return item.id === id; })[0].val;
}
Expand All @@ -983,7 +993,14 @@ class LaMetric extends utils.Adapter {
};

if (f.icon) {
newObj.icon = f.icon;
newObj.icon = f.icon.replace(
this.myDataDiyRegex,
(m, id) => {
this.log.debug('My Data (DIY) replacing {' + id + '} in frame icon');

return this.myDataDiyForeignStates.filter(item => { return item.id === id; })[0].val;
}
);
}

return newObj;
Expand Down

0 comments on commit 9551c75

Please sign in to comment.