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;
new_entity_id?: string;
options_domain?: string;
options?: SensorEntityOptions | WeatherEntityOptions;
options?: SensorEntityOptions | NumberEntityOptions | WeatherEntityOptions;
}
export const findBatteryEntity = (

View File

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