/* eslint-disable @typescript-eslint/no-explicit-any */ import { LitElement, html, customElement, property, TemplateResult, CSSResult, state, unsafeCSS, } from 'lit-element'; import { HomeAssistant, fireEvent, LovelaceCardEditor } from 'custom-card-helpers'; import { FrigateCardConfig } from './types'; import frigate_card_editor_style from './frigate-card-editor.scss'; const options = { required: { icon: 'cog', name: 'Required', secondary: 'Required options for this card to function', show: true, }, optional: { icon: 'tune', name: 'Optional', secondary: 'Optional configuration to tweak card behavior', show: false, }, webrtc: { icon: 'webrtc', name: 'WebRTC', secondary: 'Optional WebRTC parameters', show: false, }, advanced: { icon: 'cogs', name: 'Advanced', secondary: 'Advanced options', show: false, }, }; @customElement('frigate-card-editor') export class FrigateCardEditor extends LitElement implements LovelaceCardEditor { @property({ attribute: false }) public hass?: HomeAssistant; @state() private _config?: FrigateCardConfig; @state() private _toggle?: boolean; @state() private _helpers?: any; private _initialized = false; public setConfig(config: FrigateCardConfig): void { this._config = config; this.loadCardHelpers(); } protected shouldUpdate(): boolean { if (!this._initialized) { this._initialize(); } return true; } protected _getEntities(domain: string): string[] { if (!this.hass) { return []; } const entities = Object.keys(this.hass.states).filter( (eid) => eid.substr(0, eid.indexOf('.')) === domain, ); entities.sort(); // Add a blank entry to unset a selection. entities.unshift(''); return entities; } 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 cameraEntities = this._getEntities('camera'); const binarySensorEntities = this._getEntities('binary_sensor'); const webrtcCameraEntity = this._config?.webrtc && (this._config?.webrtc as any).entity ? (this._config?.webrtc as any).entity : ''; const viewModes = { '': '', live: 'Live view', clips: 'Clip gallery', snapshots: 'Snapshot gallery', clip: 'Latest clip', snapshot: 'Latest snapshot', }; const liveProvider = { '': '', frigate: 'Frigate', webrtc: 'WebRTC', }; return html`