diff --git a/src/panels/lovelace/cards/energy/hui-energy-sources-table-card.ts b/src/panels/lovelace/cards/energy/hui-energy-sources-table-card.ts index 734a4067ae..4b061f42a0 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-sources-table-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-sources-table-card.ts @@ -80,6 +80,10 @@ export class HuiEnergySourcesTableCard let totalWater = 0; let totalWaterCost = 0; + let hasGridCost = false; + let hasGasCost = false; + let hasWaterCost = false; + let totalGridCompare = 0; let totalGridCostCompare = 0; let totalSolarCompare = 0; @@ -477,6 +481,7 @@ export class HuiEnergySourcesTableCard ) || 0 : null; if (cost !== null) { + hasGridCost = true; totalGridCost += cost; } @@ -575,6 +580,7 @@ export class HuiEnergySourcesTableCard ) || 0) * -1 : null; if (cost !== null) { + hasGridCost = true; totalGridCost += cost; } @@ -686,14 +692,16 @@ export class HuiEnergySourcesTableCard ? html` - ${formatNumber( - totalGridCostCompare, - this.hass.locale, - { - style: "currency", - currency: this.hass.config.currency!, - } - )} + ${hasGridCost + ? formatNumber( + totalGridCostCompare, + this.hass.locale, + { + style: "currency", + currency: this.hass.config.currency!, + } + ) + : ""} ` : ""}` : ""} @@ -706,10 +714,12 @@ export class HuiEnergySourcesTableCard ? html` - ${formatNumber(totalGridCost, this.hass.locale, { - style: "currency", - currency: this.hass.config.currency!, - })} + ${hasGridCost + ? formatNumber(totalGridCost, this.hass.locale, { + style: "currency", + currency: this.hass.config.currency!, + }) + : ""} ` : ""} ` @@ -737,6 +747,7 @@ export class HuiEnergySourcesTableCard 0 : null; if (cost !== null) { + hasGasCost = true; totalGasCost += cost; } @@ -835,14 +846,16 @@ export class HuiEnergySourcesTableCard ? html` - ${formatNumber( - totalGasCostCompare, - this.hass.locale, - { - style: "currency", - currency: this.hass.config.currency!, - } - )} + ${hasGasCost + ? formatNumber( + totalGasCostCompare, + this.hass.locale, + { + style: "currency", + currency: this.hass.config.currency!, + } + ) + : ""} ` : ""}` : ""} @@ -855,10 +868,12 @@ export class HuiEnergySourcesTableCard ? html` - ${formatNumber(totalGasCost, this.hass.locale, { - style: "currency", - currency: this.hass.config.currency!, - })} + ${hasGasCost + ? formatNumber(totalGasCost, this.hass.locale, { + style: "currency", + currency: this.hass.config.currency!, + }) + : ""} ` : ""} ` @@ -886,6 +901,7 @@ export class HuiEnergySourcesTableCard 0 : null; if (cost !== null) { + hasWaterCost = true; totalWaterCost += cost; } @@ -984,14 +1000,16 @@ export class HuiEnergySourcesTableCard ? html` - ${formatNumber( - totalWaterCostCompare, - this.hass.locale, - { - style: "currency", - currency: this.hass.config.currency!, - } - )} + ${hasWaterCost + ? formatNumber( + totalWaterCostCompare, + this.hass.locale, + { + style: "currency", + currency: this.hass.config.currency!, + } + ) + : ""} ` : ""}` : ""} @@ -1004,16 +1022,18 @@ export class HuiEnergySourcesTableCard ? html` - ${formatNumber(totalWaterCost, this.hass.locale, { - style: "currency", - currency: this.hass.config.currency!, - })} + ${hasWaterCost + ? formatNumber(totalWaterCost, this.hass.locale, { + style: "currency", + currency: this.hass.config.currency!, + }) + : ""} ` : ""} ` : ""} - ${[totalGasCost, totalWaterCost, totalGridCost].filter(Boolean) - .length > 1 + ${[hasGasCost, hasWaterCost, hasGridCost].filter(Boolean).length > + 1 ? html` @@ -1022,9 +1042,7 @@ export class HuiEnergySourcesTableCard )} ${compare - ? html`${showCosts - ? html`` - : ""} + ? html`