Move camera name and icon into camera manager.

This commit is contained in:
Dermot Duffy
2023-01-29 18:30:07 -08:00
parent eed436d77f
commit 0df6faaf7d
15 changed files with 165 additions and 110 deletions
+1
View File
@@ -33,6 +33,7 @@ export function dispatchFrigateCardEvent<T>(
* @returns A prettified name.
*/
export function prettifyTitle(input: string): string;
export function prettifyTitle(input?: string): string | undefined;
export function prettifyTitle(input?: string): string | undefined {
if (!input) {
return undefined;
-50
View File
@@ -1,7 +1,4 @@
import { HomeAssistant } from 'custom-card-helpers';
import { CameraConfig, RawFrigateCardConfig } from '../types.js';
import { prettifyTitle } from './basic.js';
import { getEntityIcon, getEntityTitle } from './ha';
/**
* Get a camera id.
@@ -26,53 +23,6 @@ export function getCameraID(
);
}
/**
* Get a camera text title.
* @param hass The Home Assistant object.
* @param config The camera config (either parsed or raw).
* @returns A title string.
*/
export function getCameraTitle(
hass?: HomeAssistant,
config?: CameraConfig | RawFrigateCardConfig | null,
): string {
// Attempt to render a recognizable name for the camera,
// starting with the most likely to be useful and working our
// ways towards the least useful. Extra type checking here since this is also
// used on raw configuration in the editor.
return (
(typeof config?.title === 'string' && config.title) ||
(typeof config?.camera_entity === 'string'
? getEntityTitle(hass, config.camera_entity)
: '') ||
(typeof config?.webrtc_card === 'object' &&
config.webrtc_card &&
typeof config.webrtc_card['entity'] === 'string' &&
config.webrtc_card['entity']) ||
(typeof config?.frigate === 'object' &&
config.frigate &&
typeof config?.frigate['camera_name'] === 'string' &&
config.frigate['camera_name']
? prettifyTitle(config.frigate['camera_name'])
: '') ||
(typeof config?.id === 'string' && config.id) ||
''
);
}
/**
* Get a camera icon.
* @param hass The Home Assistant object.
* @param config The camera config.
* @returns An icon string.
*/
export function getCameraIcon(
hass?: HomeAssistant,
config?: CameraConfig | null,
): string {
return config?.icon || getEntityIcon(hass, config?.camera_entity) || 'mdi:video';
}
/**
* Get all cameras that depend on a given camera.
* @param cameras Cameras map.
+3 -4
View File
@@ -5,7 +5,6 @@ import { dispatchErrorMessageEvent } from '../../components/message.js';
import { localize } from '../../localize/localize.js';
import {
BrowseMediaQueryParameters,
BrowseRecordingQueryParameters,
CameraConfig,
ClipsOrSnapshots,
FrigateBrowseMediaSource,
@@ -15,7 +14,7 @@ import {
MEDIA_TYPE_PLAYLIST,
MEDIA_TYPE_VIDEO,
} from '../../types.js';
import { getAllDependentCameras, getCameraTitle } from '../camera.js';
import { getAllDependentCameras } from '../camera.js';
/**
* Return the Frigate event_id given a FrigateBrowseMediaSource object.
@@ -189,7 +188,7 @@ export const mergeFrigateBrowseMediaSources = async (
* @returns A BrowseMediaQueryParameters object.
*/
export const getBrowseMediaQueryParameters = (
hass: HomeAssistant,
_hass: HomeAssistant,
cameraID: string,
cameraConfig?: CameraConfig,
overrides?: Partial<BrowseMediaQueryParameters>,
@@ -202,7 +201,7 @@ export const getBrowseMediaQueryParameters = (
cameraName: cameraConfig.frigate.camera_name,
label: cameraConfig.frigate.label,
zone: cameraConfig.frigate.zone,
title: getCameraTitle(hass, cameraConfig),
title: '', // TODO: Replace: getCameraTitle(hass, cameraConfig),
cameraID: cameraID,
...overrides,
};