Skip to content

Commit

Permalink
Merge pull request #24 from flixlix/fix-state-type-fossil
Browse files Browse the repository at this point in the history
fix: reintroduce `non_fossil` state type percentage
  • Loading branch information
flixlix committed May 24, 2023
2 parents 4ac4dd9 + 7381e3a commit a3016d8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/energy-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
? this.displayValue(totalHomeConsumption - totalIndividualConsumption || 0)
: this.displayValue(totalHomeConsumption);

let lowCarbonPercentage: number | undefined;
if (this._data.co2SignalEntity && this._data.fossilEnergyConsumption) {
// Calculate high carbon consumption
const highCarbonEnergy = Object.values(this._data.fossilEnergyConsumption).reduce((sum, a) => sum + a, 0) * 1000;
Expand All @@ -902,6 +903,7 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {

homeGridCircumference = circleCircumference * (highCarbonConsumption / totalHomeConsumption);
homeNonFossilCircumference = circleCircumference - (homeSolarCircumference || 0) - (homeBatteryCircumference || 0) - homeGridCircumference;
lowCarbonPercentage = ((lowCarbonEnergy || 0) / totalFromGrid) * 100;
}

const hasNonFossilFuelUsage =
Expand Down Expand Up @@ -971,9 +973,14 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
? 'padding-bottom: 2px;'
: 'padding-bottom: 0px;'}"
></ha-icon>
${entities.fossil_fuel_percentage?.display_zero_state !== false ||
(nonFossilFuelenergy || 0) > (entities.fossil_fuel_percentage?.display_zero_tolerance || 0)
? html` <span class="low-carbon">${this.displayValue(lowCarbonEnergy ?? null)}</span> `
${entities.fossil_fuel_percentage?.display_zero_state !== false || hasNonFossilFuelUsage !== false
? html`
<span class="low-carbon"
>${entities.fossil_fuel_percentage?.state_type === 'percentage'
? lowCarbonPercentage?.toFixed(0) + '%' || '0%'
: this.displayValue(lowCarbonEnergy ?? null)}</span
>
`
: ''}
</div>
${this.showLine(nonFossilFuelenergy || 0)
Expand Down

0 comments on commit a3016d8

Please sign in to comment.