Add option to remove duplicates. Fix #26
This commit is contained in:
parent
65490abff1
commit
6d3329b925
@ -33,6 +33,7 @@ filter:
|
||||
- <filter>
|
||||
|
||||
show_empty: <show_empty>
|
||||
unique: <unique>
|
||||
sort: <sort_method>
|
||||
```
|
||||
|
||||
@ -44,6 +45,7 @@ sort: <sort_method>
|
||||
- `include:` **Required.** A list of filters specifying which entities to add to the card
|
||||
- `exclude:` A list of filters specifying which entities to remove from the card
|
||||
- `show_empty:` Whether to display the card if it has no entities. Default: `true`.
|
||||
- `unique:` Whether to remove duplicate values after filtering and sorting. Default: `false`.
|
||||
- `sort:` How to sort the entities of the card. Default: `none`.
|
||||
|
||||
### Filters
|
||||
|
File diff suppressed because one or more lines are too long
15
src/main.js
15
src/main.js
@ -76,6 +76,21 @@ class AutoEntities extends LitElement {
|
||||
entities = entities.sort(entity_sorter(this.hass, this._config.sort));
|
||||
}
|
||||
|
||||
if(this._config.unique) {
|
||||
function compare(a,b) {
|
||||
if(typeof(a) !== typeof(b)) return false;
|
||||
if(typeof(a) !== "object") return a===b;
|
||||
if(Object.keys(a).some((k) => !Object.keys(b).includes(k))) return false;
|
||||
|
||||
return Object.keys(a).every((k) => compare(a[k], b[k]));
|
||||
}
|
||||
let newEntities = [];
|
||||
for(const e of entities) {
|
||||
if(newEntities.some((i) => compare(i,e))) continue;
|
||||
newEntities.push(e);
|
||||
}
|
||||
entities = newEntities;
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user