From d844c5b8948848ff6944fa05842f4a6badb9fb10 Mon Sep 17 00:00:00 2001 From: Matthias de Baat Date: Mon, 16 Feb 2026 11:52:24 +0100 Subject: [PATCH] Make energy config page consistent (#29452) * Make energy config page consistent * Update src/translations/en.json Co-authored-by: Norbert Rittel * small tweaks --------- Co-authored-by: Norbert Rittel Co-authored-by: Petar Petrov --- .../components/ha-energy-battery-settings.ts | 102 +++++----- .../ha-energy-device-settings-water.ts | 87 ++++----- .../components/ha-energy-device-settings.ts | 87 ++++----- .../components/ha-energy-gas-settings.ts | 81 ++++---- .../components/ha-energy-grid-settings.ts | 175 +++++++++--------- .../components/ha-energy-solar-settings.ts | 94 +++++----- .../components/ha-energy-water-settings.ts | 83 +++++---- src/panels/config/energy/components/styles.ts | 23 ++- src/panels/config/energy/ha-config-energy.ts | 27 ++- src/translations/en.json | 2 +- 10 files changed, 401 insertions(+), 360 deletions(-) diff --git a/src/panels/config/energy/components/ha-energy-battery-settings.ts b/src/panels/config/energy/components/ha-energy-battery-settings.ts index d38be1d75d..c35276faeb 100644 --- a/src/panels/config/energy/components/ha-energy-battery-settings.ts +++ b/src/panels/config/energy/components/ha-energy-battery-settings.ts @@ -57,7 +57,7 @@ export class EnergyBatterySettings extends LitElement { }); return html` - +

${this.hass.localize("ui.panel.config.energy.battery.title")} @@ -83,56 +83,58 @@ export class EnergyBatterySettings extends LitElement { > ` )} - -

- ${this.hass.localize( - "ui.panel.config.energy.battery.battery_systems" - )} -

- ${batterySources.map((source) => { - const toEntityState = this.hass.states[source.stat_energy_to]; - return html` -
- ${toEntityState?.attributes.icon - ? html`` - : html``} -
- ${getStatisticLabel( - this.hass, - source.stat_energy_from, - this.statsMetadata?.[source.stat_energy_from] - )} - ${getStatisticLabel( - this.hass, - source.stat_energy_to, - this.statsMetadata?.[source.stat_energy_to] - )} + ${batterySources.length > 0 + ? html` +
+ ${batterySources.map((source) => { + const toEntityState = + this.hass.states[source.stat_energy_to]; + return html` +
+ ${toEntityState?.attributes.icon + ? html`` + : html``} +
+ ${getStatisticLabel( + this.hass, + source.stat_energy_from, + this.statsMetadata?.[source.stat_energy_from] + )} + ${getStatisticLabel( + this.hass, + source.stat_energy_to, + this.statsMetadata?.[source.stat_energy_to] + )} +
+ + +
+ `; + })}
- - -
- `; - })} -
- + ` + : ""} +
+

${this.hass.localize( @@ -82,49 +82,52 @@ export class EnergyDeviceSettingsWater extends LitElement { > ` )} -

- ${this.hass.localize( - "ui.panel.config.energy.device_consumption_water.devices" - )} -

- -
- ${repeat( - this.preferences.device_consumption_water, - (device) => device.stat_consumption, - (device) => html` -
-
- + ${this.preferences.device_consumption_water.length > 0 + ? html` +
+ +
+ ${repeat( + this.preferences.device_consumption_water, + (device) => device.stat_consumption, + (device) => html` +
+
+ +
+ ${device.name || + getStatisticLabel( + this.hass, + device.stat_consumption, + this.statsMetadata?.[device.stat_consumption] + )} + + +
+ ` + )}
- ${device.name || - getStatisticLabel( - this.hass, - device.stat_consumption, - this.statsMetadata?.[device.stat_consumption] - )} - - -
- ` - )} -
- + +
+ ` + : ""}
- +

${this.hass.localize( @@ -82,49 +82,52 @@ export class EnergyDeviceSettings extends LitElement { > ` )} -

- ${this.hass.localize( - "ui.panel.config.energy.device_consumption.devices" - )} -

- -
- ${repeat( - this.preferences.device_consumption, - (device) => device.stat_consumption, - (device) => html` -
-
- + ${this.preferences.device_consumption.length > 0 + ? html` +
+ +
+ ${repeat( + this.preferences.device_consumption, + (device) => device.stat_consumption, + (device) => html` +
+
+ +
+ ${device.name || + getStatisticLabel( + this.hass, + device.stat_consumption, + this.statsMetadata?.[device.stat_consumption] + )} + + +
+ ` + )}
- ${device.name || - getStatisticLabel( - this.hass, - device.stat_consumption, - this.statsMetadata?.[device.stat_consumption] - )} - - -
- ` - )} -
- + +
+ ` + : ""}
- +

${this.hass.localize("ui.panel.config.energy.gas.title")} @@ -82,44 +82,47 @@ export class EnergyGasSettings extends LitElement { > ` )} -

- ${this.hass.localize("ui.panel.config.energy.gas.gas_consumption")} -

- ${gasSources.map((source) => { - const entityState = this.hass.states[source.stat_energy_from]; - return html` -
- ${entityState?.attributes.icon - ? html`` - : html``} - ${getStatisticLabel( - this.hass, - source.stat_energy_from, - this.statsMetadata?.[source.stat_energy_from] - )} - - -
- `; - })} -
- + ${gasSources.length > 0 + ? html` +
+ ${gasSources.map((source) => { + const entityState = + this.hass.states[source.stat_energy_from]; + return html` +
+ ${entityState?.attributes.icon + ? html`` + : html``} + ${getStatisticLabel( + this.hass, + source.stat_energy_from, + this.statsMetadata?.[source.stat_energy_from] + )} + + +
+ `; + })} +
+ ` + : ""} +
+

${this.hass.localize("ui.panel.config.energy.grid.title")} @@ -104,58 +104,63 @@ export class EnergyGridSettings extends LitElement { "ui.panel.config.energy.grid.grid_connections" )}

