Add sorting by last_triggered

This commit is contained in:
Thomas Lovén 2020-01-07 20:54:13 +01:00
parent 4398cb44b1
commit 0a15d4e68e
3 changed files with 13 additions and 4 deletions

View File

@ -163,10 +163,10 @@ sort:
numeric: <numeric>
```
- `method:` **Required** One of `domain`, `entity_id`, `name`, `state`, `attribute`, `last_changed` or `last_updated`
- `method:` **Required** One of `domain`, `entity_id`, `name`, `state`, `attribute`, `last_changed` `last_updated` or `last_triggered`.
- `reverse:` Set to `true` to reverse the order. Default: `false`.
- `ignore_case:` Set to `true` to make the sort case-insensitive. Default: `false`.
- `numeric:` Set to `true` to sort by numeric value. Default: `false` except for `last_changed` and `last_updated` sorting methods.
- `numeric:` Set to `true` to sort by numeric value. Default: `false` except for `last_changed`, `last_updated` and `last_triggered` sorting methods.
- `attribute:` Attribute to sort by if `method: attribute`. Can be an *object attribute* as above (e.g. `attribute: rgb_color:2`)
- `first` and `count` can be used to only display `<count>` entities, starting with the `<first>` (starts with 0).

File diff suppressed because one or more lines are too long

View File

@ -78,6 +78,15 @@ export function entity_sorter(hass, method) {
new Date(entityB.last_changed).getTime(),
new Date(entityA.last_changed).getTime()
);
case "last_triggered":
if(entityA.attributes.last_triggered == null
|| entityB.attributes.last_triggered == null)
return 0;
method.numeric=true;
return compare(
new Date(entityB.attributes.last_triggered).getTime(),
new Date(entityA.attributes.last_triggered).getTime()
);
default:
return 0;
}