Merge pull request #672 from dermotduffy/timeline-dedup-cameras
Deduplicate Frigate cameras on the timeline (support multiple live providers)
This commit is contained in:
@@ -50,6 +50,8 @@ import { getCameraTitle } from '../utils/camera.js';
|
|||||||
import {
|
import {
|
||||||
getRecordingSegments,
|
getRecordingSegments,
|
||||||
getRecordingsSummary,
|
getRecordingsSummary,
|
||||||
|
getUniqueFrigateCameraEventsID,
|
||||||
|
getUniqueFrigateCameraID,
|
||||||
RecordingSegments,
|
RecordingSegments,
|
||||||
RecordingSummary
|
RecordingSummary
|
||||||
} from '../utils/frigate';
|
} from '../utils/frigate';
|
||||||
@@ -597,9 +599,9 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
|
|
||||||
// There is a single set of recordings for a given Frigate camera name.
|
// There is a single set of recordings for a given Frigate camera name.
|
||||||
// Zones on that same camera do not get separate recordings. The card may
|
// Zones on that same camera do not get separate recordings. The card may
|
||||||
// have multiple instances of the same camera for different zoness, so
|
// have multiple instances of the same camera for different zones, so
|
||||||
// need to enforce uniqueness here.
|
// need to enforce uniqueness here.
|
||||||
const uniqueID = `${config.frigate.client_id}/${config.frigate.camera_name}`;
|
const uniqueID = getUniqueFrigateCameraID(config);
|
||||||
if (processedCameras.has(uniqueID)) {
|
if (processedCameras.has(uniqueID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -886,11 +888,16 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
*/
|
*/
|
||||||
protected _getGroups(): DataGroupCollectionType {
|
protected _getGroups(): DataGroupCollectionType {
|
||||||
const groups: FrigateCardGroupData[] = [];
|
const groups: FrigateCardGroupData[] = [];
|
||||||
|
const processedCameras: Set<string> = new Set();
|
||||||
|
|
||||||
this.cameras?.forEach((cameraConfig, camera) => {
|
this.cameras?.forEach((cameraConfig, camera) => {
|
||||||
|
const frigateCameraID = getUniqueFrigateCameraEventsID(cameraConfig);
|
||||||
if (
|
if (
|
||||||
cameraConfig.frigate.camera_name &&
|
cameraConfig.frigate.camera_name &&
|
||||||
cameraConfig.frigate.camera_name !== CAMERA_BIRDSEYE
|
cameraConfig.frigate.camera_name !== CAMERA_BIRDSEYE &&
|
||||||
|
!processedCameras.has(frigateCameraID)
|
||||||
) {
|
) {
|
||||||
|
processedCameras.add(frigateCameraID);
|
||||||
groups.push({
|
groups.push({
|
||||||
id: camera,
|
id: camera,
|
||||||
content: getCameraTitle(this.hass, cameraConfig),
|
content: getCameraTitle(this.hass, cameraConfig),
|
||||||
|
|||||||
+25
-1
@@ -1,5 +1,5 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { ExtendedHomeAssistant } from '../types';
|
import { CameraConfig, ExtendedHomeAssistant } from '../types';
|
||||||
import { homeAssistantHTTPRequest } from './ha';
|
import { homeAssistantHTTPRequest } from './ha';
|
||||||
|
|
||||||
export const FRIGATE_ICON_SVG_PATH =
|
export const FRIGATE_ICON_SVG_PATH =
|
||||||
@@ -95,3 +95,27 @@ export const getRecordingSegments = async (
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an id that unique identifies a particular camera (not zone, object, etc)
|
||||||
|
* within a particular Frigate instance. ID will not (necessarily) be unique
|
||||||
|
* within the card.
|
||||||
|
* @param cameraConfig The camera config.
|
||||||
|
*/
|
||||||
|
export const getUniqueFrigateCameraID = (config: CameraConfig): string => {
|
||||||
|
return [config.frigate.client_id, config.frigate.camera_name].join('/');
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an id that unique identifies a source of Frigate events. ID will not
|
||||||
|
* (necessarily) be unique within the card.
|
||||||
|
* @param cameraConfig The camera config.
|
||||||
|
*/
|
||||||
|
export const getUniqueFrigateCameraEventsID = (config: CameraConfig): string => {
|
||||||
|
return [
|
||||||
|
config.frigate.client_id,
|
||||||
|
config.frigate.camera_name,
|
||||||
|
config.frigate.label,
|
||||||
|
config.frigate.zone,
|
||||||
|
].join('/');
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user