From 85d13b4947ee84cbd0b48935e31b2a12b67192df Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sun, 19 Mar 2023 15:01:52 -0700 Subject: [PATCH] Tolerate media players not in the entity registry. --- src/card.ts | 9 ++++++--- src/utils/ha/entity-registry/index.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/card.ts b/src/card.ts index da61080b..fe97c6de 100644 --- a/src/card.ts +++ b/src/card.ts @@ -1154,9 +1154,12 @@ class FrigateCard extends LitElement { // Filter out entities that are marked as hidden (this information is not // available in the HA state, only in the registry). - this._mediaPlayers = [...mediaPlayerEntities.values()] - .filter((entity) => !entity.hidden_by) - .map((entity) => entity.entity_id); + this._mediaPlayers = mediaPlayers.filter((entityID) => { + // Specifically allow for media players that are not found in the entity registry: + // See: https://github.com/dermotduffy/frigate-hass-card/issues/1016 + const entity = mediaPlayerEntities.get(entityID); + return !entity || !entity.hidden_by; + }); } /** diff --git a/src/utils/ha/entity-registry/index.ts b/src/utils/ha/entity-registry/index.ts index 71d9cbb6..79b1dfe5 100644 --- a/src/utils/ha/entity-registry/index.ts +++ b/src/utils/ha/entity-registry/index.ts @@ -43,7 +43,14 @@ export class EntityRegistryManager { ): Promise> { const output: Map = new Map(); const _storeEntity = async (entityID: string): Promise => { - const entity = await this.getEntity(hass, entityID); + let entity: Entity | null = null; + try { + entity = await this.getEntity(hass, entityID); + } catch { + // When asked to fetch multiple entities, ignore missing entities (they + // will just not feature in the output). + return; + } if (entity) { output.set(entityID, entity); }