Skip to content

Commit ec98b21

Browse files
authored
Highlight problematic devices in Energy Dashboard list (#52088)
1 parent defad3b commit ec98b21

2 files changed

Lines changed: 76 additions & 4 deletions

File tree

src/panels/config/energy/components/ha-energy-device-settings-water.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
2+
mdiAlertCircle,
23
mdiDelete,
34
mdiWater,
45
mdiDragHorizontalVariant,
56
mdiPencil,
67
mdiPlus,
78
} from "@mdi/js";
89
import type { CSSResultGroup, TemplateResult } from "lit";
9-
import { css, html, LitElement } from "lit";
10+
import { css, html, LitElement, nothing } from "lit";
1011
import { repeat } from "lit/directives/repeat";
1112
import { customElement, property } from "lit/decorators";
1213
import { fireEvent } from "../../../../common/dom/fire_event";
@@ -15,10 +16,12 @@ import "../../../../components/ha-button";
1516
import "../../../../components/ha-icon-button";
1617
import "../../../../components/ha-sortable";
1718
import "../../../../components/ha-svg-icon";
19+
import "../../../../components/ha-tooltip";
1820
import type {
1921
DeviceConsumptionEnergyPreference,
2022
EnergyPreferences,
2123
EnergyPreferencesValidation,
24+
EnergyValidationIssue,
2225
} from "../../../../data/energy";
2326
import { saveEnergyPreferences } from "../../../../data/energy";
2427
import type { StatisticsMetaData } from "../../../../data/recorder";
@@ -93,7 +96,7 @@ export class EnergyDeviceSettingsWater extends LitElement {
9396
${repeat(
9497
this.preferences.device_consumption_water,
9598
(device) => device.stat_consumption,
96-
(device) => html`
99+
(device, index) => html`
97100
<div class="row" .device=${device}>
98101
<div class="handle">
99102
<ha-svg-icon
@@ -108,6 +111,12 @@ export class EnergyDeviceSettingsWater extends LitElement {
108111
this.statsMetadata?.[device.stat_consumption]
109112
)}</span
110113
>
114+
${this._renderIssueIndicator(
115+
this.validationResult?.device_consumption_water[
116+
index
117+
],
118+
index
119+
)}
111120
<ha-icon-button
112121
.label=${this.hass.localize("ui.common.edit")}
113122
@click=${this._editDevice}
@@ -144,6 +153,31 @@ export class EnergyDeviceSettingsWater extends LitElement {
144153
`;
145154
}
146155

156+
private _renderIssueIndicator(
157+
issues: EnergyValidationIssue[] | undefined,
158+
index: number
159+
) {
160+
if (!issues?.length) {
161+
return nothing;
162+
}
163+
const titles = issues.map(
164+
(issue) =>
165+
this.hass.localize(`component.energy.issues.${issue.type}.title`) ||
166+
issue.type
167+
);
168+
const label = titles.join("\n");
169+
const id = `issue-icon-${index}`;
170+
return html`
171+
<ha-svg-icon
172+
id=${id}
173+
class="issue-icon"
174+
.path=${mdiAlertCircle}
175+
aria-label=${label}
176+
></ha-svg-icon>
177+
<ha-tooltip .for=${id} placement="top">${label}</ha-tooltip>
178+
`;
179+
}
180+
147181
private _itemMoved(ev: CustomEvent): void {
148182
ev.stopPropagation();
149183
const { oldIndex, newIndex } = ev.detail;
@@ -248,6 +282,9 @@ export class EnergyDeviceSettingsWater extends LitElement {
248282
cursor: move; /* fallback if grab cursor is unsupported */
249283
cursor: grab;
250284
}
285+
.issue-icon {
286+
color: var(--warning-color);
287+
}
251288
`,
252289
];
253290
}

src/panels/config/energy/components/ha-energy-device-settings.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
2+
mdiAlertCircle,
23
mdiDelete,
34
mdiDevices,
45
mdiDragHorizontalVariant,
56
mdiPencil,
67
mdiPlus,
78
} from "@mdi/js";
89
import type { CSSResultGroup, TemplateResult } from "lit";
9-
import { css, html, LitElement } from "lit";
10+
import { css, html, LitElement, nothing } from "lit";
1011
import { repeat } from "lit/directives/repeat";
1112
import { customElement, property } from "lit/decorators";
1213
import { fireEvent } from "../../../../common/dom/fire_event";
@@ -15,10 +16,12 @@ import "../../../../components/ha-button";
1516
import "../../../../components/ha-icon-button";
1617
import "../../../../components/ha-sortable";
1718
import "../../../../components/ha-svg-icon";
19+
import "../../../../components/ha-tooltip";
1820
import type {
1921
DeviceConsumptionEnergyPreference,
2022
EnergyPreferences,
2123
EnergyPreferencesValidation,
24+
EnergyValidationIssue,
2225
} from "../../../../data/energy";
2326
import { saveEnergyPreferences } from "../../../../data/energy";
2427
import type { StatisticsMetaData } from "../../../../data/recorder";
@@ -93,7 +96,7 @@ export class EnergyDeviceSettings extends LitElement {
9396
${repeat(
9497
this.preferences.device_consumption,
9598
(device) => device.stat_consumption,
96-
(device) => html`
99+
(device, index) => html`
97100
<div class="row" .device=${device}>
98101
<div class="handle">
99102
<ha-svg-icon
@@ -108,6 +111,10 @@ export class EnergyDeviceSettings extends LitElement {
108111
this.statsMetadata?.[device.stat_consumption]
109112
)}</span
110113
>
114+
${this._renderIssueIndicator(
115+
this.validationResult?.device_consumption[index],
116+
index
117+
)}
111118
<ha-icon-button
112119
.label=${this.hass.localize("ui.common.edit")}
113120
@click=${this._editDevice}
@@ -144,6 +151,31 @@ export class EnergyDeviceSettings extends LitElement {
144151
`;
145152
}
146153

154+
private _renderIssueIndicator(
155+
issues: EnergyValidationIssue[] | undefined,
156+
index: number
157+
) {
158+
if (!issues?.length) {
159+
return nothing;
160+
}
161+
const titles = issues.map(
162+
(issue) =>
163+
this.hass.localize(`component.energy.issues.${issue.type}.title`) ||
164+
issue.type
165+
);
166+
const label = titles.join("\n");
167+
const id = `issue-icon-${index}`;
168+
return html`
169+
<ha-svg-icon
170+
id=${id}
171+
class="issue-icon"
172+
.path=${mdiAlertCircle}
173+
aria-label=${label}
174+
></ha-svg-icon>
175+
<ha-tooltip .for=${id} placement="top">${label}</ha-tooltip>
176+
`;
177+
}
178+
147179
private _itemMoved(ev: CustomEvent): void {
148180
ev.stopPropagation();
149181
const { oldIndex, newIndex } = ev.detail;
@@ -244,6 +276,9 @@ export class EnergyDeviceSettings extends LitElement {
244276
cursor: move; /* fallback if grab cursor is unsupported */
245277
cursor: grab;
246278
}
279+
.issue-icon {
280+
color: var(--warning-color);
281+
}
247282
`,
248283
];
249284
}

0 commit comments

Comments
 (0)