Skip to content

Commit

Permalink
Squash state with same value or unknown
Browse files Browse the repository at this point in the history
Duplicates entries could happen on reboot ...

Fix #8
  • Loading branch information
royto committed Nov 7, 2019
1 parent 369c8a8 commit 480ef90
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions logbook-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ class LogbookCard extends Polymer.Element {
return s !== undefined && s.label ? s.label : state;
}

squashSameState(array, val) {
var prev = array[array.length -1];
if (!prev || (prev.state !== val.state && val.state !== 'unknown')) {
array.push(val);
} else {
prev.end = val.end;
}
return array;
}

set hass(hass) {
this._hass = hass;

Expand Down Expand Up @@ -136,6 +146,8 @@ class LogbookCard extends Polymer.Element {
...x,
duration: x.end - x.start
}))
//squash same state or unknown with previous state
.reduce(this.squashSameState, [])
.filter(x => !this._config.hiddenState.includes(x.state));

if (this._config.desc === true) {
Expand Down

0 comments on commit 480ef90

Please sign in to comment.