Fix map card not loading in sidebar view (#14872)

fixes undefined
This commit is contained in:
karwosts 2022-12-27 13:00:19 -08:00 committed by GitHub
parent 419f23879a
commit 1c139d0bc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}