Add initial keyboard shortcut support.
This commit is contained in:
1 parent
904f6d8142
commit
7ab545738d
186 files changed
+9564
-3658
No files matched your search
@@ -68,17 +68,19 @@ describe('Capabilities', () => {
|
||||
it('when unset', () => {
|
||||
const capabilities = new Capabilities({});
|
||||
expect(capabilities.getPTZCapabilities()).toBeNull();
|
||||
expect(capabilities.hasPTZCapability()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('when set', () => {
|
||||
const ptz: PTZCapabilities = {
|
||||
panTilt: ['continuous' as const],
|
||||
left: ['continuous' as const],
|
||||
presets: ['1', '2'],
|
||||
};
|
||||
const capabilities = new Capabilities({
|
||||
ptz: ptz,
|
||||
});
|
||||
expect(capabilities.getPTZCapabilities()).toBe(ptz);
|
||||
expect(capabilities.hasPTZCapability()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -191,6 +191,7 @@ describe('FrigateCamera', () => {
|
||||
await camera.initialize(createHASS(), mock<EntityRegistryManager>());
|
||||
|
||||
expect(camera.getCapabilities()?.has('ptz')).toBeFalsy();
|
||||
expect(camera.getCapabilities()?.hasPTZCapability()).toBeFalsy();
|
||||
expect(consoleSpy).toBeCalled();
|
||||
});
|
||||
|
||||
@@ -214,10 +215,15 @@ describe('FrigateCamera', () => {
|
||||
|
||||
expect(camera.getCapabilities()?.has('ptz')).toBeTruthy();
|
||||
expect(camera.getCapabilities()?.getPTZCapabilities()).toEqual({
|
||||
panTilt: ['continuous'],
|
||||
zoom: ['continuous'],
|
||||
left: ['continuous'],
|
||||
right: ['continuous'],
|
||||
up: ['continuous'],
|
||||
down: ['continuous'],
|
||||
zoomIn: ['continuous'],
|
||||
zoomOut: ['continuous'],
|
||||
presets: ['preset01'],
|
||||
});
|
||||
expect(camera.getCapabilities()?.hasPTZCapability()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('when getPTZInfo call succeeds with relative motion', async () => {
|
||||
@@ -240,10 +246,15 @@ describe('FrigateCamera', () => {
|
||||
|
||||
expect(camera.getCapabilities()?.has('ptz')).toBeTruthy();
|
||||
expect(camera.getCapabilities()?.getPTZCapabilities()).toEqual({
|
||||
panTilt: ['relative'],
|
||||
zoom: ['relative'],
|
||||
left: [],
|
||||
right: [],
|
||||
up: [],
|
||||
down: [],
|
||||
zoomIn: [],
|
||||
zoomOut: [],
|
||||
presets: ['preset01'],
|
||||
});
|
||||
expect(camera.getCapabilities()?.hasPTZCapability()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
FrigateRecordingViewMedia,
|
||||
} from '../../../src/camera-manager/frigate/media';
|
||||
import { FrigateEvent, eventSchema } from '../../../src/camera-manager/frigate/types.js';
|
||||
import { PTZAction } from '../../../src/config/ptz';
|
||||
import {
|
||||
CameraConfig,
|
||||
FrigateCardView,
|
||||
PTZAction,
|
||||
RawFrigateCardConfig,
|
||||
} from '../../../src/config/types';
|
||||
import { ViewMedia } from '../../../src/view/media';
|
||||
|
||||
@@ -1070,7 +1070,7 @@ describe('CameraManager', async () => {
|
||||
snapshots: true,
|
||||
|
||||
ptz: {
|
||||
panTilt: ['continuous'],
|
||||
left: ['continuous'],
|
||||
},
|
||||
}),
|
||||
},
|
||||
@@ -1102,7 +1102,50 @@ describe('CameraManager', async () => {
|
||||
expect(engine.executePTZAction).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('successfully', async () => {
|
||||
it('without hass', async () => {
|
||||
const api = createCardAPI();
|
||||
const engine = mock<CameraManagerEngine>();
|
||||
const manager = createCameraManager(api, engine);
|
||||
|
||||
const hass = createHASS();
|
||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(hass);
|
||||
expect(await manager.initializeCamerasFromConfig()).toBeTruthy();
|
||||
|
||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(null);
|
||||
manager.executePTZAction('id', 'left');
|
||||
|
||||
expect(engine.executePTZAction).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('successfully from config', async () => {
|
||||
const api = createCardAPI();
|
||||
const engine = mock<CameraManagerEngine>();
|
||||
const hass = createHASS();
|
||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(hass);
|
||||
const action = {
|
||||
action: 'call-service' as const,
|
||||
service: 'service',
|
||||
}
|
||||
const manager = createCameraManager(api, engine, [
|
||||
{
|
||||
config: createCameraConfig({
|
||||
baseCameraConfig,
|
||||
id: 'another',
|
||||
ptz: {
|
||||
actions_left: action,
|
||||
},
|
||||
}),
|
||||
},
|
||||
]);
|
||||
expect(await manager.initializeCamerasFromConfig()).toBeTruthy();
|
||||
|
||||
manager.executePTZAction('another', 'left');
|
||||
|
||||
expect(api.getActionsManager().executeActions).toBeCalledWith(action);
|
||||
expect(engine.executePTZAction).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('successfully from engine', async () => {
|
||||
const api = createCardAPI();
|
||||
const engine = mock<CameraManagerEngine>();
|
||||
const hass = createHASS();
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
getConfiguredPTZAction,
|
||||
getConfiguredPTZMovementType,
|
||||
getPTZCapabilitiesFromCameraConfig,
|
||||
} from '../../../src/camera-manager/utils/ptz';
|
||||
import { createCameraConfig } from '../../test-utils';
|
||||
import { PTZAction } from '../../../src/config/ptz';
|
||||
|
||||
const action = {
|
||||
action: 'call-service' as const,
|
||||
service: 'service',
|
||||
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(
|
||||
expect.objectContaining({
|
||||
[capabilityName]: ['relative'],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('with preset', () => {
|
||||
expect(
|
||||
getPTZCapabilitiesFromCameraConfig(
|
||||
createCameraConfig({
|
||||
ptz: {
|
||||
presets: {
|
||||
window: action,
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
)?.toEqual(
|
||||
expect.objectContaining({
|
||||
presets: ['window'],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user