diff --git a/src/panels/lovelace/cards/hui-map-card.ts b/src/panels/lovelace/cards/hui-map-card.ts index e5b7951160..ca91c301e8 100644 --- a/src/panels/lovelace/cards/hui-map-card.ts +++ b/src/panels/lovelace/cards/hui-map-card.ts @@ -102,6 +102,7 @@ class HuiMapCard extends LitElement implements LovelaceCard { ratio && ratio.w > 0 && ratio.h > 0 ? `${((100 * ratio.h) / ratio.w).toFixed(2)}` : "100"; + return 1 + Math.floor(Number(ar) / 25) || 3; } @@ -185,10 +186,21 @@ class HuiMapCard extends LitElement implements LovelaceCard { return false; } - protected firstUpdated(changedProps: PropertyValues): void { - super.firstUpdated(changedProps); - const root = this.shadowRoot!.getElementById("root"); + protected updated(changedProps: PropertyValues): void { + if (this._config?.hours_to_show && this._configEntities?.length) { + if (changedProps.has("_config")) { + this._getHistory(); + } else if (Date.now() - this._date!.getTime() >= MINUTE) { + this._getHistory(); + } + } + if (changedProps.has("_config")) { + this._computePadding(); + } + } + private _computePadding(): void { + const root = this.shadowRoot!.getElementById("root"); if (!this._config || this.isPanel || !root) { return; } @@ -206,16 +218,6 @@ class HuiMapCard extends LitElement implements LovelaceCard { : (root.style.paddingBottom = "100%"); } - protected updated(changedProps: PropertyValues): void { - if (this._config?.hours_to_show && this._configEntities?.length) { - if (changedProps.has("_config")) { - this._getHistory(); - } else if (Date.now() - this._date!.getTime() >= MINUTE) { - this._getHistory(); - } - } - } - private _fitMap() { this._map?.fitMap(); }