diff --git a/src/data/energy.ts b/src/data/energy.ts index 4110bcde82..d7a8bf63d4 100644 --- a/src/data/energy.ts +++ b/src/data/energy.ts @@ -186,8 +186,8 @@ export interface EnergyInfo { export interface EnergyValidationIssue { type: string; - identifier: string; - value?: unknown; + affected_entities: [string, unknown][]; + translation_placeholders: Record; } export interface EnergyPreferencesValidation { @@ -200,10 +200,12 @@ export const getEnergyInfo = (hass: HomeAssistant) => type: "energy/info", }); -export const getEnergyPreferenceValidation = (hass: HomeAssistant) => - hass.callWS({ +export const getEnergyPreferenceValidation = async (hass: HomeAssistant) => { + await hass.loadBackendTranslation("issues", "energy"); + return hass.callWS({ type: "energy/validate", }); +}; export const getEnergyPreferences = (hass: HomeAssistant) => hass.callWS({ diff --git a/src/panels/config/energy/components/ha-energy-validation-result.ts b/src/panels/config/energy/components/ha-energy-validation-result.ts index 4757e1f552..618c2a6aef 100644 --- a/src/panels/config/energy/components/ha-energy-validation-result.ts +++ b/src/panels/config/energy/components/ha-energy-validation-result.ts @@ -1,6 +1,5 @@ import { css, html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; -import { groupBy } from "../../../../common/util/group-by"; import "../../../../components/ha-alert"; import { EnergyValidationIssue } from "../../../../data/energy"; import { HomeAssistant } from "../../../../types"; @@ -18,46 +17,33 @@ class EnergyValidationMessage extends LitElement { return html``; } - const grouped = groupBy(this.issues, (issue) => issue.type); - - return Object.entries(grouped).map( - ([issueType, gIssues]) => html` - - ${this.hass.localize( - `ui.panel.config.energy.validation.issues.${issueType}.description`, - { currency: this.hass.config.currency } + return this.issues.map( + (issue) => html` + + ${this.hass.localize( + `component.energy.issues.${issue.type}.description`, + issue.translation_placeholders + )} + ${issue.type === "recorder_untracked" + ? html`(${this.hass.localize("ui.panel.config.common.learn_more")})` + : ""} +
    + ${issue.affected_entities.map( + ([entity, value]) => + html`
  • ${entity}${value ? html` (${value})` : ""}
  • ` )} - ${ - issueType === "recorder_untracked" - ? html`(${this.hass.localize( - "ui.panel.config.common.learn_more" - )})` - : "" - } -
      - ${gIssues.map( - (issue) => - html`
    • - ${issue.identifier}${issue.value - ? html` (${issue.value})` - : ""} -
    • ` - )} -
    - - +
+
` ); } diff --git a/src/translations/en.json b/src/translations/en.json index 2ea4881433..1b35019433 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1634,66 +1634,6 @@ "device_consumption_energy": "Device consumption energy (kWh)", "selected_stat_intro": "Select the entity that represents the device energy usage." } - }, - "validation": { - "issues": { - "entity_not_defined": { - "title": "Entity not defined", - "description": "Check the integration or your configuration that provides:" - }, - "recorder_untracked": { - "title": "Entity not tracked", - "description": "The recorder has been configured to exclude these configured entities:" - }, - "entity_unavailable": { - "title": "Entity unavailable", - "description": "The state of these configured entities are currently not available:" - }, - "entity_state_non_numeric": { - "title": "Entity has non-numeric state", - "description": "The following entities have a state that cannot be parsed as a number:" - }, - "entity_negative_state": { - "title": "Entity has a negative state", - "description": "The following entities have a negative state while a positive state is expected:" - }, - "entity_unexpected_unit_energy": { - "title": "Unexpected unit of measurement", - "description": "The following entities do not have the expected units of measurement 'Wh', 'kWh', 'MWh' or 'GJ':" - }, - "entity_unexpected_unit_gas": { - "title": "Unexpected unit of measurement", - "description": "The following entities do not have the expected units of measurement 'Wh', 'kWh', 'MWh' or 'GJ' for an energy sensor or 'm³' or 'ft³' for a gas sensor:" - }, - "entity_unexpected_unit_water": { - "title": "Unexpected unit of measurement", - "description": "The following entities do not have the expected units of measurement 'm³' or 'ft³' for a water sensor:" - }, - "entity_unexpected_unit_energy_price": { - "title": "Unexpected unit of measurement", - "description": "The following entities do not have the expected units of measurement ''{currency}/kWh'', ''{currency}/Wh'', ''{currency}/MWh'' or ''{currency}/GJ'':" - }, - "entity_unexpected_unit_gas_price": { - "title": "Unexpected unit of measurement", - "description": "The following entities do not have the expected units of measurement ''{currency}/kWh'', ''{currency}/Wh'', ''{currency}/MWh'', ''{currency}/GJ'', ''{currency}/m³'' or ''{currency}/ft³'':" - }, - "entity_unexpected_unit_water_price": { - "title": "Unexpected unit of measurement", - "description": "The following entities do not have the expected units of measurement ''{currency}/m³'' or ''{currency}/ft³'':" - }, - "entity_unexpected_state_class": { - "title": "Unexpected state class", - "description": "The following entities do not have the expected state class:" - }, - "entity_unexpected_device_class": { - "title": "Unexpected device class", - "description": "The following entities do not have the expected device class:" - }, - "entity_state_class_measurement_no_last_reset": { - "title": "Last reset missing", - "description": "The following entities have state class 'measurement' but 'last_reset' is missing:" - } - } } }, "helpers": {