From 67d146220a33531ec033ce28bbcf690b9e19a717 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Thu, 16 Jul 2026 16:25:48 +0200 Subject: [PATCH] test(integrations): wait for Home Assistant restart --- .../integrations/test/home-assistant.spec.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/integrations/test/home-assistant.spec.ts b/packages/integrations/test/home-assistant.spec.ts index 608af1ce0..5dc2be90e 100644 --- a/packages/integrations/test/home-assistant.spec.ts +++ b/packages/integrations/test/home-assistant.spec.ts @@ -77,9 +77,29 @@ const prepareHomeAssistantContainerAsync = async () => { const startedContainer = await homeAssistantContainer.start(); await startedContainer.exec(["unzip", "-o", "/tmp/config.zip", "-d", "/config"]); await startedContainer.restart(); + await waitForHomeAssistantAsync(startedContainer); return startedContainer; }; +const waitForHomeAssistantAsync = async (container: StartedTestContainer) => { + const url = `http://${container.getHost()}:${container.getMappedPort(8123)}/api/config`; + + for (let attempt = 0; attempt < 40; attempt++) { + try { + const response = await fetch(url, { + headers: { Authorization: `Bearer ${DEFAULT_API_KEY}` }, + }); + if (response.ok) return; + } catch { + // Home Assistant is still restarting. + } + + await new Promise((resolve) => setTimeout(resolve, 500)); + } + + throw new Error("Home Assistant did not become ready after restart"); +}; + const createHomeAssistantContainer = () => { return ( new GenericContainer(IMAGE_NAME)