mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Energy: Wait with subscribe for _config to be set (#11884)
This commit is contained in:
parent
437de42c55
commit
1159798b8d
@ -13,6 +13,9 @@ export const SubscribeMixin = <T extends Constructor<ReactiveElement>>(
|
|||||||
class SubscribeClass extends superClass {
|
class SubscribeClass extends superClass {
|
||||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
|
|
||||||
|
// we wait with subscribing till these properties are set on the host element
|
||||||
|
protected hassSubscribeRequiredHostProps?: string[];
|
||||||
|
|
||||||
private __unsubs?: Array<UnsubscribeFunc | Promise<UnsubscribeFunc>>;
|
private __unsubs?: Array<UnsubscribeFunc | Promise<UnsubscribeFunc>>;
|
||||||
|
|
||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
@ -39,6 +42,16 @@ export const SubscribeMixin = <T extends Constructor<ReactiveElement>>(
|
|||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
if (changedProps.has("hass")) {
|
if (changedProps.has("hass")) {
|
||||||
this.__checkSubscribed();
|
this.__checkSubscribed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.hassSubscribeRequiredHostProps) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const key of changedProps.keys()) {
|
||||||
|
if (this.hassSubscribeRequiredHostProps.includes(key as string)) {
|
||||||
|
this.__checkSubscribed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +65,10 @@ export const SubscribeMixin = <T extends Constructor<ReactiveElement>>(
|
|||||||
if (
|
if (
|
||||||
this.__unsubs !== undefined ||
|
this.__unsubs !== undefined ||
|
||||||
!(this as unknown as Element).isConnected ||
|
!(this as unknown as Element).isConnected ||
|
||||||
this.hass === undefined
|
this.hass === undefined ||
|
||||||
|
this.hassSubscribeRequiredHostProps?.some(
|
||||||
|
(prop) => this[prop] === undefined
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ class HuiEnergyCarbonGaugeCard
|
|||||||
|
|
||||||
@state() private _data?: EnergyData;
|
@state() private _data?: EnergyData;
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public getCardSize(): number {
|
public getCardSize(): number {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ export class HuiEnergyDevicesGraphCard
|
|||||||
|
|
||||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
@query("ha-chart-base") private _chart?: HaChartBase;
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return [
|
return [
|
||||||
getEnergyDataCollection(this.hass, {
|
getEnergyDataCollection(this.hass, {
|
||||||
|
@ -43,6 +43,8 @@ class HuiEnergyDistrubutionCard
|
|||||||
|
|
||||||
@state() private _data?: EnergyData;
|
@state() private _data?: EnergyData;
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public setConfig(config: EnergyDistributionCardConfig): void {
|
public setConfig(config: EnergyDistributionCardConfig): void {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,8 @@ export class HuiEnergyGasGraphCard
|
|||||||
|
|
||||||
@state() private _unit?: string;
|
@state() private _unit?: string;
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return [
|
return [
|
||||||
getEnergyDataCollection(this.hass, {
|
getEnergyDataCollection(this.hass, {
|
||||||
|
@ -35,6 +35,8 @@ class HuiEnergyGridGaugeCard
|
|||||||
|
|
||||||
@state() private _data?: EnergyData;
|
@state() private _data?: EnergyData;
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return [
|
return [
|
||||||
getEnergyDataCollection(this.hass!, {
|
getEnergyDataCollection(this.hass!, {
|
||||||
|
@ -30,6 +30,8 @@ class HuiEnergySolarGaugeCard
|
|||||||
|
|
||||||
@state() private _data?: EnergyData;
|
@state() private _data?: EnergyData;
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return [
|
return [
|
||||||
getEnergyDataCollection(this.hass!, {
|
getEnergyDataCollection(this.hass!, {
|
||||||
|
@ -61,6 +61,8 @@ export class HuiEnergySolarGraphCard
|
|||||||
|
|
||||||
@state() private _end = endOfToday();
|
@state() private _end = endOfToday();
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return [
|
return [
|
||||||
getEnergyDataCollection(this.hass, {
|
getEnergyDataCollection(this.hass, {
|
||||||
|
@ -45,6 +45,8 @@ export class HuiEnergySourcesTableCard
|
|||||||
|
|
||||||
@state() private _data?: EnergyData;
|
@state() private _data?: EnergyData;
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return [
|
return [
|
||||||
getEnergyDataCollection(this.hass, {
|
getEnergyDataCollection(this.hass, {
|
||||||
|
@ -50,6 +50,8 @@ export class HuiEnergyUsageGraphCard
|
|||||||
|
|
||||||
@state() private _end = endOfToday();
|
@state() private _end = endOfToday();
|
||||||
|
|
||||||
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return [
|
return [
|
||||||
getEnergyDataCollection(this.hass, {
|
getEnergyDataCollection(this.hass, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user