feat: Add control/output of selected camera via an entity (#1895)

- Closes #1871
This commit is contained in:
Dermot Duffy
2025-02-17 13:33:10 -08:00
committed by GitHub
parent da79664a67
commit c66c3ec919
46 changed files with 677 additions and 91 deletions
+40 -2
View File
@@ -397,7 +397,7 @@ const logActionConfigSchema = advancedCameraCardCustomActionsBaseSchema.extend({
});
export type LogActionConfig = z.infer<typeof logActionConfigSchema>;
export const advancedCameraCardCustomActionSchema = z.union([
const advancedCameraCardCustomActionSchema = z.union([
cameraSelectActionConfigSchema,
generalActionConfigSchema,
substreamSelectActionConfigSchema,
@@ -416,6 +416,26 @@ export type AdvancedCameraCardCustomAction = z.infer<
typeof advancedCameraCardCustomActionSchema
>;
// An action that can be used internally to call a callback.
// Note: The internal callback action is kept out of schemas that can be user-specified.
export const INTERNAL_CALLBACK_ACTION = '__INTERNAL_CALLBACK_ACTION__';
const internalCallbackActionConfigSchema =
advancedCameraCardCustomActionsBaseSchema.extend({
advanced_camera_card_action: z.literal(INTERNAL_CALLBACK_ACTION),
// The callback is expected to be called with a CardController API object.
callback: z.function().args(z.any()).returns(z.promise(z.void())),
});
export type InternalCallbackActionConfig = z.infer<
typeof internalCallbackActionConfigSchema
>;
export const internalAdvancedCameraCardCustomActionSchema =
advancedCameraCardCustomActionSchema.or(internalCallbackActionConfigSchema);
export type InternalAdvancedCameraCardCustomAction = z.infer<
typeof internalAdvancedCameraCardCustomActionSchema
>;
// Cannot use discriminatedUnion since advancedCameraCardCustomActionSchema uses
// a transform on the discriminated union key.
export const actionSchema = z.union([
@@ -429,7 +449,9 @@ export const actionSchema = z.union([
customActionSchema,
advancedCameraCardCustomActionSchema,
]);
export type ActionType = z.infer<typeof actionSchema>;
const internalActionSchema = actionSchema.or(internalCallbackActionConfigSchema);
export type ActionType = z.infer<typeof internalActionSchema>;
const actionsBaseSchema = z
.object({
@@ -2075,6 +2097,20 @@ const PROFILES = ['casting', 'low-performance', 'scrubbing'] as const;
export type ProfileType = (typeof PROFILES)[number];
export const profilesSchema = z.enum(PROFILES).array().optional();
// *************************************************************************
// *** Remote Control Configuration ***
// *************************************************************************
const remoteControlConfigSchema = z
.object({
entities: z
.object({
camera: z.string().startsWith('input_select.').optional(),
})
.optional(),
})
.optional();
// *************************************************************************
// *** Card Configuration ***
// *************************************************************************
@@ -2114,6 +2150,8 @@ export const advancedCameraCardConfigSchema = z.object({
// that be easily used in a URL.
card_id: z.string().regex(cardIDRegex).optional(),
remote_control: remoteControlConfigSchema,
// Stock lovelace card config.
type: z.string(),
});