From b96ad65f4891469ffc48ba84faaca4b936fb34b3 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Thu, 29 Jun 2023 00:57:37 -0700 Subject: [PATCH] Add summations to gas/solar/water energy graph tooltips (#17084) --- .../cards/energy/hui-energy-gas-graph-card.ts | 18 ++++++++++++++++ .../energy/hui-energy-solar-graph-card.ts | 21 +++++++++++++++++++ .../energy/hui-energy-water-graph-card.ts | 18 ++++++++++++++++ src/translations/en.json | 9 +++++++- 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts index 68ac83ab67..3a67549e4f 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts @@ -240,6 +240,24 @@ export class HuiEnergyGasGraphCard context.parsed.y, locale )} ${unit}`, + footer: (contexts) => { + if (contexts.length < 2) { + return []; + } + let total = 0; + for (const context of contexts) { + total += (context.dataset.data[context.dataIndex] as any).y; + } + if (total === 0) { + return []; + } + return [ + this.hass.localize( + "ui.panel.lovelace.cards.energy.energy_gas_graph.total_consumed", + { num: formatNumber(total, locale), unit } + ), + ]; + }, }, }, filler: { diff --git a/src/panels/lovelace/cards/energy/hui-energy-solar-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-solar-graph-card.ts index 778ccb77d1..b1f8da63c0 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-solar-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-solar-graph-card.ts @@ -236,6 +236,27 @@ export class HuiEnergySolarGraphCard context.parsed.y, locale )} kWh`, + footer: (contexts) => { + const production_contexts = contexts.filter( + (c) => c.dataset?.stack === "solar" + ); + if (production_contexts.length < 2) { + return []; + } + let total = 0; + for (const context of production_contexts) { + total += (context.dataset.data[context.dataIndex] as any).y; + } + if (total === 0) { + return []; + } + return [ + this.hass.localize( + "ui.panel.lovelace.cards.energy.energy_solar_graph.total_produced", + { num: formatNumber(total, locale) } + ), + ]; + }, }, }, filler: { diff --git a/src/panels/lovelace/cards/energy/hui-energy-water-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-water-graph-card.ts index 41d4029c04..4fc102ebf2 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-water-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-water-graph-card.ts @@ -240,6 +240,24 @@ export class HuiEnergyWaterGraphCard context.parsed.y, locale )} ${unit}`, + footer: (contexts) => { + if (contexts.length < 2) { + return []; + } + let total = 0; + for (const context of contexts) { + total += (context.dataset.data[context.dataIndex] as any).y; + } + if (total === 0) { + return []; + } + return [ + this.hass.localize( + "ui.panel.lovelace.cards.energy.energy_water_graph.total_consumed", + { num: formatNumber(total, locale), unit } + ), + ]; + }, }, }, filler: { diff --git a/src/translations/en.json b/src/translations/en.json index 2f71088f55..2c60787dbf 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4312,7 +4312,14 @@ }, "energy_solar_graph": { "production": "Production {name}", - "forecast": "Forecast {name}" + "forecast": "Forecast {name}", + "total_produced": "Total produced {num} kWh" + }, + "energy_gas_graph": { + "total_consumed": "Total consumed {num} {unit}" + }, + "energy_water_graph": { + "total_consumed": "[%key:ui::panel::lovelace::cards::energy::energy_gas_graph::total_consumed%]" }, "solar_consumed_gauge": { "card_indicates_solar_energy_used": "This card indicates how much of the solar energy you produced was used by your home instead of being returned to the grid.",