refactor: Break apart monolithic configuration schema (#1977)

[skip ci]
This commit is contained in:
Dermot Duffy
2025-03-22 15:06:11 -07:00
committed by GitHub
parent 92fc8dd844
commit d6225fefda
266 changed files with 2789 additions and 2562 deletions
@@ -0,0 +1,17 @@
import { z } from 'zod';
// https://www.home-assistant.io/lovelace/picture-elements/#custom-elements
export const customSchema = z
.object({
// Insist that Advanced Camera Card custom elements are handled by other schemas.
type: z.string().superRefine((val, ctx) => {
if (!val.match(/^custom:(?!advanced-camera-card).+/)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'advanced-camera-card custom elements must match specific schemas',
fatal: true,
});
}
}),
})
.passthrough();
+9
View File
@@ -0,0 +1,9 @@
import { z } from 'zod';
import { elementsBaseSchema } from '../base';
// https://www.home-assistant.io/lovelace/picture-elements/#icon-element
export const iconSchema = elementsBaseSchema.extend({
type: z.literal('icon'),
icon: z.string(),
entity: z.string().optional(),
});
+15
View File
@@ -0,0 +1,15 @@
import { z } from 'zod';
import { elementsBaseSchema } from '../base';
// https://www.home-assistant.io/lovelace/picture-elements/#image-element
export const imageSchema = elementsBaseSchema.extend({
type: z.literal('image'),
entity: z.string().optional(),
image: z.string().optional(),
camera_image: z.string().optional(),
camera_view: z.string().optional(),
state_image: z.object({}).passthrough().optional(),
filter: z.string().optional(),
state_filter: z.object({}).passthrough().optional(),
aspect_ratio: z.string().optional(),
});
@@ -0,0 +1,12 @@
import { z } from 'zod';
import { elementsBaseSchema } from '../base';
// https://www.home-assistant.io/lovelace/picture-elements/#service-call-button
export const serviceCallButtonSchema = elementsBaseSchema.extend({
type: z.literal('service-button'),
// Title is required for service button.
title: z.string(),
service: z.string(),
service_data: z.object({}).passthrough().optional(),
});
@@ -0,0 +1,8 @@
import { z } from 'zod';
import { elementsBaseSchema } from '../base';
// https://www.home-assistant.io/lovelace/picture-elements/#state-badge
export const stateBadgeIconSchema = elementsBaseSchema.extend({
type: z.literal('state-badge'),
entity: z.string(),
});
@@ -0,0 +1,10 @@
import { z } from 'zod';
import { elementsBaseSchema } from '../base';
// https://www.home-assistant.io/lovelace/picture-elements/#state-icon
export const stateIconSchema = elementsBaseSchema.extend({
type: z.literal('state-icon'),
entity: z.string(),
icon: z.string().optional(),
state_color: z.boolean().default(true),
});
@@ -0,0 +1,11 @@
import { z } from 'zod';
import { elementsBaseSchema } from '../base';
// https://www.home-assistant.io/lovelace/picture-elements/#state-label
export const stateLabelSchema = elementsBaseSchema.extend({
type: z.literal('state-label'),
entity: z.string(),
attribute: z.string().optional(),
prefix: z.string().optional(),
suffix: z.string().optional(),
});