diff --git a/src/card.ts b/src/card.ts index 6bdc9798..2caa05e2 100644 --- a/src/card.ts +++ b/src/card.ts @@ -1306,10 +1306,11 @@ export class FrigateCard extends LitElement { case 'camera_select': const camera = frigateCardAction.camera; if (this._cameras?.has(camera) && this._view) { - const targetView = + const targetView = View.selectBestViewForUserSpecified( this._getConfig().view.camera_select === 'current' ? this._view.view - : (this._getConfig().view.camera_select as FrigateCardView); + : (this._getConfig().view.camera_select as FrigateCardView), + ); this._changeView({ view: new View({ view: this._cameras?.get(camera)?.frigate.camera_name diff --git a/src/types.ts b/src/types.ts index 6aab3318..728936e1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -53,6 +53,8 @@ const FRIGATE_CARD_VIEWS = [ ] as const; export type FrigateCardView = typeof FRIGATE_CARD_VIEWS[number]; +export type FrigateCardUserSpecifiedView = typeof FRIGATE_CARD_VIEWS_USER_SPECIFIED[number]; +export const FRIGATE_CARD_VIEW_DEFAULT = 'live' as const; const FRIGATE_MENU_STYLES = ['none', 'hidden', 'overlay', 'hover', 'outside'] as const; const FRIGATE_MENU_POSITIONS = ['left', 'right', 'top', 'bottom'] as const; @@ -526,7 +528,7 @@ export type PictureElements = z.infer; * View configuration section. */ const viewConfigDefault = { - default: 'live' as const, + default: FRIGATE_CARD_VIEW_DEFAULT, camera_select: 'current' as const, timeout_seconds: 300, update_seconds: 0, diff --git a/src/view.ts b/src/view.ts index 7759bbcb..8f2ee4bd 100644 --- a/src/view.ts +++ b/src/view.ts @@ -1,4 +1,10 @@ -import type { FrigateBrowseMediaSource, FrigateCardView } from './types.js'; +import { + FrigateBrowseMediaSource, + FrigateCardUserSpecifiedView, + FrigateCardView, + FRIGATE_CARD_VIEWS_USER_SPECIFIED, + FRIGATE_CARD_VIEW_DEFAULT +} from './types.js'; import { dispatchFrigateCardEvent } from './utils/basic.js'; // eslint-disable-next-line @typescript-eslint/no-empty-interface @@ -41,7 +47,20 @@ export class View { * @returns The closest view supported by the non-Frigate camera. */ public static selectBestViewForNonFrigateCameras(view: FrigateCardView) { - return ['timeline', 'image'].includes(view) ? view : 'live'; + return ['timeline', 'image'].includes(view) ? view : FRIGATE_CARD_VIEW_DEFAULT; + } + + /** + * Selects the best view for a user specified view. + * @param view The wanted view. + * @returns The closest view supported that is user changeable. + */ + public static selectBestViewForUserSpecified(view: FrigateCardView) { + return FRIGATE_CARD_VIEWS_USER_SPECIFIED.includes( + view as FrigateCardUserSpecifiedView, + ) + ? view + : FRIGATE_CARD_VIEW_DEFAULT; } /**