From eccf50252f72e9113d7f3185133758525faff936 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Tue, 1 Oct 2024 12:19:22 -0700 Subject: [PATCH] fix: Fix card initialization on some cast devices (#1601) --- src/utils/ha/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils/ha/index.ts b/src/utils/ha/index.ts index 3da4cece..6a15b77f 100644 --- a/src/utils/ha/index.ts +++ b/src/utils/ha/index.ts @@ -327,7 +327,15 @@ export const sideLoadHomeAssistantElements = async (): Promise => { camera_image: 'dummy-to-load-editor-components', }); - const pgcConstructor = await customElements.whenDefined('hui-picture-glance-card'); + // Some cast devices have a bug that causes whenDefined to return + // undefined instead of a constructor. + // See related: https://issues.chromium.org/issues/40846966 + await customElements.whenDefined('hui-picture-glance-card'); + const pgcConstructor = customElements.get('hui-picture-glance-card'); + if (!pgcConstructor) { + return false; + } + const pgc = new pgcConstructor() as LovelaceCardWithEditor; await pgc.constructor.getConfigElement();