feat: Add out of the box support for Reolink PTZ (#1982)

- Closes: #1964
This commit is contained in:
Dermot Duffy
2025-03-26 21:26:02 -07:00
committed by GitHub
parent f6bb8001e3
commit b5eee5878a
50 changed files with 953 additions and 679 deletions
@@ -7,20 +7,16 @@ import {
} from '../../../src/camera-manager/frigate/media';
import { FrigateEvent, eventSchema } from '../../../src/camera-manager/frigate/types.js';
import { StateWatcher } from '../../../src/card-controller/hass/state-watcher';
import { PTZAction } from '../../../src/config/schema/actions/custom/ptz';
import { CameraConfig } from '../../../src/config/schema/cameras';
import { AdvancedCameraCardView } from '../../../src/config/schema/common/const';
import { RawAdvancedCameraCardConfig } from '../../../src/config/types';
import {
EntityRegistryManager,
createEntityRegistryCache,
} from '../../../src/utils/ha/registry/entity';
import { ViewMedia } from '../../../src/view/media';
import { TestViewMedia, createCameraConfig, createHASS } from '../../test-utils';
import { EntityRegistryManagerMock } from '../../utils/ha/registry/entity/mock';
const createEngine = (): FrigateCameraManagerEngine => {
return new FrigateCameraManagerEngine(
new EntityRegistryManager(createEntityRegistryCache()),
new EntityRegistryManagerMock(),
new StateWatcher(),
new RecordingSegmentsCache(),
new RequestCache(),
@@ -401,101 +397,3 @@ 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',
});
});
});
});
});