Add support for configuration profiles.
This commit is contained in:
@@ -78,7 +78,7 @@ describe('ConfigManager', () => {
|
||||
|
||||
manager.setConfig(config);
|
||||
|
||||
expect(manager.hasConfig()).toBeTruthy()
|
||||
expect(manager.hasConfig()).toBeTruthy();
|
||||
expect(manager.getRawConfig()).toBe(config);
|
||||
|
||||
// Verify at least the camera is set.
|
||||
@@ -102,12 +102,12 @@ describe('ConfigManager', () => {
|
||||
expect(api.getCardElementManager().update).toBeCalled();
|
||||
});
|
||||
|
||||
it('should apply low performance defaults', () => {
|
||||
it('should apply profiles', () => {
|
||||
const manager = new ConfigManager(createCardAPI());
|
||||
const config = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
performance: { profile: 'low' },
|
||||
profiles: ['low-performance'],
|
||||
};
|
||||
|
||||
manager.setConfig(config);
|
||||
@@ -143,7 +143,9 @@ describe('ConfigManager', () => {
|
||||
logging: true,
|
||||
},
|
||||
performance: {
|
||||
profile: 'low',
|
||||
style: {
|
||||
box_shadow: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -155,12 +157,11 @@ describe('ConfigManager', () => {
|
||||
},
|
||||
performance: {
|
||||
features: {
|
||||
animated_progress_indicator: false,
|
||||
media_chunk_size: 10,
|
||||
animated_progress_indicator: true,
|
||||
media_chunk_size: 50,
|
||||
},
|
||||
profile: 'low',
|
||||
style: {
|
||||
border_radius: false,
|
||||
border_radius: true,
|
||||
box_shadow: false,
|
||||
},
|
||||
},
|
||||
@@ -257,8 +258,8 @@ describe('ConfigManager', () => {
|
||||
const config_2 = {
|
||||
...config_1,
|
||||
cameras_global: {
|
||||
live_provider: 'jsmpeg'
|
||||
}
|
||||
live_provider: 'jsmpeg',
|
||||
},
|
||||
};
|
||||
vi.mocked(getOverriddenConfig).mockReturnValue(createConfig(config_2));
|
||||
manager.computeOverrideConfig();
|
||||
@@ -276,9 +277,9 @@ describe('ConfigManager', () => {
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
live: {
|
||||
microphone: {
|
||||
always_connected: false
|
||||
}
|
||||
}
|
||||
always_connected: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
vi.mocked(getOverriddenConfig).mockReturnValue(createConfig(config_1));
|
||||
|
||||
@@ -289,9 +290,9 @@ describe('ConfigManager', () => {
|
||||
...config_1,
|
||||
live: {
|
||||
microphone: {
|
||||
always_connected: true
|
||||
}
|
||||
}
|
||||
always_connected: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
vi.mocked(getOverriddenConfig).mockReturnValue(createConfig(config_2));
|
||||
manager.computeOverrideConfig();
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { FrigateCardView } from '../../src/config/types';
|
||||
import { setPerformanceCSSStyles } from '../../src/performance';
|
||||
import { StyleManager } from '../../src/card-controller/style-manager';
|
||||
import { createCardAPI, createConfig, createHASS, createView } from '../test-utils';
|
||||
|
||||
vi.mock('../../src/performance');
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('StyleManager', () => {
|
||||
beforeEach(() => {
|
||||
@@ -226,19 +223,49 @@ describe('StyleManager', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('setPerformance', () => {
|
||||
const api = createCardAPI();
|
||||
const element = document.createElement('div');
|
||||
vi.mocked(api.getCardElementManager().getElement).mockReturnValue(element);
|
||||
const config = createConfig();
|
||||
vi.mocked(api.getConfigManager().getCardWideConfig).mockReturnValue({
|
||||
performance: config.performance,
|
||||
describe('setPerformance', () => {
|
||||
it('no styles set', () => {
|
||||
const api = createCardAPI();
|
||||
const element = document.createElement('div');
|
||||
vi.mocked(api.getCardElementManager().getElement).mockReturnValue(element);
|
||||
vi.mocked(api.getConfigManager().getCardWideConfig).mockReturnValue({});
|
||||
const manager = new StyleManager(api);
|
||||
|
||||
manager.setPerformance();
|
||||
|
||||
expect(
|
||||
element.style.getPropertyValue('--frigate-card-css-box-shadow'),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
element.style.getPropertyValue('--frigate-card-css-border-radius'),
|
||||
).toBeFalsy();
|
||||
});
|
||||
const manager = new StyleManager(api);
|
||||
|
||||
manager.setPerformance();
|
||||
it('valid styles set', () => {
|
||||
const api = createCardAPI();
|
||||
const element = document.createElement('div');
|
||||
vi.mocked(api.getCardElementManager().getElement).mockReturnValue(element);
|
||||
vi.mocked(api.getConfigManager().getCardWideConfig).mockReturnValue(
|
||||
createConfig({
|
||||
performance: {
|
||||
style: {
|
||||
box_shadow: false,
|
||||
border_radius: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
const manager = new StyleManager(api);
|
||||
|
||||
expect(setPerformanceCSSStyles).toBeCalledWith(element, config.performance);
|
||||
manager.setPerformance();
|
||||
|
||||
expect(element.style.getPropertyValue('--frigate-card-css-box-shadow')).toEqual(
|
||||
'none',
|
||||
);
|
||||
expect(
|
||||
element.style.getPropertyValue('--frigate-card-css-border-radius'),
|
||||
).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAspectRatioStyle', () => {
|
||||
|
||||
@@ -16,8 +16,8 @@ import {
|
||||
upgradeMoveToWithOverrides,
|
||||
upgradeObjectRecursively,
|
||||
upgradeWithOverrides,
|
||||
} from '../src/config-mgmt';
|
||||
import { RawFrigateCardConfig } from '../src/config/types';
|
||||
} from '../../src/config/management';
|
||||
import { RawFrigateCardConfig } from '../../src/config/types';
|
||||
|
||||
describe('general functions', () => {
|
||||
it('should set value', () => {
|
||||
@@ -2459,6 +2459,43 @@ describe('should handle version specific upgrades', () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('from performance profile to generic profile', () => {
|
||||
it('low performance', () => {
|
||||
const config = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [],
|
||||
performance: {
|
||||
profile: 'low',
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config).toEqual({
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [],
|
||||
profiles: ['low-performance'],
|
||||
performance: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('high performance', () => {
|
||||
const config = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [],
|
||||
performance: {
|
||||
profile: 'high',
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config).toEqual({
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [],
|
||||
performance: {},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { ProfileType } from '../../../src/config/types';
|
||||
import { setProfiles } from '../../../src/config/profiles';
|
||||
import { createConfig } from '../../test-utils';
|
||||
|
||||
describe('setProfiles', () => {
|
||||
it('should handle failed parse', () => {
|
||||
expect(setProfiles({ cameras: 'not_an_array' }, {})).toEqual({});
|
||||
});
|
||||
|
||||
it('should handle no profiles', () => {
|
||||
const input = createConfig();
|
||||
const output = createConfig();
|
||||
|
||||
expect(setProfiles(input, output)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should handle invalid profiles', () => {
|
||||
const input = createConfig();
|
||||
const output = createConfig();
|
||||
|
||||
expect(setProfiles(input, output, ['bogus' as ProfileType])).toEqual(input);
|
||||
});
|
||||
|
||||
it('should handle profiles', () => {
|
||||
const input = {
|
||||
type: 'frigate-hass-card',
|
||||
cameras: [],
|
||||
live: {
|
||||
controls: {
|
||||
timeline: {
|
||||
// This will not be overridden.
|
||||
style: 'stack',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(setProfiles(input, {}, ['scrubbing'])).toEqual({
|
||||
live: {
|
||||
controls: {
|
||||
timeline: {
|
||||
mode: 'below',
|
||||
pan_mode: 'seek',
|
||||
},
|
||||
},
|
||||
},
|
||||
media_viewer: {
|
||||
controls: {
|
||||
timeline: {
|
||||
mode: 'below',
|
||||
style: 'ribbon',
|
||||
pan_mode: 'seek',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import { expect, it } from 'vitest';
|
||||
import { LOW_PERFORMANCE_PROFILE } from '../../../src/config/profiles/low-performance';
|
||||
|
||||
it('low performance profile', () => {
|
||||
expect(LOW_PERFORMANCE_PROFILE).toEqual({
|
||||
'cameras_global.image.refresh_seconds': 10,
|
||||
'cameras_global.live_provider': 'image',
|
||||
'cameras_global.triggers.occupancy': false,
|
||||
'live.auto_mute': 'never',
|
||||
'live.controls.thumbnails.mode': 'none',
|
||||
'live.controls.thumbnails.show_details': false,
|
||||
'live.controls.thumbnails.show_download_control': false,
|
||||
'live.controls.thumbnails.show_favorite_control': false,
|
||||
'live.controls.thumbnails.show_timeline_control': false,
|
||||
'live.controls.timeline.show_recordings': false,
|
||||
'live.controls.title.mode': 'none',
|
||||
'live.draggable': false,
|
||||
'live.lazy_unload': 'all',
|
||||
'live.show_image_during_load': false,
|
||||
'live.transition_effect': 'none',
|
||||
'media_gallery.controls.thumbnails.show_details': false,
|
||||
'media_gallery.controls.thumbnails.show_download_control': false,
|
||||
'media_gallery.controls.thumbnails.show_favorite_control': false,
|
||||
'media_gallery.controls.thumbnails.show_timeline_control': false,
|
||||
'media_viewer.auto_mute': 'never',
|
||||
'media_viewer.auto_pause': 'never',
|
||||
'media_viewer.auto_play': 'never',
|
||||
'media_viewer.controls.next_previous.style': 'chevrons',
|
||||
'media_viewer.controls.thumbnails.mode': 'none',
|
||||
'media_viewer.controls.thumbnails.show_details': false,
|
||||
'media_viewer.controls.thumbnails.show_download_control': false,
|
||||
'media_viewer.controls.thumbnails.show_favorite_control': false,
|
||||
'media_viewer.controls.thumbnails.show_timeline_control': false,
|
||||
'media_viewer.controls.timeline.show_recordings': false,
|
||||
'media_viewer.controls.title.mode': 'none',
|
||||
'media_viewer.draggable': false,
|
||||
'media_viewer.snapshot_click_plays_clip': false,
|
||||
'media_viewer.transition_effect': 'none',
|
||||
'menu.buttons.frigate.enabled': false,
|
||||
'menu.buttons.media_player.enabled': false,
|
||||
'menu.buttons.timeline.enabled': false,
|
||||
'menu.style': 'outside',
|
||||
'performance.features.animated_progress_indicator': false,
|
||||
'performance.features.media_chunk_size': 10,
|
||||
'performance.style.border_radius': false,
|
||||
'performance.style.box_shadow': false,
|
||||
'timeline.controls.thumbnails.mode': 'none',
|
||||
'timeline.controls.thumbnails.show_details': false,
|
||||
'timeline.controls.thumbnails.show_download_control': false,
|
||||
'timeline.controls.thumbnails.show_favorite_control': false,
|
||||
'timeline.controls.thumbnails.show_timeline_control': false,
|
||||
'timeline.show_recordings': false,
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import { expect, it } from 'vitest';
|
||||
import { SCRUBBING_PROFILE } from '../../../src/config/profiles/scrubbing';
|
||||
|
||||
it('scrubbing profile', () => {
|
||||
expect(SCRUBBING_PROFILE).toEqual({
|
||||
'live.controls.timeline.mode': 'below',
|
||||
'live.controls.timeline.style': 'ribbon',
|
||||
'live.controls.timeline.pan_mode': 'seek',
|
||||
'media_viewer.controls.timeline.mode': 'below',
|
||||
'media_viewer.controls.timeline.style': 'ribbon',
|
||||
'media_viewer.controls.timeline.pan_mode': 'seek',
|
||||
});
|
||||
});
|
||||
@@ -253,7 +253,6 @@ describe('config defaults', () => {
|
||||
animated_progress_indicator: true,
|
||||
media_chunk_size: 50,
|
||||
},
|
||||
profile: 'high',
|
||||
style: {
|
||||
border_radius: true,
|
||||
box_shadow: true,
|
||||
|
||||
Reference in New Issue
Block a user