feat: Add control/output of selected camera via an entity (#1895)
- Closes #1871
This commit is contained in:
+40
-2
@@ -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(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user