fix: Folders should be overrideable (#2198)

- Closes #2196
This commit is contained in:
Dermot Duffy
2025-10-04 16:13:11 -07:00
committed by GitHub
parent 78dee9194f
commit af53c66cd5
2 changed files with 41 additions and 2 deletions
+6 -1
View File
@@ -119,7 +119,12 @@ export const transformPathURLToPathArray = (
}; };
const haFolderConfigSchema = z.object({ const haFolderConfigSchema = z.object({
url: z.string().transform(transformPathURLToPathArray).optional(), url: z
.string()
.transform(transformPathURLToPathArray)
// See: https://github.com/dermotduffy/advanced-camera-card/issues/2196
.or(haFolderPathComponentSchema.array().min(1))
.optional(),
path: haFolderPathComponentSchema.array().nonempty().optional(), path: haFolderPathComponentSchema.array().nonempty().optional(),
}); });
export type HAFolderConfig = z.infer<typeof haFolderConfigSchema>; export type HAFolderConfig = z.infer<typeof haFolderConfigSchema>;
+35 -1
View File
@@ -1,11 +1,13 @@
import { NonEmptyTuple } from 'type-fest'; import { NonEmptyTuple } from 'type-fest';
import { describe, expect, it } from 'vitest'; import { describe, expect, it } from 'vitest';
import { import {
FolderConfigWithoutID,
foldersConfigSchema,
matcherSchema, matcherSchema,
transformPathURLToPathArray, transformPathURLToPathArray,
} from '../../../src/config/schema/folders'; } from '../../../src/config/schema/folders';
describe('transformURLToMediaSourceRoot', () => { describe('transformPathURLToPathArray', () => {
const prefixes: NonEmptyTuple<string>[] = [ const prefixes: NonEmptyTuple<string>[] = [
['http://card.camera/' as const], ['http://card.camera/' as const],
['/' as const], ['/' as const],
@@ -92,3 +94,35 @@ describe('should lazy evaluate schemas', () => {
}); });
}); });
}); });
// See: https://github.com/dermotduffy/advanced-camera-card/issues/2196
describe('should be able to re-parse a folder', () => {
it('should be able to re-parse a folder', () => {
const inputFolder = {
type: 'ha',
ha: {
url: 'media-browser/browser/app%2Cmedia-source%3A%2F%2Fcamera' as const,
},
};
const expectedFolder: FolderConfigWithoutID = {
type: 'ha',
ha: {
url: [
{
id: 'media-source://',
},
{
id: 'media-source://camera',
},
],
},
};
const parsedFolders = foldersConfigSchema.parse([inputFolder]);
expect(parsedFolders).toEqual([expectedFolder]);
const parsedFolder_2 = foldersConfigSchema.parse(parsedFolders);
expect(parsedFolder_2).toEqual([expectedFolder]);
});
});