Prevent re-creation of custom panel when content was not changed (#13747)

This commit is contained in:
Bram Kragten 2022-09-27 19:39:05 +02:00 committed by GitHub
parent 3083d5b04c
commit 17a11809de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -61,7 +61,7 @@ export interface EntityRegistryEntryUpdateParams {
hidden_by: string | null; hidden_by: string | null;
new_entity_id?: string; new_entity_id?: string;
options_domain?: string; options_domain?: string;
options?: SensorEntityOptions | WeatherEntityOptions; options?: SensorEntityOptions | NumberEntityOptions | WeatherEntityOptions;
} }
export const findBatteryEntity = ( export const findBatteryEntity = (

View File

@ -1,6 +1,7 @@
import { PropertyValues, ReactiveElement } from "lit"; import { PropertyValues, ReactiveElement } from "lit";
import { property } from "lit/decorators"; import { property } from "lit/decorators";
import { navigate, NavigateOptions } from "../../common/navigate"; import { navigate, NavigateOptions } from "../../common/navigate";
import { deepEqual } from "../../common/util/deep-equal";
import { CustomPanelInfo } from "../../data/panel_custom"; import { CustomPanelInfo } from "../../data/panel_custom";
import { HomeAssistant, Route } from "../../types"; import { HomeAssistant, Route } from "../../types";
import { createCustomPanelElement } from "../../util/custom-panel/create-custom-panel-element"; import { createCustomPanelElement } from "../../util/custom-panel/create-custom-panel-element";
@ -54,12 +55,15 @@ export class HaPanelCustom extends ReactiveElement {
protected update(changedProps: PropertyValues) { protected update(changedProps: PropertyValues) {
super.update(changedProps); super.update(changedProps);
if (changedProps.has("panel")) { if (changedProps.has("panel")) {
// Clean up old things if we had a panel // Clean up old things if we had a panel and the new one is different.
if (changedProps.get("panel")) { const oldPanel = changedProps.get("panel") as CustomPanelInfo | undefined;
this._cleanupPanel(); if (!deepEqual(oldPanel, this.panel)) {
if (oldPanel) {
this._cleanupPanel();
}
this._createPanel(this.panel);
return;
} }
this._createPanel(this.panel);
return;
} }
if (!this._setProperties) { if (!this._setProperties) {
return; return;