import { HomeAssistant } from '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 liveHAStyle from '../../scss/live-ha.scss'; import { CameraConfig, FrigateCardMediaPlayer } from '../../types.js'; import { getStateObjOrDispatchError } from './live.js'; import '../../patches/ha-camera-stream'; import '../../patches/ha-hls-player.js'; import '../../patches/ha-web-rtc-player.ts'; @customElement('frigate-card-live-ha') export class FrigateCardLiveHA extends LitElement implements FrigateCardMediaPlayer { @property({ attribute: false }) public hass?: HomeAssistant; @property({ attribute: false }) public cameraConfig?: CameraConfig; protected _playerRef: Ref = createRef(); public async play(): Promise { return this._playerRef.value?.play(); } public async pause(): Promise { this._playerRef.value?.pause(); } public async mute(): Promise { this._playerRef.value?.mute(); } public async unmute(): Promise { this._playerRef.value?.unmute(); } public isMuted(): boolean { return this._playerRef.value?.isMuted() ?? true; } public async seek(seconds: number): Promise { this._playerRef.value?.seek(seconds); } public async setControls(controls: boolean): Promise { this._playerRef.value?.setControls(controls); } protected render(): TemplateResult | void { if (!this.hass) { return; } const stateObj = getStateObjOrDispatchError(this, this.hass, this.cameraConfig); if (!stateObj) { return; } return html` `; } static get styles(): CSSResultGroup { return unsafeCSS(liveHAStyle); } } declare global { interface HTMLElementTagNameMap { 'frigate-card-live-ha': FrigateCardLiveHA; } }