From 450cb0151f543b3548ac7653a4c2698569d497cb Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Thu, 11 Nov 2021 20:08:50 -0800 Subject: [PATCH] fire-dom-event must be a literal --- src/types.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/types.ts b/src/types.ts index a7c52b24..853a6ebc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,6 @@ import { CallServiceActionConfig, + CustomActionConfig, LovelaceCard, LovelaceCardEditor, MoreInfoActionConfig, @@ -99,14 +100,21 @@ const moreInfoActionSchema = schemaForType()( action: z.literal('more-info'), }), ); -const customActionSchema = z.object({ - action: z.literal('fire-dom-event'), -}) -export const frigateCardCustomActionSchema = customActionSchema.merge(z.object({ - // Syntactic sugar to avoid 'fire-dom-event' as part of an external API. - action: z.literal('fire-dom-event').or(z.literal('custom:frigate-card-action').transform(() => 'fire-dom-event')), - frigate_card_action: z.string(), -})) +const customActionSchema = schemaForType()( + z.object({ + action: z.literal('fire-dom-event'), + }), +); +export const frigateCardCustomActionSchema = customActionSchema.merge( + z.object({ + // Syntactic sugar to avoid 'fire-dom-event' as part of an external API. + action: z + .literal('custom:frigate-card-action') + .transform((): 'fire-dom-event' => 'fire-dom-event') + .or(z.literal('fire-dom-event')), + frigate_card_action: z.string(), + }), +); export type FrigateCardCustomAction = z.infer; const elementsActionSchema = z.union([ @@ -485,10 +493,7 @@ export const frigateCardConfigDefaults = { event_viewer: viewerConfigDefault, }; -const menuButtonSchema = z.union([ - menuIconSchema, - menuStateIconSchema, -]); +const menuButtonSchema = z.union([menuIconSchema, menuStateIconSchema]); export type MenuButton = z.infer; export interface ExtendedHomeAssistant { hassUrl(path?): string;