Skip to content

Commit

Permalink
Merge pull request #16 from SNoof85/test-for-max
Browse files Browse the repository at this point in the history
4th value in severity
  • Loading branch information
SNoof85 authored Jan 22, 2021
2 parents f8663ce + c2433f0 commit 33404a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ Add it as a custom card to your lovelace : `'custom:tempometer-gauge-card'`.
| green ***(required)*** | number | Value for the color green.
| yellow ***(required)*** | number | Value for the color yellow.
| red ***(required)*** | number | Value for the color red.
| max | number | Maximum value of the last step, normal color will be rendered above

Example:
```yaml
severity:
green: 1020
yellow: 1000
red: 900
max: 1100
```
## Tip
Expand Down Expand Up @@ -94,6 +96,7 @@ severity:
green: 1000
yellow: 2000
red: 3000
max: 5000
```
Maybe more to come ! PR are welcome and i can have a look to features requests.
15 changes: 12 additions & 3 deletions tempometer-gauge-card.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
console.info(`%c TEMPOMETER-CARD \n%c v0.7 `, 'color: orange; font-weight: bold; background: black', 'color: white; font-weight: bold; background: dimgray');
class TempometerGaugeCard extends HTMLElement {
constructor() {
super();
Expand Down Expand Up @@ -295,15 +296,23 @@ class TempometerGaugeCard extends HTMLElement {
sortable.push([severity, sections[severity]]);
}
sortable.sort((a, b) => { return a[1] - b[1] });

if (numberValue >= sortable[0][1] && numberValue < sortable[1][1]) {
return severityMap[sortable[0][0]];
}
if (numberValue >= sortable[1][1] && numberValue < sortable[2][1]) {
return severityMap[sortable[1][0]];
}
if (numberValue >= sortable[2][1]) {
return severityMap[sortable[2][0]];
if (sortable.length === 4) {
if (numberValue >= sortable[2][1] && numberValue < sortable[3][1]) {
return severityMap[sortable[2][0]];
}
if (numberValue > sortable[3][1]) {
return severityMap["normal"]
}
} else {
if (numberValue >= sortable[2][1]) {
return severityMap[sortable[2][0]];
}
}
return severityMap["normal"];
}
Expand Down

0 comments on commit 33404a6

Please sign in to comment.