Add exclude attributes support to attribute selector (#13421)

* Add exclude attribute support to attribute selector

* Fix typing

* Fix rebase f-up

* Revert const removal

* Make exclude_attributes readonly and fix some propert mismatches

Co-authored-by: Zack <zackbarett@hey.com>
Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
This commit is contained in:
Franck Nijhof
2022-08-20 20:54:42 +02:00
committed by GitHub
parent 5ecde44243
commit aa2641d5c9
7 changed files with 219 additions and 17 deletions

View File

@@ -15,6 +15,14 @@ class HaEntityAttributePicker extends LitElement {
@property() public entityId?: string;
/**
* List of attributes to be excluded.
* @type {Array}
* @attr exclude-attributes
*/
@property({ type: Array, attribute: "exclude-attributes" })
public excludeAttributes?: string[];
@property({ type: Boolean }) public autofocus = false;
@property({ type: Boolean }) public disabled = false;
@@ -42,10 +50,12 @@ class HaEntityAttributePicker extends LitElement {
if (changedProps.has("_opened") && this._opened) {
const state = this.entityId ? this.hass.states[this.entityId] : undefined;
(this._comboBox as any).items = state
? Object.keys(state.attributes).map((key) => ({
value: key,
label: formatAttributeName(key),
}))
? Object.keys(state.attributes)
.filter((key) => !this.excludeAttributes?.includes(key))
.map((key) => ({
value: key,
label: formatAttributeName(key),
}))
: [];
}
}