From 0e13abf62a3735de2cda2ee9e8b27c9321b80de9 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sat, 12 Feb 2022 08:57:00 -0800 Subject: [PATCH] Hide clips/snapshots button for non-Frigate cameras --- README.md | 4 ++-- src/card.ts | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 4e875a1d..89f98caf 100644 --- a/README.md +++ b/README.md @@ -173,8 +173,8 @@ menu: | `frigate` | `true` | :white_check_mark: | Whether to show the `Frigate` menu button: brings the user to the default configured view (`view.default`), or collapses/expands the menu if the `menu.mode` is `hidden-*` . | | `cameras` | `true` | :white_check_mark: | Whether to show the camera selection submenu. Will only appear if multiple cameras are configured. | | `live` | `true` | :white_check_mark: | Whether to show the `live` view menu button: brings the user to the `live` view. See [views](#views) below.| -| `clips` | `true` | :white_check_mark: | Whether to show the `clips` view menu button: brings the user to the `clips` view on tap and the most-recent `clip` view on hold. See [views](#views) below.| -| `snapshots` | `true` | :white_check_mark: | Whether to show the `snapshots` view menu button: brings the user to the `clips` view on tap and the most-recent `snapshot` view on hold. See [views](#views) below.| +| `clips` | `true` | :white_check_mark: | Whether to show the `clips` view menu button: brings the user to the `clips` view on tap and the most-recent `clip` view on hold. See [views](#views) below. This button will never be shown if the `camera_name` for the selected camera is not auto-detected/specified (e.g. non-Frigate cameras).| +| `snapshots` | `true` | :white_check_mark: | Whether to show the `snapshots` view menu button: brings the user to the `clips` view on tap and the most-recent `snapshot` view on hold. See [views](#views) below. This button will never be shown if the `camera_name` for the selected camera is not auto-detected/specified (e.g. non-Frigate cameras).| | `image` | `false` | :white_check_mark: | Whether to show the `image` view menu button: brings the user to the static `image` view. See [views](#views) below.| | `download` | `true` | :white_check_mark: | Whether to show the `download` menu button: allow direct download of the media being displayed.| | `frigate_ui` | `true` | :white_check_mark: | Whether to show the `frigate_ui` menu button: brings the user to a context-appropriate page on the Frigate UI (e.g. the camera homepage). Will only appear if the `frigate.url` option is set.| diff --git a/src/card.ts b/src/card.ts index c6f6fc4d..ec2c2aaa 100644 --- a/src/card.ts +++ b/src/card.ts @@ -313,7 +313,11 @@ export class FrigateCard extends LitElement { }); } - if (this._getConfig().menu.buttons.clips) { + const cameraConfig = this._getSelectedCameraConfig(); + + // Don't show `clips` button if there's no `camera_name` (e.g. non-Frigate + // cameras). + if (this._getConfig().menu.buttons.clips && cameraConfig?.camera_name) { buttons.push({ type: 'custom:frigate-card-menu-icon', title: localize('config.view.views.clips'), @@ -324,7 +328,9 @@ export class FrigateCard extends LitElement { }); } - if (this._getConfig().menu.buttons.snapshots) { + // Don't show `snapshots` button if there's no `camera_name` (e.g. non-Frigate + // cameras). + if (this._getConfig().menu.buttons.snapshots && cameraConfig?.camera_name) { buttons.push({ type: 'custom:frigate-card-menu-icon', title: localize('config.view.views.snapshots'), @@ -358,12 +364,7 @@ export class FrigateCard extends LitElement { }); } - const cameraConfig = this._getSelectedCameraConfig(); - if ( - this._getConfig().menu.buttons.frigate_ui && - cameraConfig && - cameraConfig.frigate_url - ) { + if (this._getConfig().menu.buttons.frigate_ui && cameraConfig?.frigate_url) { buttons.push({ type: 'custom:frigate-card-menu-icon', title: localize('config.menu.buttons.frigate_ui'), @@ -834,9 +835,10 @@ export class FrigateCard extends LitElement { if (this._cameras?.has(camera) && this._view) { this._changeView({ view: new View({ - view: this._getConfig().view.camera_select === 'current' - ? this._view.view - : this._getConfig().view.camera_select as FrigateCardView, + view: + this._getConfig().view.camera_select === 'current' + ? this._view.view + : (this._getConfig().view.camera_select as FrigateCardView), camera: camera, }), });