forked from DigiLive/mushroom-strategy
Fix counting entity states
* Add state filters to getCountTemplate() States `unavailable` and `unknown` are now excluded from the return value of `getCountTemplate()`, since there's no interest in counting those states. This change affect all entities. * Add states to unclosed cover count Aside from state `open`, the cover-chip and -view, will include state `opening` and `closing` to the count of unclosed covers.
This commit is contained in:
@ -218,9 +218,10 @@ class Helper {
|
||||
* Get a template string to define the number of a given domain's entities with a certain state.
|
||||
*
|
||||
* States are compared against a given value by a given operator.
|
||||
* States `unavailable` and `unknown` are always excluded.
|
||||
*
|
||||
* @param {string} domain The domain of the entities.
|
||||
* @param {string} operator The Comparison operator between state and value.
|
||||
* @param {string} operator The comparison operator between state and value.
|
||||
* @param {string} value The value to which the state is compared against.
|
||||
*
|
||||
* @return {string} The template string.
|
||||
@ -265,7 +266,16 @@ class Helper {
|
||||
states.push(...newStates);
|
||||
}
|
||||
|
||||
return `{% set entities = [${states}] %} {{ entities | selectattr('state','${operator}','${value}') | list | count }}`;
|
||||
return (
|
||||
`{% set entities = [${states}] %}
|
||||
{{ entities
|
||||
| selectattr('state','${operator}','${value}')
|
||||
| selectattr('state','ne','unavailable')
|
||||
| selectattr('state','ne','unknown')
|
||||
| list
|
||||
| count
|
||||
}}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,7 @@ class CoverChip extends AbstractChip {
|
||||
type: "template",
|
||||
icon: "mdi:window-open",
|
||||
icon_color: "cyan",
|
||||
content: Helper.getCountTemplate("cover", "eq", "open"),
|
||||
content: Helper.getCountTemplate("cover", "search", "(open|opening|closing)"),
|
||||
tap_action: {
|
||||
action: "none",
|
||||
},
|
||||
|
@ -28,7 +28,8 @@
|
||||
"numbers": "Numbers",
|
||||
"off": "Off",
|
||||
"on": "On",
|
||||
"open": "Open"
|
||||
"open": "Open",
|
||||
"unclosed": "Unclosed"
|
||||
},
|
||||
"input_select": {
|
||||
"input_selects": "Input Selects"
|
||||
|
@ -28,7 +28,8 @@
|
||||
"numbers": "Nummers",
|
||||
"off": "Uit",
|
||||
"on": "Aan",
|
||||
"open": "Open"
|
||||
"open": "Open",
|
||||
"unclosed": "Ongesloten"
|
||||
},
|
||||
"input_select": {
|
||||
"input_selects": "Lijsten"
|
||||
|
@ -51,8 +51,8 @@ class CoverView extends AbstractView {
|
||||
#viewControllerCardConfig: cards.ControllerCardOptions = {
|
||||
title: Helper.customLocalize("cover.all_covers"),
|
||||
subtitle:
|
||||
`${Helper.getCountTemplate(CoverView.#domain, "eq", "open")} ${Helper.customLocalize("cover.covers")} `
|
||||
+ Helper.customLocalize("generic.open"),
|
||||
`${Helper.getCountTemplate(CoverView.#domain, "search", "(open|opening|closing)")} ${Helper.customLocalize("cover.covers")} `
|
||||
+ Helper.customLocalize("generic.unclosed"),
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user