Skip to content

Commit

Permalink
Merge pull request #95 from htmltiger/htmltiger-patch-1
Browse files Browse the repository at this point in the history
Add rounding in secondary info
  • Loading branch information
htmltiger authored Jul 17, 2023
2 parents 68a02e4 + 1e4ed81 commit 5f8d976
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions numberbox-card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((LitElement) => {

console.info('NUMBERBOX_CARD 4.11');
console.info('NUMBERBOX_CARD 4.12');
const html = LitElement.prototype.html;
const css = LitElement.prototype.css;
class NumberBox extends LitElement {
Expand Down Expand Up @@ -84,11 +84,13 @@ secondaryInfo(){
while(j.length){
let t=j.shift();
if(t[0]=='%'){
let f=NaN;
t=t.substring(1).split(':');
let b=this._hass.states;
for (let d=0; d<t.length; d++){
if(lu.indexOf(t[d])>1){t[d]=t[d].replace('-','_');}
const id = t[d];
if(id[0]=='~'){f=Number(id.substring(1));break;}
if(b.hasOwnProperty(id)){
b=b[id];
if(!d){
Expand All @@ -107,7 +109,7 @@ secondaryInfo(){
}
}
}
ret += (typeof b !== 'object')? b : t;
ret += (typeof b !== 'object')? (isNaN(f)?b:b.toFixed(f)) : t;
}else{
ret += t;
}
Expand Down

0 comments on commit 5f8d976

Please sign in to comment.