/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/camelcase */ import { LitElement, html, customElement, property, TemplateResult, CSSResult, css, internalProperty, } from 'lit-element'; import { HomeAssistant, fireEvent, LovelaceCardEditor, ActionConfig } from 'custom-card-helpers'; import { BoilerplateCardConfig } from './types'; const options = { required: { icon: 'tune', name: 'Required', secondary: 'Required options for this card to function', show: true, }, actions: { icon: 'gesture-tap-hold', name: 'Actions', secondary: 'Perform actions based on tapping/clicking', show: false, options: { tap: { icon: 'gesture-tap', name: 'Tap', secondary: 'Set the action to perform on tap', show: false, }, hold: { icon: 'gesture-tap-hold', name: 'Hold', secondary: 'Set the action to perform on hold', show: false, }, double_tap: { icon: 'gesture-double-tap', name: 'Double Tap', secondary: 'Set the action to perform on double tap', show: false, }, }, }, appearance: { icon: 'palette', name: 'Appearance', secondary: 'Customize the name, icon, etc', show: false, }, }; @customElement('boilerplate-card-editor') export class BoilerplateCardEditor extends LitElement implements LovelaceCardEditor { @property({ attribute: false }) public hass?: HomeAssistant; @internalProperty() private _config?: BoilerplateCardConfig; @internalProperty() private _toggle?: boolean; @internalProperty() private _helpers?: any; private _initialized = false; public setConfig(config: BoilerplateCardConfig): void { this._config = config; this.loadCardHelpers(); } protected shouldUpdate(): boolean { if (!this._initialized) { this._initialize(); } return true; } get _name(): string { return this._config?.name || ''; } get _entity(): string { return this._config?.entity || ''; } get _show_warning(): boolean { return this._config?.show_warning || false; } get _show_error(): boolean { return this._config?.show_error || false; } get _tap_action(): ActionConfig { return this._config?.tap_action || { action: 'more-info' }; } get _hold_action(): ActionConfig { return this._config?.hold_action || { action: 'none' }; } get _double_tap_action(): ActionConfig { return this._config?.double_tap_action || { action: 'none' }; } protected render(): TemplateResult | void { if (!this.hass || !this._helpers) { return html``; } // The climate more-info has ha-switch and paper-dropdown-menu elements that are lazy loaded unless explicitly done here this._helpers.importMoreInfoControl('climate'); // You can restrict on domain type const entities = Object.keys(this.hass.states).filter(eid => eid.substr(0, eid.indexOf('.')) === 'sun'); return html`