From ac295327ece06571a13447fb34f685cb5d96b417 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sun, 29 Jan 2023 22:05:09 -0800 Subject: [PATCH] Correctly calculate cameraIDs to display. --- src/components/surround.ts | 17 ++++++++++++++++- src/components/timeline-core.ts | 19 +++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/components/surround.ts b/src/components/surround.ts index 1044c972..9fd63dd3 100644 --- a/src/components/surround.ts +++ b/src/components/surround.ts @@ -21,6 +21,7 @@ import { View } from '../view/view.js'; import { ThumbnailCarouselTap } from './thumbnail-carousel.js'; import './surround-basic.js'; import { changeViewToRecentEventsForCameraAndDependents } from '../utils/media-to-view'; +import { getAllDependentCameras } from '../utils/camera.js'; interface ThumbnailViewContext { // Whether or not to fetch thumbnails. @@ -124,12 +125,25 @@ export class FrigateCardSurround extends LitElement { } } + protected _getCameraIDsForView(): Set | null { + if (!this.view || !this.cameras) { + return null; + } + if (this.view?.is('live')) { + return getAllDependentCameras(this.cameras, this.view.camera); + } + if (this.view.isViewerView()) { + return new Set(this.view.queryResults?.getResults()?.map((media) => media.getCameraID())); + } + return null; + } + /** * Master render method. * @returns A rendered template. */ protected render(): TemplateResult | void { - if (!this.hass || !this.view || !this.thumbnailConfig) { + if (!this.hass || !this.view || !this.thumbnailConfig || !this.cameras) { return; } @@ -191,6 +205,7 @@ export class FrigateCardSurround extends LitElement { .hass=${this.hass} .view=${this.view} .cameras=${this.cameras} + .cameraIDs=${this._getCameraIDsForView() ?? undefined} .mini=${true} .timelineConfig=${this.timelineConfig} .thumbnailDetails=${this.thumbnailConfig?.show_details} diff --git a/src/components/timeline-core.ts b/src/components/timeline-core.ts index fa5dd832..c5f38630 100644 --- a/src/components/timeline-core.ts +++ b/src/components/timeline-core.ts @@ -179,11 +179,16 @@ export class FrigateCardTimelineCore extends LitElement { @property({ attribute: false }) public thumbnailSize?: number; - // Whether or not this is a mini-timeline for a different view (e.g. media - // viewer). + // Whether or not this is a mini-timeline (in mini-mode the component takes a + // supportive role for other views). @property({ attribute: true, type: Boolean, reflect: true }) public mini = false; + // Which cameraIDs to include in the timeline. If not specified, all cameraIDs + // are shown. + @property({ attribute: false }) + public cameraIDs?: Set; + @property({ attribute: false }) public cameraManager?: CameraManager; @@ -282,10 +287,7 @@ export class FrigateCardTimelineCore extends LitElement { * @returns A set of camera ids (may be empty). */ protected _getTimelineCameraIDs(): Set { - if (!this.mini || !this.cameras) { - return this._getAllCameraIDs(); - } - return getAllDependentCameras(this.cameras, this.view?.camera); + return this.cameraIDs ?? this._getAllCameraIDs(); } /** @@ -1068,10 +1070,7 @@ export class FrigateCardTimelineCore extends LitElement { this._refTimeline.value && options && this.timelineConfig && - (changedProperties.has('timelineConfig') || - (this.mini && - changedProperties.has('view') && - this.view?.camera !== changedProperties.get('view').camera)) + (changedProperties.has('timelineConfig') || changedProperties.has('cameraIDs')) ) { if (this._timeline) { this._destroy();