mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
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:
parent
9d9522cade
commit
b33e4bf305
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user