fix: Unparseable config when using the low-performance profile (#1570)
* The `low-performance` profile itself had parse errors: fix them! * Do not silently swallow override parse errors, they are always a user issue * Minor error message rendering improvements to show multiple pieces of context
This commit is contained in:
@@ -347,7 +347,7 @@ describe('getOverriddenConfig', () => {
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
manager.setState({ fullscreen: true });
|
||||
|
||||
expect(
|
||||
expect(() =>
|
||||
getOverriddenConfig(manager, config, {
|
||||
configOverrides: [
|
||||
{
|
||||
@@ -364,40 +364,7 @@ describe('getOverriddenConfig', () => {
|
||||
],
|
||||
schema: testSchema,
|
||||
}),
|
||||
).toEqual(config);
|
||||
});
|
||||
|
||||
it('failing and logging', () => {
|
||||
const consoleSpy = vi.spyOn(global.console, 'warn').mockReturnValue(undefined);
|
||||
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
manager.setState({ fullscreen: true });
|
||||
|
||||
expect(
|
||||
getOverriddenConfig(manager, config, {
|
||||
configOverrides: [
|
||||
{
|
||||
conditions: [
|
||||
{
|
||||
condition: 'fullscreen' as const,
|
||||
fullscreen: true,
|
||||
},
|
||||
],
|
||||
set: {
|
||||
'menu.style': 'NOT_A_STYLE',
|
||||
},
|
||||
},
|
||||
],
|
||||
schema: testSchema,
|
||||
logOnParseError: true,
|
||||
}),
|
||||
).toEqual(config);
|
||||
|
||||
expect(consoleSpy).toBeCalledWith(
|
||||
'Cannot parse overridden configuration',
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
);
|
||||
).toThrowError(/Invalid override configuration/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -218,6 +218,24 @@ describe('ConfigManager', () => {
|
||||
expect(manager.getConfig()).not.toEqual(manager.getNonOverriddenConfig());
|
||||
});
|
||||
|
||||
it('should set error on invalid override', () => {
|
||||
const api = createCardAPI();
|
||||
const manager = new ConfigManager(api);
|
||||
manager.setConfig({
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
});
|
||||
|
||||
const error = new Error('Invalid override configuration');
|
||||
vi.mocked(getOverriddenConfig).mockImplementation(() => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
manager.computeOverrideConfig();
|
||||
|
||||
expect(api.getMessageManager().setErrorIfHigherPriority).toBeCalledWith(error);
|
||||
});
|
||||
|
||||
describe('should uninitialize on override', () => {
|
||||
it('cameras', () => {
|
||||
const api = createCardAPI();
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { expect, it } from 'vitest';
|
||||
import { setProfiles } from '../../../src/config/profiles';
|
||||
import { LOW_PERFORMANCE_PROFILE } from '../../../src/config/profiles/low-performance';
|
||||
import { frigateCardConfigSchema } from '../../../src/config/types';
|
||||
import { createRawConfig } from '../../test-utils';
|
||||
|
||||
it('low performance profile', () => {
|
||||
it('should contain expected defaults', () => {
|
||||
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.auto_mute': [],
|
||||
'live.controls.thumbnails.mode': 'none',
|
||||
'live.controls.thumbnails.show_details': false,
|
||||
'live.controls.thumbnails.show_download_control': false,
|
||||
@@ -14,16 +17,16 @@ it('low performance profile', () => {
|
||||
'live.controls.thumbnails.show_timeline_control': false,
|
||||
'live.controls.timeline.show_recordings': false,
|
||||
'live.draggable': false,
|
||||
'live.lazy_unload': 'all',
|
||||
'live.lazy_unload': ['unselected', 'hidden'],
|
||||
'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.auto_mute': [],
|
||||
'media_viewer.auto_pause': [],
|
||||
'media_viewer.auto_play': [],
|
||||
'media_viewer.controls.next_previous.style': 'chevrons',
|
||||
'media_viewer.controls.thumbnails.mode': 'none',
|
||||
'media_viewer.controls.thumbnails.show_details': false,
|
||||
@@ -53,3 +56,14 @@ it('low performance profile', () => {
|
||||
'view.triggers.actions.trigger': 'none',
|
||||
});
|
||||
});
|
||||
|
||||
it('should be parseable after application', () => {
|
||||
const rawInputConfig = createRawConfig();
|
||||
const parsedConfig = frigateCardConfigSchema.parse(rawInputConfig);
|
||||
|
||||
setProfiles(rawInputConfig, parsedConfig, ['low-performance']);
|
||||
|
||||
// Reparse the config to ensure the profile did not introduce errors.
|
||||
const parseResult = frigateCardConfigSchema.safeParse(parsedConfig);
|
||||
expect(parseResult.success, parseResult.error?.toString()).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { expect, it } from 'vitest';
|
||||
import { SCRUBBING_PROFILE } from '../../../src/config/profiles/scrubbing';
|
||||
import { setProfiles } from '../../../src/config/profiles';
|
||||
import { frigateCardConfigSchema } from '../../../src/config/types';
|
||||
import { createRawConfig } from '../../test-utils';
|
||||
|
||||
it('scrubbing profile', () => {
|
||||
it('should contain expected defaults', () => {
|
||||
expect(SCRUBBING_PROFILE).toEqual({
|
||||
'live.controls.timeline.mode': 'below',
|
||||
'live.controls.timeline.style': 'ribbon',
|
||||
@@ -11,3 +14,14 @@ it('scrubbing profile', () => {
|
||||
'media_viewer.controls.timeline.pan_mode': 'seek',
|
||||
});
|
||||
});
|
||||
|
||||
it('should be parseable after application', () => {
|
||||
const rawInputConfig = createRawConfig();
|
||||
const parsedConfig = frigateCardConfigSchema.parse(rawInputConfig);
|
||||
|
||||
setProfiles(rawInputConfig, parsedConfig, ['low-performance']);
|
||||
|
||||
// Reparse the config to ensure the profile did not introduce errors.
|
||||
const parseResult = frigateCardConfigSchema.safeParse(parsedConfig);
|
||||
expect(parseResult.success, parseResult.error?.toString()).toBeTruthy();
|
||||
});
|
||||
|
||||
+9
-3
@@ -81,12 +81,18 @@ export const createCondition = (
|
||||
return frigateCardConditionSchema.parse(condition ?? {});
|
||||
};
|
||||
|
||||
export const createConfig = (config?: RawFrigateCardConfig): FrigateCardConfig => {
|
||||
return frigateCardConfigSchema.parse({
|
||||
export const createRawConfig = (
|
||||
config?: Partial<RawFrigateCardConfig>,
|
||||
): RawFrigateCardConfig => {
|
||||
return {
|
||||
type: 'frigate-hass-card',
|
||||
cameras: [{}],
|
||||
...config,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const createConfig = (config?: RawFrigateCardConfig): FrigateCardConfig => {
|
||||
return frigateCardConfigSchema.parse(createRawConfig(config));
|
||||
};
|
||||
|
||||
export const createCamera = (
|
||||
|
||||
Reference in New Issue
Block a user