Whilst the Frigate support in this card is the best among camera engines, the name incorrectly suggests that Frigate is a requirement. Instead, to broaden the appeal, change to more camera agnostic name. This does not suggest any change in priority, role or support for Frigate. This change is likely to be bug prone, due to the size of the rename -- the code contains 1500+ references to "Frigate" most of which make sense to rename, some which do not, all of which needed human assessment. - Closes #1298 BREAKING CHANGE: References to `frigate-card` in all kinds of configuration need to be updated to `advanced-camera-card`. An automated config upgrade should take care of the majority of usecases (click `Edit -> Upgrade -> Save`), though may not be perfect.
108 lines
2.7 KiB
TypeScript
108 lines
2.7 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { CardController } from '../../../../src/card-controller/controller';
|
|
import { SubstreamOnViewModifier } from '../../../../src/card-controller/view/modifiers/substream-on';
|
|
import { RawAdvancedCameraCardConfig } from '../../../../src/config/types';
|
|
import {
|
|
getStreamCameraID,
|
|
hasSubstream,
|
|
setSubstream,
|
|
} from '../../../../src/utils/substream';
|
|
import {
|
|
createCameraConfig,
|
|
createCameraManager,
|
|
createCapabilities,
|
|
createCardAPI,
|
|
createConfig,
|
|
createStore,
|
|
createView,
|
|
} from '../../../test-utils';
|
|
|
|
const createAPIWithSubstreams = (
|
|
config?: RawAdvancedCameraCardConfig,
|
|
): CardController => {
|
|
const api = createCardAPI();
|
|
vi.mocked(api.getCameraManager).mockReturnValue(createCameraManager());
|
|
vi.mocked(api.getCameraManager().getStore).mockReturnValue(
|
|
createStore([
|
|
{
|
|
cameraID: 'camera.office',
|
|
capabilities: createCapabilities({
|
|
live: true,
|
|
substream: true,
|
|
}),
|
|
config: createCameraConfig({
|
|
dependencies: {
|
|
all_cameras: true,
|
|
},
|
|
}),
|
|
},
|
|
{
|
|
cameraID: 'camera.kitchen',
|
|
capabilities: createCapabilities({
|
|
substream: true,
|
|
}),
|
|
},
|
|
]),
|
|
);
|
|
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(createConfig(config));
|
|
return api;
|
|
};
|
|
|
|
describe('should turn on substream', () => {
|
|
it('substream available', () => {
|
|
const view = createView({
|
|
view: 'live',
|
|
camera: 'camera.office',
|
|
});
|
|
|
|
expect(hasSubstream(view)).toBe(false);
|
|
|
|
const api = createAPIWithSubstreams();
|
|
|
|
const modifier = new SubstreamOnViewModifier(api);
|
|
modifier.modify(view);
|
|
|
|
expect(hasSubstream(view)).toBe(true);
|
|
expect(getStreamCameraID(view)).toBe('camera.kitchen');
|
|
|
|
modifier.modify(view);
|
|
|
|
expect(hasSubstream(view)).toBe(false);
|
|
expect(getStreamCameraID(view)).toBe('camera.office');
|
|
});
|
|
|
|
it('malformed substream', () => {
|
|
const view = createView({
|
|
view: 'live',
|
|
camera: 'camera.office',
|
|
});
|
|
|
|
const api = createAPIWithSubstreams();
|
|
|
|
setSubstream(view, 'NOT_A_REAL_CAMERA');
|
|
|
|
const modifier = new SubstreamOnViewModifier(api);
|
|
modifier.modify(view);
|
|
|
|
expect(hasSubstream(view)).toBe(false);
|
|
expect(getStreamCameraID(view)).toBe('camera.office');
|
|
});
|
|
|
|
it('substream unavailable', () => {
|
|
const view = createView({
|
|
view: 'live',
|
|
camera: 'camera.office',
|
|
});
|
|
|
|
expect(hasSubstream(view)).toBe(false);
|
|
|
|
const api = createCardAPI();
|
|
vi.mocked(api.getCameraManager).mockReturnValue(createCameraManager());
|
|
|
|
const modifier = new SubstreamOnViewModifier(api);
|
|
modifier.modify(view);
|
|
|
|
expect(hasSubstream(view)).toBe(false);
|
|
});
|
|
});
|