feat: Add or and template folder media matchers (#2071)

- For: #1748
This commit is contained in:
Dermot Duffy
2025-05-29 21:21:59 -07:00
committed by GitHub
parent c077f8bf70
commit dc63dcdab9
25 changed files with 502 additions and 145 deletions
+22 -2
View File
@@ -1,8 +1,8 @@
import { NonEmptyTuple } from 'type-fest';
import { z } from 'zod';
import { AdvancedCameraCardError } from '../../types';
import { isTruthy } from '../../utils/basic';
import { regexSchema } from './common/regex';
import { AdvancedCameraCardError } from '../../types';
export const HA_MEDIA_SOURCE_ROOT = 'media-source://';
@@ -31,12 +31,32 @@ const parserSchema = z.discriminatedUnion('type', [
]);
export type Parser = z.infer<typeof parserSchema>;
const templateMatcherSchema = parserBaseSchema.extend({
type: z.literal('template'),
value_template: z.string(),
});
export type TemplateMatcher = z.infer<typeof templateMatcherSchema>;
const titleMatcherSchema = parserBaseSchema.extend({
type: z.literal('title'),
regexp: regexSchema.optional(),
title: z.string().optional(),
});
const matcherSchema = z.discriminatedUnion('type', [titleMatcherSchema]);
export type TitleMatcher = z.infer<typeof titleMatcherSchema>;
type OrMatcher = {
type: 'or';
matchers: Matcher[];
};
const orMatcherSchema: z.ZodSchema<OrMatcher, z.ZodTypeDef> = z.object({
type: z.literal('or'),
matchers: z.array(z.lazy(() => matcherSchema)),
});
export const matcherSchema = z.union([
orMatcherSchema,
templateMatcherSchema,
titleMatcherSchema,
]);
export type Matcher = z.infer<typeof matcherSchema>;
const haFolderPathComponentSchema = z.object({