fix: Untriggering to default should reset to default camera (#1571)
This commit is contained in:
@@ -35,27 +35,37 @@ export class ViewFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let forceCameraID: string | null = options?.params?.camera ?? null;
|
// Neither options.baseView.camera nor options.baseView.view are respected
|
||||||
|
// here, since this is the default view / camera.
|
||||||
|
// See: https://github.com/dermotduffy/frigate-hass-card/issues/1564
|
||||||
|
|
||||||
|
let cameraID: string | null = null;
|
||||||
const viewName = options?.params?.view ?? config.view.default;
|
const viewName = options?.params?.view ?? config.view.default;
|
||||||
|
|
||||||
if (
|
if (options?.params?.camera) {
|
||||||
!forceCameraID &&
|
cameraID = options.params.camera;
|
||||||
options?.baseView?.camera &&
|
} else {
|
||||||
config.view.default_cycle_camera
|
|
||||||
) {
|
|
||||||
const cameraIDs = [
|
const cameraIDs = [
|
||||||
...getCameraIDsForViewName(this._api.getCameraManager(), viewName),
|
...getCameraIDsForViewName(this._api.getCameraManager(), viewName),
|
||||||
];
|
];
|
||||||
const currentIndex = cameraIDs.indexOf(options?.baseView?.camera);
|
if (!cameraIDs.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.baseView?.camera && config.view.default_cycle_camera) {
|
||||||
|
const currentIndex = cameraIDs.indexOf(options.baseView.camera);
|
||||||
const targetIndex = currentIndex + 1 >= cameraIDs.length ? 0 : currentIndex + 1;
|
const targetIndex = currentIndex + 1 >= cameraIDs.length ? 0 : currentIndex + 1;
|
||||||
forceCameraID = cameraIDs[targetIndex];
|
cameraID = cameraIDs[targetIndex];
|
||||||
|
} else {
|
||||||
|
cameraID = cameraIDs[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.getViewByParameters({
|
return this.getViewByParameters({
|
||||||
params: {
|
params: {
|
||||||
...options?.params,
|
...options?.params,
|
||||||
view: viewName,
|
view: viewName,
|
||||||
...(forceCameraID && { camera: forceCameraID }),
|
camera: cameraID,
|
||||||
},
|
},
|
||||||
baseView: options?.baseView,
|
baseView: options?.baseView,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,6 +27,33 @@ describe('getViewDefault', () => {
|
|||||||
expect(factory.getViewDefault()).toBeNull();
|
expect(factory.getViewDefault()).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return null if no cameras support view', () => {
|
||||||
|
const api = createCardAPI();
|
||||||
|
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(createConfig());
|
||||||
|
vi.mocked(api.getCameraManager).mockReturnValue(createCameraManager());
|
||||||
|
|
||||||
|
// No cameras support live.
|
||||||
|
vi.mocked(api.getCameraManager().getStore).mockReturnValue(
|
||||||
|
createStore([
|
||||||
|
{
|
||||||
|
cameraID: 'camera.office',
|
||||||
|
capabilities: createCapabilities({
|
||||||
|
live: false,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cameraID: 'camera.kitchen',
|
||||||
|
capabilities: createCapabilities({
|
||||||
|
live: false,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
const factory = new ViewFactory(api);
|
||||||
|
expect(factory.getViewDefault()).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
it('should create view', () => {
|
it('should create view', () => {
|
||||||
const factory = new ViewFactory(createPopulatedAPI());
|
const factory = new ViewFactory(createPopulatedAPI());
|
||||||
const view = factory.getViewDefault();
|
const view = factory.getViewDefault();
|
||||||
@@ -64,17 +91,31 @@ describe('getViewDefault', () => {
|
|||||||
expect(view?.camera).toBe('camera.office');
|
expect(view?.camera).toBe('camera.office');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should respect parameters', () => {
|
it('should use default camera when camera unspecified', () => {
|
||||||
|
// Even though baseView has a camera, since default is called it should
|
||||||
|
// use that camera.
|
||||||
|
|
||||||
const factory = new ViewFactory(createPopulatedAPI());
|
const factory = new ViewFactory(createPopulatedAPI());
|
||||||
|
const baseView = createView({ camera: 'camera.kitchen' });
|
||||||
const view = factory.getViewDefault({
|
const view = factory.getViewDefault({
|
||||||
params: {
|
baseView: baseView,
|
||||||
camera: 'camera.office',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(view?.is('live')).toBeTruthy();
|
expect(view?.is('live')).toBeTruthy();
|
||||||
expect(view?.camera).toBe('camera.office');
|
expect(view?.camera).toBe('camera.office');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should respect parameters', () => {
|
||||||
|
const factory = new ViewFactory(createPopulatedAPI());
|
||||||
|
const view = factory.getViewDefault({
|
||||||
|
params: {
|
||||||
|
camera: 'camera.kitchen',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(view?.is('live')).toBeTruthy();
|
||||||
|
expect(view?.camera).toBe('camera.kitchen');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getViewByParameters', () => {
|
describe('getViewByParameters', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user