From 4deb7bd0c450ec76a9a2148abd9e176259ec2f13 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Tue, 10 May 2022 21:27:28 -0700 Subject: [PATCH] Show message if no timeline cameras. --- src/components/timeline.ts | 17 +++++++++++++++-- src/localize/languages/en.json | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/timeline.ts b/src/components/timeline.ts index 3d8ad9ff..108aa6f7 100644 --- a/src/components/timeline.ts +++ b/src/components/timeline.ts @@ -37,9 +37,11 @@ import { View, ViewContext } from '../view'; import { dispatchErrorMessageEvent, dispatchFrigateCardEvent, + dispatchMessageEvent, getCameraTitle, stopEventFromActivatingCardWideActions, } from '../common.js'; +import { localize } from '../localize/localize'; import timelineCoreStyle from '../scss/timeline-core.scss'; import timelineStyle from '../scss/timeline.scss'; @@ -593,7 +595,7 @@ export class FrigateCardTimelineCore extends LitElement { protected _getGroups(): DataGroupCollectionType { const groups: FrigateCardGroupData[] = []; this.cameras?.forEach((cameraConfig, camera) => { - if (cameraConfig.camera_name !== CAMERA_BIRDSEYE) { + if (cameraConfig.camera_name && cameraConfig.camera_name !== CAMERA_BIRDSEYE) { groups.push({ id: camera, content: getCameraTitle(this.hass, cameraConfig), @@ -882,10 +884,21 @@ export class FrigateCardTimelineCore extends LitElement { if (this._timeline) { this._timeline.setOptions(options); } else { + // Don't show an empty timeline, show a message instead. + const groups = this._getGroups(); + if (!groups.length) { + dispatchMessageEvent( + this, + localize('error.timeline_no_cameras'), + 'mdi:chart-gantt', + ); + return; + } + this._timeline = new Timeline( this._refTimeline.value, this._events.dataset, - this._getGroups(), + groups, options, ); this._timeline.on('select', this._timelineSelectHandler.bind(this)); diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index b9223c0e..3ef5eefc 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -312,6 +312,7 @@ "no_camera_name": "Could not determine a Frigate camera name for camera (or one of its dependents), please specify either 'camera_entity' or 'camera_name'", "download_no_media": "No media to download", "download_no_event_id": "Could not extract Frigate event id from media", - "download_sign_failed": "Could not sign media URL for download" + "download_sign_failed": "Could not sign media URL for download", + "timeline_no_cameras": "No Frigate cameras to show in timeline" } }