import type { PropertyValues } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { customElement, property } from "lit/decorators"; import { keyed } from "lit/directives/keyed"; import { repeat } from "lit/directives/repeat"; import { fireEvent } from "../../common/dom/fire_event"; import { ensureArray } from "../../common/array/ensure-array"; import type { HomeAssistant } from "../../types"; import "./ha-entity-state-picker"; @customElement("ha-entity-states-picker") export class HaEntityStatesPicker extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public entityId?: string; @property() public attribute?: string; @property({ attribute: false }) public extraOptions?: any[]; @property({ type: Boolean, attribute: "allow-custom-value" }) public allowCustomValue; @property() public label?: string; @property({ type: Array }) public value?: string[]; @property() public helper?: string; @property({ type: Boolean }) public disabled = false; @property({ type: Boolean }) public required = false; @property({ attribute: false }) public hideStates?: string[]; private _keys: string[] = []; private _getKey(index: number) { if (!this._keys[index]) { this._keys[index] = Math.random().toString(); } return this._keys[index]; } protected willUpdate(changedProps: PropertyValues): void { super.willUpdate(changedProps); if (changedProps.has("value")) { this.value = ensureArray(this.value); } } protected render() { if (!this.hass) { return nothing; } const value = this.value || []; const hide = [...(this.hideStates || []), ...value]; return html` ${repeat( value, (_state, index) => this._getKey(index), (state, index) => html`