- ${gridSources.map((source, idx) => { - // At least one of import/export/power must exist (enforced by validation) - const primaryStat = (source.stat_energy_from || - source.stat_energy_to || - source.stat_rate)!; - const primaryEntityState = this.hass.states[primaryStat]; - return html` -
- ${primaryEntityState?.attributes.icon - ? html`` - : html``} -
- ${getStatisticLabel( - this.hass, - primaryStat, - this.statsMetadata?.[primaryStat] - )} - ${source.stat_energy_from && source.stat_energy_to - ? html`${getStatisticLabel( - this.hass, - source.stat_energy_to, - this.statsMetadata?.[source.stat_energy_to] - )}` - : nothing} + ${gridSources.length > 0 + ? html` +
+ ${gridSources.map((source, idx) => { + // At least one of import/export/power must exist (enforced by validation) + const primaryStat = (source.stat_energy_from || + source.stat_energy_to || + source.stat_rate)!; + const primaryEntityState = this.hass.states[primaryStat]; + return html` +
+ ${primaryEntityState?.attributes.icon + ? html`` + : html``} +
+ ${getStatisticLabel( + this.hass, + primaryStat, + this.statsMetadata?.[primaryStat] + )} + ${source.stat_energy_from && source.stat_energy_to + ? html`${getStatisticLabel( + this.hass, + source.stat_energy_to, + this.statsMetadata?.[source.stat_energy_to] + )}` + : nothing} +
+ + +
+ `; + })}
- - -
- `; - })} -
- + ` + : nothing} +
${this._co2ConfigEntry - ? html`
- - ${this._co2ConfigEntry.title} - - - - -
` + ? html` +
+
+ + ${this._co2ConfigEntry.title} + + + + +
+
+ ` : html` -
- +
+

${this.hass.localize("ui.panel.config.energy.solar.title")} @@ -85,53 +85,55 @@ export class EnergySolarSettings extends LitElement { > ` )} - -

- ${this.hass.localize( - "ui.panel.config.energy.solar.solar_production" - )} -

- ${solarSources.map((source) => { - const entityState = this.hass.states[source.stat_energy_from]; - return html` -
- ${entityState?.attributes.icon - ? html`` - : html``} - ${getStatisticLabel( - this.hass, - source.stat_energy_from, - this.statsMetadata?.[source.stat_energy_from] - )} - ${this.info - ? html` - - ` - : ""} - -
- `; - })} + ${solarSources.length > 0 + ? html` +
+ ${solarSources.map((source) => { + const entityState = + this.hass.states[source.stat_energy_from]; + return html` +
+ ${entityState?.attributes.icon + ? html`` + : html``} + ${getStatisticLabel( + this.hass, + source.stat_energy_from, + this.statsMetadata?.[source.stat_energy_from] + )} + ${this.info + ? html` + + ` + : ""} + +
+ `; + })} +
+ ` + : ""} ${this.info ? html` -
- +
+

${this.hass.localize("ui.panel.config.energy.water.title")} @@ -81,46 +81,47 @@ export class EnergyWaterSettings extends LitElement { > ` )} -

- ${this.hass.localize( - "ui.panel.config.energy.water.water_consumption" - )} -

- ${waterSources.map((source) => { - const entityState = this.hass.states[source.stat_energy_from]; - return html` -
- ${entityState?.attributes.icon - ? html`` - : html``} - ${getStatisticLabel( - this.hass, - source.stat_energy_from, - this.statsMetadata?.[source.stat_energy_from] - )} - - -
- `; - })} -
- + ${waterSources.length > 0 + ? html` +
+ ${waterSources.map((source) => { + const entityState = + this.hass.states[source.stat_energy_from]; + return html` +
+ ${entityState?.attributes.icon + ? html`` + : html``} + ${getStatisticLabel( + this.hass, + source.stat_energy_from, + this.statsMetadata?.[source.stat_energy_from] + )} + + +
+ `; + })} +
+ ` + : ""} +
${this.hass.localize("ui.panel.config.energy.new_device_info")} -
+