import { HomeAssistant } from '@dermotduffy/custom-card-helpers'; import { CSSResultGroup, html, LitElement, TemplateResult, unsafeCSS } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { createRef, ref, Ref } from 'lit/directives/ref.js'; import { CameraConfig } from '../../../config/types'; import basicBlockStyle from '../../../scss/basic-block.scss'; import { FrigateCardMediaPlayer } from '../../../types.js'; import '../../image-base.js'; @customElement('frigate-card-live-image') export class FrigateCardLiveImage extends LitElement implements FrigateCardMediaPlayer { @property({ attribute: false }) public hass?: HomeAssistant; @property({ attribute: false }) public cameraConfig?: CameraConfig; protected _refImage: Ref = createRef(); public async play(): Promise { await this._refImage.value?.play(); } public async pause(): Promise { await this._refImage.value?.pause(); } public async mute(): Promise { await this._refImage.value?.mute(); } public async unmute(): Promise { await this._refImage.value?.unmute(); } public isMuted(): boolean { return !!this._refImage.value?.isMuted(); } public async seek(seconds: number): Promise { await this._refImage.value?.seek(seconds); } public async setControls(controls?: boolean): Promise { await this._refImage.value?.setControls(controls); } public isPaused(): boolean { return this._refImage.value?.isPaused() ?? true; } public async getScreenshotURL(): Promise { return (await this._refImage.value?.getScreenshotURL()) ?? null; } protected render(): TemplateResult | void { if (!this.hass || !this.cameraConfig) { return; } return html` `; } static get styles(): CSSResultGroup { return unsafeCSS(basicBlockStyle); } } declare global { interface HTMLElementTagNameMap { 'frigate-card-live-image': FrigateCardLiveImage; } }