Add out-of-the-box Frigate PTZ support.

This commit is contained in:
Dermot Duffy
2023-10-29 14:10:41 -07:00
parent fa43d2e439
commit e12912fa85
74 changed files with 3981 additions and 1514 deletions
@@ -9,6 +9,7 @@ import { FrigateEvent, eventSchema } from '../../../src/camera-manager/frigate/t
import {
CameraConfig,
FrigateCardView,
PTZAction,
RawFrigateCardConfig,
} from '../../../src/config/types';
import { ViewMedia } from '../../../src/view/media';
@@ -392,3 +393,101 @@ describe('getCameraEndpoints', () => {
});
});
});
describe('executePTZAction', () => {
describe('preset', () => {
it('should reject without preset argument', () => {
const hass = createHASS();
const cameraConfig = createCameraConfig({ camera_entity: 'camera.office' });
createEngine().executePTZAction(hass, cameraConfig, 'preset');
expect(hass.callService).not.toBeCalled();
});
it('should succeed', () => {
const hass = createHASS();
const cameraConfig = createCameraConfig({ camera_entity: 'camera.office' });
createEngine().executePTZAction(hass, cameraConfig, 'preset', {
preset: 'preset-foo',
});
expect(hass.callService).toBeCalledWith('frigate', 'ptz', {
entity_id: 'camera.office',
action: 'preset',
argument: 'preset-foo',
});
});
});
describe('zoom', () => {
describe.each([['zoom_in' as const], ['zoom_out' as const]])(
'%s',
(actionName: PTZAction) => {
it('start', () => {
const hass = createHASS();
const cameraConfig = createCameraConfig({ camera_entity: 'camera.office' });
createEngine().executePTZAction(hass, cameraConfig, actionName);
expect(hass.callService).toBeCalledWith('frigate', 'ptz', {
entity_id: 'camera.office',
action: 'zoom',
argument: actionName === 'zoom_in' ? 'in' : 'out',
});
});
it('stop', () => {
const hass = createHASS();
const cameraConfig = createCameraConfig({ camera_entity: 'camera.office' });
createEngine().executePTZAction(hass, cameraConfig, actionName, {
phase: 'stop',
});
expect(hass.callService).toBeCalledWith('frigate', 'ptz', {
entity_id: 'camera.office',
action: 'stop',
});
});
},
);
});
describe('move', () => {
describe.each([
['left' as const],
['right' as const],
['up' as const],
['down' as const],
])('%s', (actionName: PTZAction) => {
it('start', () => {
const hass = createHASS();
const cameraConfig = createCameraConfig({ camera_entity: 'camera.office' });
createEngine().executePTZAction(hass, cameraConfig, actionName);
expect(hass.callService).toBeCalledWith('frigate', 'ptz', {
entity_id: 'camera.office',
action: 'move',
argument: actionName,
});
});
it('stop', () => {
const hass = createHASS();
const cameraConfig = createCameraConfig({ camera_entity: 'camera.office' });
createEngine().executePTZAction(hass, cameraConfig, actionName, {
phase: 'stop',
});
expect(hass.callService).toBeCalledWith('frigate', 'ptz', {
entity_id: 'camera.office',
action: 'stop',
});
});
});
});
});