diff --git a/src/common/entity/compute_attribute_display.ts b/src/common/entity/compute_attribute_display.ts index 7cba3466f7..c1079d70c1 100644 --- a/src/common/entity/compute_attribute_display.ts +++ b/src/common/entity/compute_attribute_display.ts @@ -12,6 +12,7 @@ export const computeAttributeValueDisplay = ( value?: any ): string => { const entityId = stateObj.entity_id; + const deviceClass = stateObj.attributes.device_class; const attributeValue = value !== undefined ? value : stateObj.attributes[attribute]; const domain = computeDomain(entityId); @@ -23,8 +24,12 @@ export const computeAttributeValueDisplay = ( localize( `component.${entity.platform}.entity.${domain}.${translationKey}.state_attributes.${attribute}.state.${attributeValue}` )) || + (deviceClass && + localize( + `component.${domain}.entity_component.${deviceClass}.state_attributes.${attribute}.state.${attributeValue}` + )) || localize( - `component.${domain}.state_attributes._.${attribute}.state.${attributeValue}` + `component.${domain}.entity_component._.state_attributes.${attribute}.state.${attributeValue}` ) || attributeValue ); @@ -37,6 +42,7 @@ export const computeAttributeNameDisplay = ( attribute: string ): string => { const entityId = stateObj.entity_id; + const deviceClass = stateObj.attributes.device_class; const domain = computeDomain(entityId); const entity = entities[entityId] as EntityRegistryDisplayEntry | undefined; const translationKey = entity?.translation_key; @@ -46,7 +52,13 @@ export const computeAttributeNameDisplay = ( localize( `component.${entity.platform}.entity.${domain}.${translationKey}.state_attributes.${attribute}.name` )) || - localize(`component.${domain}.state_attributes._.${attribute}.name`) || + (deviceClass && + localize( + `component.${domain}.entity_component.${deviceClass}.state_attributes.${attribute}.name` + )) || + localize( + `component.${domain}.entity_component._.state_attributes.${attribute}.name` + ) || attribute ); }; diff --git a/src/common/entity/compute_state_display.ts b/src/common/entity/compute_state_display.ts index 930d8added..ee1326f291 100644 --- a/src/common/entity/compute_state_display.ts +++ b/src/common/entity/compute_state_display.ts @@ -214,10 +214,10 @@ export const computeStateDisplayFromEntityAttributes = ( // Return device class translation (attributes.device_class && localize( - `component.${domain}.state.${attributes.device_class}.${state}` + `component.${domain}.entity_component.${attributes.device_class}.state.${state}` )) || // Return default translation - localize(`component.${domain}.state._.${state}`) || + localize(`component.${domain}.entity_component._.state.${state}`) || // We don't know! Return the raw state. state ); diff --git a/src/components/ha-vacuum-state.js b/src/components/ha-vacuum-state.js index da4ab54acd..371de7b4f5 100644 --- a/src/components/ha-vacuum-state.js +++ b/src/components/ha-vacuum-state.js @@ -76,7 +76,7 @@ class HaVacuumState extends LocalizeMixin(PolymerElement) { ? this.localize( `ui.card.vacuum.actions.${STATES_INTERCEPTABLE[state].action}` ) - : this.localize(`component.vacuum._.${state}`); + : this.localize(`component.vacuum.entity_component._.state.${state}`); } _callService(ev) { diff --git a/src/data/translation.ts b/src/data/translation.ts index b0030c0605..382c5a804d 100644 --- a/src/data/translation.ts +++ b/src/data/translation.ts @@ -44,8 +44,8 @@ declare global { export type TranslationCategory = | "title" | "state" - | "state_attributes" | "entity" + | "entity_component" | "config" | "config_panel" | "options" diff --git a/src/dialogs/more-info/controls/more-info-vacuum.ts b/src/dialogs/more-info/controls/more-info-vacuum.ts index c734e0160c..541a13d865 100644 --- a/src/dialogs/more-info/controls/more-info-vacuum.ts +++ b/src/dialogs/more-info/controls/more-info-vacuum.ts @@ -115,7 +115,7 @@ class MoreInfoVacuum extends LitElement { ${stateObj.attributes.status || this.hass.localize( - `component.vacuum.state._.${stateObj.state}` + `component.vacuum.entity_component._.state.${stateObj.state}` ) || stateObj.state} diff --git a/src/dialogs/more-info/controls/more-info-water_heater.js b/src/dialogs/more-info/controls/more-info-water_heater.js index a48c3b4118..bc7c673d41 100644 --- a/src/dialogs/more-info/controls/more-info-water_heater.js +++ b/src/dialogs/more-info/controls/more-info-water_heater.js @@ -225,7 +225,10 @@ class MoreInfoWaterHeater extends LocalizeMixin(EventsMixin(PolymerElement)) { } _localizeOperationMode(localize, mode) { - return localize(`component.water_heater.state._.${mode}`) || mode; + return ( + localize(`component.water_heater.entity_component._.state.${mode}`) || + mode + ); } } diff --git a/src/layouts/home-assistant.ts b/src/layouts/home-assistant.ts index a09b1441cb..bcd99b762d 100644 --- a/src/layouts/home-assistant.ts +++ b/src/layouts/home-assistant.ts @@ -136,12 +136,14 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) { protected hassConnected() { super.hassConnected(); // @ts-ignore - this._loadHassTranslations(this.hass!.language, "state"); - // @ts-ignore - this._loadHassTranslations(this.hass!.language, "state_attributes"); + this._loadHassTranslations(this.hass!.language, "entity_component"); // @ts-ignore this._loadHassTranslations(this.hass!.language, "entity"); + // Backwards compatibility for custom integrations + // @ts-ignore + this._loadHassTranslations(this.hass!.language, "state"); + document.addEventListener( "visibilitychange", () => this._checkVisibility(), diff --git a/src/panels/lovelace/cards/hui-alarm-panel-card.ts b/src/panels/lovelace/cards/hui-alarm-panel-card.ts index 165fb8ed8a..b35235bd2d 100644 --- a/src/panels/lovelace/cards/hui-alarm-panel-card.ts +++ b/src/panels/lovelace/cards/hui-alarm-panel-card.ts @@ -236,7 +236,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard { return entityState === UNAVAILABLE ? this.hass!.localize("state.default.unavailable") : this.hass!.localize( - `component.alarm_control_panel.state._.${entityState}` + `component.alarm_control_panel.entity_component._.state.${entityState}` ) || entityState; } diff --git a/src/panels/lovelace/cards/hui-thermostat-card.ts b/src/panels/lovelace/cards/hui-thermostat-card.ts index dbeb47db18..e9daa3ccc5 100644 --- a/src/panels/lovelace/cards/hui-thermostat-card.ts +++ b/src/panels/lovelace/cards/hui-thermostat-card.ts @@ -478,7 +478,9 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard { @click=${this._handleAction} tabindex="0" .path=${modeIcons[mode]} - .label=${this.hass!.localize(`component.climate.state._.${mode}`)} + .label=${this.hass!.localize( + `component.climate.entity_component._.state.${mode}` + ) || mode} > `; diff --git a/test/common/entity/compute_state_display.ts b/test/common/entity/compute_state_display.ts index 26284d5af9..ff3a30a599 100644 --- a/test/common/entity/compute_state_display.ts +++ b/test/common/entity/compute_state_display.ts @@ -32,7 +32,7 @@ describe("computeStateDisplay", () => { }; assert.strictEqual( computeStateDisplay(localize, stateObj, localeData, {}), - "component.binary_sensor.state._.off" + "component.binary_sensor.entity_component._.state.off" ); }); @@ -154,7 +154,9 @@ describe("computeStateDisplay", () => { it("Localizes sensor value with component translation", () => { const altLocalize = (message, ...args) => { - if (message !== "component.sensor.state._.custom_state") { + if ( + message !== "component.sensor.entity_component._.state.custom_state" + ) { return ""; } return localize(message, ...args); @@ -166,7 +168,7 @@ describe("computeStateDisplay", () => { }; assert.strictEqual( computeStateDisplay(altLocalize, stateObj, localeData, {}), - "component.sensor.state._.custom_state" + "component.sensor.entity_component._.state.custom_state" ); });