mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
Add total consumption to energy usage graph card (#28086)
* Add total consumption to energy usage graph card * Add "used" suffix to energy usage graph card total * Apply code review feedback * Update src/panels/lovelace/cards/energy/hui-energy-usage-graph-card.ts --------- Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import { getEnergyColor } from "./common/color";
|
|||||||
import { formatNumber } from "../../../../common/number/format_number";
|
import { formatNumber } from "../../../../common/number/format_number";
|
||||||
import "../../../../components/chart/ha-chart-base";
|
import "../../../../components/chart/ha-chart-base";
|
||||||
import "../../../../components/ha-card";
|
import "../../../../components/ha-card";
|
||||||
|
import "./common/hui-energy-graph-chip";
|
||||||
import type {
|
import type {
|
||||||
EnergyData,
|
EnergyData,
|
||||||
EnergySumData,
|
EnergySumData,
|
||||||
@@ -67,6 +68,8 @@ export class HuiEnergyUsageGraphCard
|
|||||||
|
|
||||||
@state() private _compareEnd?: Date;
|
@state() private _compareEnd?: Date;
|
||||||
|
|
||||||
|
@state() private _total?: number;
|
||||||
|
|
||||||
protected hassSubscribeRequiredHostProps = ["_config"];
|
protected hassSubscribeRequiredHostProps = ["_config"];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
@@ -100,9 +103,19 @@ export class HuiEnergyUsageGraphCard
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card>
|
<ha-card>
|
||||||
${this._config.title
|
<div class="card-header">
|
||||||
? html`<h1 class="card-header">${this._config.title}</h1>`
|
<span>${this._config.title ? this._config.title : nothing}</span>
|
||||||
: ""}
|
${this._total
|
||||||
|
? html`<hui-energy-graph-chip
|
||||||
|
.tooltip=${this._formatTotal(this._total)}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.lovelace.cards.energy.energy_usage_graph.total_usage",
|
||||||
|
{ num: formatNumber(this._total, this.hass.locale) }
|
||||||
|
)}
|
||||||
|
</hui-energy-graph-chip>`
|
||||||
|
: nothing}
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
class="content ${classMap({
|
class="content ${classMap({
|
||||||
"has-header": !!this._config.title,
|
"has-header": !!this._config.title,
|
||||||
@@ -338,6 +351,13 @@ export class HuiEnergyUsageGraphCard
|
|||||||
datasets.sort((a, b) => a.order - b.order);
|
datasets.sort((a, b) => a.order - b.order);
|
||||||
fillDataGapsAndRoundCaps(datasets);
|
fillDataGapsAndRoundCaps(datasets);
|
||||||
this._chartData = datasets;
|
this._chartData = datasets;
|
||||||
|
this._total = this._processTotal(consumption);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _processTotal(consumption: EnergyConsumptionData) {
|
||||||
|
return consumption.total.used_total > 0
|
||||||
|
? consumption.total.used_total
|
||||||
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _processDataSet(
|
private _processDataSet(
|
||||||
@@ -515,6 +535,9 @@ export class HuiEnergyUsageGraphCard
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
.card-header {
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
}
|
}
|
||||||
.content {
|
.content {
|
||||||
|
|||||||
@@ -7158,6 +7158,7 @@
|
|||||||
"energy_usage_graph": {
|
"energy_usage_graph": {
|
||||||
"total_consumed": "Total consumed {num} kWh",
|
"total_consumed": "Total consumed {num} kWh",
|
||||||
"total_returned": "Total returned {num} kWh",
|
"total_returned": "Total returned {num} kWh",
|
||||||
|
"total_usage": "{num} kWh used",
|
||||||
"combined_from_grid": "Combined from grid",
|
"combined_from_grid": "Combined from grid",
|
||||||
"consumed_solar": "Consumed solar",
|
"consumed_solar": "Consumed solar",
|
||||||
"consumed_battery": "Consumed battery"
|
"consumed_battery": "Consumed battery"
|
||||||
|
|||||||
Reference in New Issue
Block a user