Render low carbon gauge when only solar consumption (#24992)

* Render low carbon gauge when only solar consumption

* no null check
This commit is contained in:
karwosts 2025-04-10 09:01:49 -07:00 committed by GitHub
parent 9d9522cade
commit b33e4bf305
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -95,14 +95,15 @@ class HuiEnergyCarbonGaugeCard
const prefs = this._data.prefs; const prefs = this._data.prefs;
const types = energySourcesByType(prefs); const types = energySourcesByType(prefs);
const totalGridConsumption = calculateStatisticsSumGrowth( const totalGridConsumption =
calculateStatisticsSumGrowth(
this._data.stats, this._data.stats,
types.grid![0].flow_from.map((flow) => flow.stat_energy_from) types.grid![0].flow_from.map((flow) => flow.stat_energy_from)
); ) ?? 0;
let value: number | undefined; let value: number | undefined;
if (this._data.fossilEnergyConsumption && totalGridConsumption) { if (this._data.fossilEnergyConsumption) {
const highCarbonEnergy = this._data.fossilEnergyConsumption const highCarbonEnergy = this._data.fossilEnergyConsumption
? Object.values(this._data.fossilEnergyConsumption).reduce( ? Object.values(this._data.fossilEnergyConsumption).reduce(
(sum, a) => sum + a, (sum, a) => sum + a,
@ -127,8 +128,10 @@ class HuiEnergyCarbonGaugeCard
totalGridConsumption + totalGridConsumption +
Math.max(0, totalSolarProduction - totalGridReturned); Math.max(0, totalSolarProduction - totalGridReturned);
if (totalEnergyConsumed) {
value = round((1 - highCarbonEnergy / totalEnergyConsumed) * 100); value = round((1 - highCarbonEnergy / totalEnergyConsumed) * 100);
} }
}
return html` return html`
<ha-card> <ha-card>