mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Fix hui-energy-compare-card (#24711)
* Fix hui-energy-compare-card * rename var
This commit is contained in:
parent
e0fbd3cd1f
commit
4c952c191a
@ -12,6 +12,7 @@ import type { LovelaceCard } from "../../types";
|
||||
import type { EnergyCardBaseConfig } from "../types";
|
||||
import { hasConfigChanged } from "../../common/has-changed";
|
||||
import "../../../../components/ha-alert";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
|
||||
@customElement("hui-energy-compare-card")
|
||||
export class HuiEnergyCompareCard
|
||||
@ -33,6 +34,11 @@ export class HuiEnergyCompareCard
|
||||
// eslint-disable-next-line lit/no-native-attributes
|
||||
@property({ type: Boolean, reflect: true }) hidden = true;
|
||||
|
||||
// Energy compare card cannot tolerate being removed from the DOM by hui-card,
|
||||
// as it calculates its own visibility and needs an active collection
|
||||
// subscription to do so.
|
||||
connectedWhileHidden = true;
|
||||
|
||||
public getCardSize(): Promise<number> | number {
|
||||
return 1;
|
||||
}
|
||||
@ -106,7 +112,11 @@ export class HuiEnergyCompareCard
|
||||
this._end = data.end;
|
||||
this._startCompare = data.startCompare;
|
||||
this._endCompare = data.endCompare;
|
||||
const oldHidden = this.hidden;
|
||||
this.hidden = !this._startCompare;
|
||||
if (oldHidden !== this.hidden) {
|
||||
fireEvent(this, "card-visibility-changed");
|
||||
}
|
||||
}
|
||||
|
||||
private _stopCompare(): void {
|
||||
|
@ -270,7 +270,11 @@ export class HuiCard extends ReactiveElement {
|
||||
fireEvent(this, "card-visibility-changed", { value: visible });
|
||||
}
|
||||
|
||||
if (!visible && this._element.parentElement) {
|
||||
if (this._element.connectedWhileHidden === true) {
|
||||
if (!this._element.parentElement) {
|
||||
this.appendChild(this._element);
|
||||
}
|
||||
} else if (!visible && this._element.parentElement) {
|
||||
this.removeChild(this._element);
|
||||
} else if (visible && !this._element.parentElement) {
|
||||
this.appendChild(this._element);
|
||||
|
@ -65,6 +65,7 @@ export interface LovelaceCard extends HTMLElement {
|
||||
hass?: HomeAssistant;
|
||||
preview?: boolean;
|
||||
layout?: string;
|
||||
connectedWhileHidden?: boolean;
|
||||
getCardSize(): number | Promise<number>;
|
||||
/** @deprecated Use `getGridOptions` instead */
|
||||
getLayoutOptions?(): LovelaceLayoutOptions;
|
||||
|
Loading…
x
Reference in New Issue
Block a user