From 848a4f6af3ccdc5c1d8981786bb0e24c7705459b Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sun, 8 Aug 2021 16:26:50 -0700 Subject: [PATCH] Fetch latest snapshot if none specified. --- src/frigate-card.ts | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/frigate-card.ts b/src/frigate-card.ts index bb8c07a3..97ebab96 100644 --- a/src/frigate-card.ts +++ b/src/frigate-card.ts @@ -147,10 +147,12 @@ export class FrigateCard extends LitElement { this._viewMode = FrigateCardView.CLIPS; } else if (this.config.view_default == "clip") { this._viewMode = FrigateCardView.CLIP; + this._viewEvent = null; } else if (this.config.view_default == "snapshots") { this._viewMode = FrigateCardView.SNAPSHOTS; } else if (this.config.view_default == "snapshot") { this._viewMode = FrigateCardView.SNAPSHOT; + this._viewEvent = null; } } @@ -292,7 +294,9 @@ export class FrigateCard extends LitElement { protected async _renderClipPlayer(): Promise { let event: FrigateEvent; - if (!this._viewEvent) { + if (this._viewEvent) { + event = this._viewEvent; + } else { const events = await this._getEvents({ has_clip: true, limit: 1 @@ -300,16 +304,12 @@ export class FrigateCard extends LitElement { if (!events.length) { return html`
- + +
` } event = events[0]; - } else { - event = this._viewEvent; } - const url = `${this.config.frigate_url}/clips/` + `${event.camera}-${event.id}.mp4`; return html` @@ -318,12 +318,25 @@ export class FrigateCard extends LitElement { ` } - protected _renderSnapshotViewer(): TemplateResult { - if (!this._viewEvent) { - return html`` + protected async _renderSnapshotViewer(): Promise { + let event: FrigateEvent; + if (this._viewEvent) { + event = this._viewEvent; + } else { + const events = await this._getEvents({ + has_snapshot: true, + limit: 1 + }); + if (!events.length) { + return html` +
+ + +
` + } + event = events[0]; } - const url = `${this.config.frigate_url}/clips/` + - `${this._viewEvent.camera}-${this._viewEvent.id}.jpg`; + const url = `${this.config.frigate_url}/clips/${event.camera}-${event.id}.jpg`; return html`` } @@ -400,7 +413,9 @@ export class FrigateCard extends LitElement { ` : `` } ${this._viewMode == FrigateCardView.SNAPSHOT ? - this._renderSnapshotViewer() : `` + html`
+ ${until(this._renderSnapshotViewer(), this._renderProgressIndicator())} +
` : `` } ${this._renderStatusBar()} ${this._renderLiveViewer()}