From 785ef19cceb05e8f0b6daf5be1ee1e9fb9c8c287 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 12 Mar 2020 20:37:54 +0100 Subject: [PATCH] Only update map if one of entities changed (#5175) --- src/components/map/ha-map.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/components/map/ha-map.ts b/src/components/map/ha-map.ts index d86a9e7c51..a0c3075d48 100644 --- a/src/components/map/ha-map.ts +++ b/src/components/map/ha-map.ts @@ -90,6 +90,27 @@ class HaMap extends LitElement { } } + protected shouldUpdate(changedProps) { + if (!changedProps.has("hass") || changedProps.size > 1) { + return true; + } + + const oldHass = changedProps.get("hass") as HomeAssistant | undefined; + + if (!oldHass || !this.entities) { + return true; + } + + // Check if any state has changed + for (const entity of this.entities) { + if (oldHass.states[entity] !== this.hass!.states[entity]) { + return true; + } + } + + return false; + } + protected updated(changedProps: PropertyValues): void { if (changedProps.has("hass")) { this._drawEntities();