Fetch latest snapshot if none specified.

This commit is contained in:
Dermot Duffy
2021-08-08 16:26:50 -07:00
parent c4cfe03f64
commit 848a4f6af3
+28 -13
View File
@@ -147,10 +147,12 @@ export class FrigateCard extends LitElement {
this._viewMode = FrigateCardView.CLIPS; this._viewMode = FrigateCardView.CLIPS;
} else if (this.config.view_default == "clip") { } else if (this.config.view_default == "clip") {
this._viewMode = FrigateCardView.CLIP; this._viewMode = FrigateCardView.CLIP;
this._viewEvent = null;
} else if (this.config.view_default == "snapshots") { } else if (this.config.view_default == "snapshots") {
this._viewMode = FrigateCardView.SNAPSHOTS; this._viewMode = FrigateCardView.SNAPSHOTS;
} else if (this.config.view_default == "snapshot") { } else if (this.config.view_default == "snapshot") {
this._viewMode = FrigateCardView.SNAPSHOT; this._viewMode = FrigateCardView.SNAPSHOT;
this._viewEvent = null;
} }
} }
@@ -292,7 +294,9 @@ export class FrigateCard extends LitElement {
protected async _renderClipPlayer(): Promise<TemplateResult> { protected async _renderClipPlayer(): Promise<TemplateResult> {
let event: FrigateEvent; let event: FrigateEvent;
if (!this._viewEvent) { if (this._viewEvent) {
event = this._viewEvent;
} else {
const events = await this._getEvents({ const events = await this._getEvents({
has_clip: true, has_clip: true,
limit: 1 limit: 1
@@ -300,16 +304,12 @@ export class FrigateCard extends LitElement {
if (!events.length) { if (!events.length) {
return html` return html`
<div class="frigate-card-exception"> <div class="frigate-card-exception">
<ha-icon <ha-icon icon="mdi:camera-off">
icon="mdi:camera-off" </ha-icon>
></ha-icon>
</div>` </div>`
} }
event = events[0]; event = events[0];
} else {
event = this._viewEvent;
} }
const url = `${this.config.frigate_url}/clips/` + const url = `${this.config.frigate_url}/clips/` +
`${event.camera}-${event.id}.mp4`; `${event.camera}-${event.id}.mp4`;
return html` return html`
@@ -318,12 +318,25 @@ export class FrigateCard extends LitElement {
</video>` </video>`
} }
protected _renderSnapshotViewer(): TemplateResult { protected async _renderSnapshotViewer(): Promise<TemplateResult> {
if (!this._viewEvent) { let event: FrigateEvent;
return html`` if (this._viewEvent) {
event = this._viewEvent;
} else {
const events = await this._getEvents({
has_snapshot: true,
limit: 1
});
if (!events.length) {
return html`
<div class="frigate-card-exception">
<ha-icon icon="mdi:filmstrip-off">
</ha-icon>
</div>`
} }
const url = `${this.config.frigate_url}/clips/` + event = events[0];
`${this._viewEvent.camera}-${this._viewEvent.id}.jpg`; }
const url = `${this.config.frigate_url}/clips/${event.camera}-${event.id}.jpg`;
return html`<img class="frigate-card-viewer" src="${url}">` return html`<img class="frigate-card-viewer" src="${url}">`
} }
@@ -400,7 +413,9 @@ export class FrigateCard extends LitElement {
</div>` : `` </div>` : ``
} }
${this._viewMode == FrigateCardView.SNAPSHOT ? ${this._viewMode == FrigateCardView.SNAPSHOT ?
this._renderSnapshotViewer() : `` html`<div class="frigate-card-viewer">
${until(this._renderSnapshotViewer(), this._renderProgressIndicator())}
</div>` : ``
} }
${this._renderStatusBar()} ${this._renderStatusBar()}
${this._renderLiveViewer()} ${this._renderLiveViewer()}