From 4a80d1420915dc6c2723cbd18d8dd9ea66e4a719 Mon Sep 17 00:00:00 2001 From: Justin Wong <46082645+uvjustin@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:30:03 +0800 Subject: [PATCH] Update homeAssistantWSRequest to accept passthrough JSON --- src/utils/frigate.ts | 7 +++++-- src/utils/ha/index.ts | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utils/frigate.ts b/src/utils/frigate.ts index ef18c18f..02953681 100644 --- a/src/utils/frigate.ts +++ b/src/utils/frigate.ts @@ -77,7 +77,8 @@ export const getRecordingsSummary = async ( type: "frigate/recordings/summary", instance_id: client_id, camera: camera_name - } + }, + true, ); }; @@ -106,7 +107,8 @@ export const getRecordingSegments = async ( camera: camera_name, before: Math.floor(before.getTime() / 1000), after: Math.ceil(after.getTime() / 1000), - } + }, + true, ); }; @@ -133,6 +135,7 @@ export async function retainEvent( hass, retainResultSchema, retainRequest, + true, ); if (!response.success) { throw new FrigateCardError(localize('error.failed_retain'), { diff --git a/src/utils/ha/index.ts b/src/utils/ha/index.ts index 963a014a..74fd0f6a 100644 --- a/src/utils/ha/index.ts +++ b/src/utils/ha/index.ts @@ -25,6 +25,7 @@ export async function homeAssistantWSRequest( hass: HomeAssistant, schema: ZodSchema, request: MessageBase, + passthrough = false, ): Promise { let response; try { @@ -44,7 +45,11 @@ export async function homeAssistantWSRequest( request: request, }); } - const parseResult = schema.safeParse(response); + // Some endpoints on the integration pass through JSON directly from Frigate + // These end up wrapped in a string and must be unwrapped first + const parseResult = passthrough + ? schema.safeParse(JSON.parse(response)) + : schema.safeParse(response); if (!parseResult.success) { throw new FrigateCardError(localize('error.invalid_response'), { request: request,