feat: Add support for Frigate reviews / detections [initial PR] (#2315)
- Add support for Frigate reviews / detections. - Add support for GenAI metadata. - Significant internal refactor to more flexible "UnifiedQuery" to allow mixing cameras with simple metadata and review metadata (e.g. a timeline view of a Frigate camera with reviews, and a Reolink camera with simple metadata). - Add support for folder media as camera media. There are a few more PRs to commit prior to this going live, but commiting this for now due to the scale of the change. BREAKING CHANGE: `media_type` and `events_type` are retired under `live`, `viewer` and `timeline` configuration sections, instead media type is associated (once) with the camera under `media`.
This commit is contained in:
@@ -5,6 +5,7 @@ import { Capabilities } from '../../src/camera-manager/capabilities.js';
|
||||
import { CameraManager } from '../../src/camera-manager/manager.js';
|
||||
import { CameraManagerCameraMetadata } from '../../src/camera-manager/types.js';
|
||||
import { FoldersManager } from '../../src/card-controller/folders/manager.js';
|
||||
import { FolderQuery } from '../../src/card-controller/folders/types';
|
||||
import { FullscreenManager } from '../../src/card-controller/fullscreen/fullscreen-manager.js';
|
||||
import { MediaPlayerManager } from '../../src/card-controller/media-player-manager.js';
|
||||
import { MicrophoneManager } from '../../src/card-controller/microphone-manager.js';
|
||||
@@ -18,11 +19,12 @@ import { ViewDisplayMode } from '../../src/config/schema/common/display.js';
|
||||
import { MenuItem } from '../../src/config/schema/elements/custom/menu/types.js';
|
||||
import { AdvancedCameraCardConfig } from '../../src/config/schema/types.js';
|
||||
import { HomeAssistant } from '../../src/ha/types.js';
|
||||
import { QuerySource } from '../../src/query-source';
|
||||
import { MediaPlayerController, PTZMovementType } from '../../src/types.js';
|
||||
import { createGeneralAction, createViewAction } from '../../src/utils/action.js';
|
||||
import { ViewMedia, ViewMediaType } from '../../src/view/item.js';
|
||||
import { QueryResults } from '../../src/view/query-results.js';
|
||||
import { FolderViewQuery } from '../../src/view/query.js';
|
||||
import { UnifiedQuery } from '../../src/view/unified-query.js';
|
||||
import {
|
||||
getCameraIDsForViewName,
|
||||
isViewSupportedByCamera,
|
||||
@@ -559,7 +561,9 @@ describe('MenuButtonController', () => {
|
||||
describe('should have clips menu button', () => {
|
||||
it('when in clips view', () => {
|
||||
const viewManager = mock<ViewManager>();
|
||||
vi.mocked(isViewSupportedByCamera).mockReturnValue(true);
|
||||
vi.mocked(isViewSupportedByCamera).mockImplementation(
|
||||
(view) => view !== 'reviews',
|
||||
);
|
||||
const buttons = calculateButtons(controller, {
|
||||
view: createView({ view: 'clips' }),
|
||||
viewManager: viewManager,
|
||||
@@ -579,7 +583,9 @@ describe('MenuButtonController', () => {
|
||||
|
||||
it('when not in clips view', () => {
|
||||
const viewManager = mock<ViewManager>();
|
||||
vi.mocked(isViewSupportedByCamera).mockReturnValue(true);
|
||||
vi.mocked(isViewSupportedByCamera).mockImplementation(
|
||||
(view) => view !== 'reviews',
|
||||
);
|
||||
const buttons = calculateButtons(controller, {
|
||||
viewManager: viewManager,
|
||||
});
|
||||
@@ -607,12 +613,38 @@ describe('MenuButtonController', () => {
|
||||
expect.arrayContaining([expect.objectContaining({ title: 'Clips gallery' })]),
|
||||
);
|
||||
});
|
||||
|
||||
it('should be hidden when reviews are supported', () => {
|
||||
vi.mocked(isViewSupportedByCamera).mockImplementation(
|
||||
(view) => view === 'clips' || view === 'reviews',
|
||||
);
|
||||
const buttons = calculateButtons(controller);
|
||||
|
||||
expect(buttons).not.toEqual(
|
||||
expect.arrayContaining([expect.objectContaining({ title: 'Clips gallery' })]),
|
||||
);
|
||||
});
|
||||
|
||||
it('should be shown when reviews are supported but button is explicitly enabled', () => {
|
||||
vi.mocked(isViewSupportedByCamera).mockImplementation(
|
||||
(view) => view === 'clips' || view === 'reviews',
|
||||
);
|
||||
const buttons = calculateButtons(controller, {
|
||||
config: createConfig({ menu: { buttons: { clips: { enabled: true } } } }),
|
||||
});
|
||||
|
||||
expect(buttons).toContainEqual(
|
||||
expect.objectContaining({ title: 'Clips gallery', enabled: true }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should have snapshots menu button', () => {
|
||||
it('when in snapshots view', () => {
|
||||
const viewManager = mock<ViewManager>();
|
||||
vi.mocked(isViewSupportedByCamera).mockReturnValue(true);
|
||||
vi.mocked(isViewSupportedByCamera).mockImplementation(
|
||||
(view) => view !== 'reviews',
|
||||
);
|
||||
const buttons = calculateButtons(controller, {
|
||||
view: createView({ view: 'snapshots' }),
|
||||
viewManager: viewManager,
|
||||
@@ -638,7 +670,9 @@ describe('MenuButtonController', () => {
|
||||
|
||||
it('when not in snapshots view', () => {
|
||||
const viewManager = mock<ViewManager>();
|
||||
vi.mocked(isViewSupportedByCamera).mockReturnValue(true);
|
||||
vi.mocked(isViewSupportedByCamera).mockImplementation(
|
||||
(view) => view !== 'reviews',
|
||||
);
|
||||
const buttons = calculateButtons(controller, {
|
||||
viewManager: viewManager,
|
||||
});
|
||||
@@ -674,6 +708,97 @@ describe('MenuButtonController', () => {
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it('should be hidden when reviews are supported', () => {
|
||||
vi.mocked(isViewSupportedByCamera).mockImplementation(
|
||||
(view) => view === 'snapshots' || view === 'reviews',
|
||||
);
|
||||
const buttons = calculateButtons(controller);
|
||||
|
||||
expect(buttons).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ title: 'Snapshots gallery' }),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it('should be shown when reviews are supported but button is explicitly enabled', () => {
|
||||
vi.mocked(isViewSupportedByCamera).mockImplementation(
|
||||
(view) => view === 'snapshots' || view === 'reviews',
|
||||
);
|
||||
const buttons = calculateButtons(controller, {
|
||||
config: createConfig({ menu: { buttons: { snapshots: { enabled: true } } } }),
|
||||
});
|
||||
|
||||
expect(buttons).toContainEqual(
|
||||
expect.objectContaining({ title: 'Snapshots gallery', enabled: true }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should have reviews menu button', () => {
|
||||
it('when in reviews view', () => {
|
||||
const viewManager = mock<ViewManager>();
|
||||
vi.mocked(isViewSupportedByCamera).mockReturnValue(true);
|
||||
const buttons = calculateButtons(controller, {
|
||||
view: createView({ view: 'reviews' }),
|
||||
viewManager: viewManager,
|
||||
});
|
||||
|
||||
expect(buttons).toContainEqual({
|
||||
icon: 'mdi:play-box-multiple',
|
||||
enabled: true,
|
||||
priority: 50,
|
||||
type: 'custom:advanced-camera-card-menu-icon',
|
||||
title: 'Reviews gallery',
|
||||
style: { color: 'var(--advanced-camera-card-menu-button-active-color)' },
|
||||
tap_action: {
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'reviews',
|
||||
},
|
||||
hold_action: {
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'review',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('when not in reviews view', () => {
|
||||
const viewManager = mock<ViewManager>();
|
||||
vi.mocked(isViewSupportedByCamera).mockReturnValue(true);
|
||||
const buttons = calculateButtons(controller, {
|
||||
viewManager: viewManager,
|
||||
});
|
||||
|
||||
expect(buttons).toContainEqual({
|
||||
icon: 'mdi:play-box-multiple',
|
||||
enabled: true,
|
||||
priority: 50,
|
||||
type: 'custom:advanced-camera-card-menu-icon',
|
||||
title: 'Reviews gallery',
|
||||
style: {},
|
||||
tap_action: {
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'reviews',
|
||||
},
|
||||
hold_action: {
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'review',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('when not supported', () => {
|
||||
const viewManager = mock<ViewManager>();
|
||||
vi.mocked(isViewSupportedByCamera).mockReturnValue(false);
|
||||
const buttons = calculateButtons(controller, {
|
||||
viewManager: viewManager,
|
||||
});
|
||||
|
||||
expect(buttons).not.toEqual(
|
||||
expect.arrayContaining([expect.objectContaining({ title: 'Reviews gallery' })]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should have recordings menu button', () => {
|
||||
@@ -1838,11 +1963,16 @@ describe('MenuButtonController', () => {
|
||||
new Map([['folder-0', folder]]).entries(),
|
||||
);
|
||||
|
||||
const folderNode: FolderQuery = {
|
||||
source: QuerySource.Folder,
|
||||
folder: folder,
|
||||
path: [{ ha: { id: 'one' } }],
|
||||
};
|
||||
const buttons = calculateButtons(controller, {
|
||||
foldersManager,
|
||||
view: createView({
|
||||
view: 'folder',
|
||||
query: new FolderViewQuery({ folder, path: [{ ha: { id: 'one' } }] }),
|
||||
query: new UnifiedQuery().addNode(folderNode),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -1869,12 +1999,14 @@ describe('MenuButtonController', () => {
|
||||
]);
|
||||
foldersManager.getFolders.mockReturnValue(folders.entries());
|
||||
|
||||
const selectedFolderNode: FolderQuery = {
|
||||
source: QuerySource.Folder,
|
||||
folder: selectedFolder,
|
||||
path: [{ ha: { id: 'id' } }],
|
||||
};
|
||||
const view = createView({
|
||||
view: 'folder',
|
||||
query: new FolderViewQuery({
|
||||
folder: selectedFolder,
|
||||
path: [{ ha: { id: 'id' } }],
|
||||
}),
|
||||
query: new UnifiedQuery().addNode(selectedFolderNode),
|
||||
});
|
||||
|
||||
const buttons = calculateButtons(controller, {
|
||||
@@ -2123,4 +2255,86 @@ describe('MenuButtonController', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('should have set review button', () => {
|
||||
it('when unreviewed', () => {
|
||||
const selectedItem = new TestViewMedia({
|
||||
mediaType: ViewMediaType.Review,
|
||||
reviewed: false,
|
||||
});
|
||||
|
||||
const queryResults = mock<QueryResults>();
|
||||
queryResults.getSelectedResult.mockReturnValue(selectedItem);
|
||||
|
||||
const view = createView({
|
||||
view: 'media',
|
||||
queryResults: queryResults,
|
||||
});
|
||||
|
||||
const buttons = calculateButtons(controller, { view: view });
|
||||
|
||||
expect(buttons).toContainEqual(
|
||||
expect.objectContaining({
|
||||
icon: 'mdi:check-circle-outline',
|
||||
title: 'Mark as reviewed',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('when already reviewed', () => {
|
||||
const selectedItem = new TestViewMedia({
|
||||
mediaType: ViewMediaType.Review,
|
||||
reviewed: true,
|
||||
});
|
||||
|
||||
const queryResults = mock<QueryResults>();
|
||||
queryResults.getSelectedResult.mockReturnValue(selectedItem);
|
||||
|
||||
const view = createView({
|
||||
view: 'media',
|
||||
queryResults: queryResults,
|
||||
});
|
||||
|
||||
const buttons = calculateButtons(controller, { view: view });
|
||||
|
||||
expect(buttons).toContainEqual(
|
||||
expect.objectContaining({
|
||||
icon: 'mdi:check-circle',
|
||||
title: 'Mark as unreviewed',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('when isReviewed returns null', () => {
|
||||
const selectedItem = new TestViewMedia({
|
||||
mediaType: ViewMediaType.Review,
|
||||
reviewed: null,
|
||||
});
|
||||
|
||||
const queryResults = mock<QueryResults>();
|
||||
queryResults.getSelectedResult.mockReturnValue(selectedItem);
|
||||
|
||||
const view = createView({
|
||||
view: 'media',
|
||||
queryResults: queryResults,
|
||||
});
|
||||
|
||||
const buttons = calculateButtons(controller, { view: view });
|
||||
|
||||
expect(buttons).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
icon: 'mdi:check-circle',
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(buttons).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
icon: 'mdi:check-circle-outline',
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user