fire-dom-event must be a literal

This commit is contained in:
Dermot Duffy
2021-11-11 20:08:50 -08:00
parent df79ff80eb
commit 450cb0151f
+17 -12
View File
@@ -1,5 +1,6 @@
import { import {
CallServiceActionConfig, CallServiceActionConfig,
CustomActionConfig,
LovelaceCard, LovelaceCard,
LovelaceCardEditor, LovelaceCardEditor,
MoreInfoActionConfig, MoreInfoActionConfig,
@@ -99,14 +100,21 @@ const moreInfoActionSchema = schemaForType<MoreInfoActionConfig>()(
action: z.literal('more-info'), action: z.literal('more-info'),
}), }),
); );
const customActionSchema = z.object({ const customActionSchema = schemaForType<CustomActionConfig>()(
action: z.literal('fire-dom-event'), 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')), export const frigateCardCustomActionSchema = customActionSchema.merge(
frigate_card_action: z.string(), 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<typeof frigateCardCustomActionSchema>; export type FrigateCardCustomAction = z.infer<typeof frigateCardCustomActionSchema>;
const elementsActionSchema = z.union([ const elementsActionSchema = z.union([
@@ -485,10 +493,7 @@ export const frigateCardConfigDefaults = {
event_viewer: viewerConfigDefault, event_viewer: viewerConfigDefault,
}; };
const menuButtonSchema = z.union([ const menuButtonSchema = z.union([menuIconSchema, menuStateIconSchema]);
menuIconSchema,
menuStateIconSchema,
]);
export type MenuButton = z.infer<typeof menuButtonSchema>; export type MenuButton = z.infer<typeof menuButtonSchema>;
export interface ExtendedHomeAssistant { export interface ExtendedHomeAssistant {
hassUrl(path?): string; hassUrl(path?): string;