Files
advanced-camera-card/tests/camera-manager/utils/ptz.test.ts
T
Dermot Duffy fc32727860 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`.
2026-01-19 13:32:50 -08:00

188 lines
4.0 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
getConfiguredPTZAction,
getConfiguredPTZMovementType,
getPTZCapabilitiesFromCameraConfig,
} from '../../../src/camera-manager/utils/ptz';
import { PTZAction } from '../../../src/config/schema/actions/custom/ptz';
import { createCameraConfig } from '../../test-utils';
const action = {
action: 'perform-action' as const,
perform_action: 'action',
data: {
device: '048123',
cmd: 'preset',
preset: 'window',
},
};
describe('getConfiguredPTZAction', () => {
describe('should return preset', () => {
it('with preset', () => {
expect(
getConfiguredPTZAction(
createCameraConfig({
ptz: {
presets: {
window: action,
},
},
}),
'preset',
{
preset: 'window',
},
),
).toEqual(action);
});
it('without preset', () => {
expect(
getConfiguredPTZAction(
createCameraConfig({
ptz: {
presets: {
window: action,
},
},
}),
'preset',
),
).toBeNull();
});
});
describe('should return continuous action', () => {
it('with action', () => {
expect(
getConfiguredPTZAction(
createCameraConfig({
ptz: {
actions_left_start: action,
},
}),
'left',
{
phase: 'start',
},
),
).toEqual(action);
});
it('without action', () => {
expect(
getConfiguredPTZAction(
createCameraConfig({
ptz: {},
}),
'left',
{
phase: 'start',
},
),
).toBeNull();
});
});
});
describe('getConfiguredPTZMovementType', () => {
it('with continuous', () => {
expect(
getConfiguredPTZMovementType(
createCameraConfig({
ptz: {
actions_left_start: action,
actions_left_stop: action,
},
}),
'left',
),
)?.toEqual(['continuous']);
});
it('with relative', () => {
expect(
getConfiguredPTZMovementType(
createCameraConfig({
ptz: {
actions_left: action,
},
}),
'left',
),
)?.toEqual(['relative']);
});
it('with continuous and relative', () => {
expect(
getConfiguredPTZMovementType(
createCameraConfig({
ptz: {
actions_left: action,
actions_left_start: action,
actions_left_stop: action,
},
}),
'left',
),
)?.toEqual(['continuous', 'relative']);
});
it('with no actions', () => {
expect(
getConfiguredPTZMovementType(
createCameraConfig({
ptz: {},
}),
'left',
),
)?.toBeNull();
});
});
describe('getPTZCapabilitiesFromCameraConfig', () => {
it('with nothing', () => {
expect(getPTZCapabilitiesFromCameraConfig(createCameraConfig()))?.toBeNull();
});
describe('with individual actions', () => {
it.each([
['left' as const, 'left'],
['right' as const, 'right'],
['up' as const, 'up'],
['down' as const, 'down'],
['zoom_in' as const, 'zoomIn'],
['zoom_out' as const, 'zoomOut'],
])('%s', async (actionName: PTZAction, capabilityName: string) => {
expect(
getPTZCapabilitiesFromCameraConfig(
createCameraConfig({
ptz: {
['actions_' + actionName]: action,
},
}),
),
)?.toEqual({
[capabilityName]: ['relative'],
});
});
});
it('with preset', () => {
expect(
getPTZCapabilitiesFromCameraConfig(
createCameraConfig({
ptz: {
presets: {
window: action,
},
},
}),
),
)?.toEqual({
presets: ['window'],
});
});
});