mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-10 10:56:34 +00:00
Add support for entity translation key (#14482)
This commit is contained in:
parent
dff7f653b1
commit
dfc461ce05
@ -307,7 +307,8 @@ export class DemoEntityState extends LitElement {
|
|||||||
html`${computeStateDisplay(
|
html`${computeStateDisplay(
|
||||||
hass.localize,
|
hass.localize,
|
||||||
entry.stateObj,
|
entry.stateObj,
|
||||||
hass.locale
|
hass.locale,
|
||||||
|
hass.entities
|
||||||
)}`,
|
)}`,
|
||||||
},
|
},
|
||||||
device_class: {
|
device_class: {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||||
|
import { EntityRegistryEntry } from "../../data/entity_registry";
|
||||||
import { FrontendLocaleData } from "../../data/translation";
|
import { FrontendLocaleData } from "../../data/translation";
|
||||||
import {
|
import {
|
||||||
updateIsInstallingFromAttributes,
|
updateIsInstallingFromAttributes,
|
||||||
UPDATE_SUPPORT_PROGRESS,
|
UPDATE_SUPPORT_PROGRESS,
|
||||||
} from "../../data/update";
|
} from "../../data/update";
|
||||||
|
import { HomeAssistant } from "../../types";
|
||||||
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
||||||
import { formatDate } from "../datetime/format_date";
|
import { formatDate } from "../datetime/format_date";
|
||||||
import { formatDateTime } from "../datetime/format_date_time";
|
import { formatDateTime } from "../datetime/format_date_time";
|
||||||
@ -23,11 +25,13 @@ export const computeStateDisplay = (
|
|||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
stateObj: HassEntity,
|
stateObj: HassEntity,
|
||||||
locale: FrontendLocaleData,
|
locale: FrontendLocaleData,
|
||||||
|
entities: HomeAssistant["entities"],
|
||||||
state?: string
|
state?: string
|
||||||
): string =>
|
): string =>
|
||||||
computeStateDisplayFromEntityAttributes(
|
computeStateDisplayFromEntityAttributes(
|
||||||
localize,
|
localize,
|
||||||
locale,
|
locale,
|
||||||
|
entities,
|
||||||
stateObj.entity_id,
|
stateObj.entity_id,
|
||||||
stateObj.attributes,
|
stateObj.attributes,
|
||||||
state !== undefined ? state : stateObj.state
|
state !== undefined ? state : stateObj.state
|
||||||
@ -36,6 +40,7 @@ export const computeStateDisplay = (
|
|||||||
export const computeStateDisplayFromEntityAttributes = (
|
export const computeStateDisplayFromEntityAttributes = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
locale: FrontendLocaleData,
|
locale: FrontendLocaleData,
|
||||||
|
entities: HomeAssistant["entities"],
|
||||||
entityId: string,
|
entityId: string,
|
||||||
attributes: any,
|
attributes: any,
|
||||||
state: string
|
state: string
|
||||||
@ -194,7 +199,13 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
: localize("ui.card.update.up_to_date");
|
: localize("ui.card.update.up_to_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const entity = entities[entityId] as EntityRegistryEntry | undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
(entity?.translation_key &&
|
||||||
|
localize(
|
||||||
|
`component.${entity.platform}.entity.${domain}.${entity.translation_key}.state.${state}`
|
||||||
|
)) ||
|
||||||
// Return device class translation
|
// Return device class translation
|
||||||
(attributes.device_class &&
|
(attributes.device_class &&
|
||||||
localize(
|
localize(
|
||||||
|
@ -55,6 +55,7 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
state,
|
state,
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
|
this.hass.entities,
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
: formatAttributeValue(this.hass, key),
|
: formatAttributeValue(this.hass, key),
|
||||||
|
@ -158,7 +158,8 @@ export class HaStateLabelBadge extends LitElement {
|
|||||||
: computeStateDisplay(
|
: computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
entityState,
|
entityState,
|
||||||
this.hass!.locale
|
this.hass!.locale,
|
||||||
|
this.hass!.entities
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,12 @@ class HaWaterHeaterState extends LocalizeMixin(PolymerElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_localizeState(stateObj) {
|
_localizeState(stateObj) {
|
||||||
return computeStateDisplay(this.hass.localize, stateObj, this.hass.locale);
|
return computeStateDisplay(
|
||||||
|
this.hass.localize,
|
||||||
|
stateObj,
|
||||||
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
customElements.define("ha-water_heater-state", HaWaterHeaterState);
|
customElements.define("ha-water_heater-state", HaWaterHeaterState);
|
||||||
|
@ -21,6 +21,7 @@ export interface EntityRegistryEntry {
|
|||||||
has_entity_name: boolean;
|
has_entity_name: boolean;
|
||||||
original_name?: string;
|
original_name?: string;
|
||||||
unique_id: string;
|
unique_id: string;
|
||||||
|
translation_key?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
||||||
|
@ -184,6 +184,7 @@ const equalState = (obj1: LineChartState, obj2: LineChartState) =>
|
|||||||
const processTimelineEntity = (
|
const processTimelineEntity = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
language: FrontendLocaleData,
|
language: FrontendLocaleData,
|
||||||
|
entities: HomeAssistant["entities"],
|
||||||
entityId: string,
|
entityId: string,
|
||||||
states: EntityHistoryState[],
|
states: EntityHistoryState[],
|
||||||
current_state: HassEntity | undefined
|
current_state: HassEntity | undefined
|
||||||
@ -198,6 +199,7 @@ const processTimelineEntity = (
|
|||||||
state_localize: computeStateDisplayFromEntityAttributes(
|
state_localize: computeStateDisplayFromEntityAttributes(
|
||||||
localize,
|
localize,
|
||||||
language,
|
language,
|
||||||
|
entities,
|
||||||
entityId,
|
entityId,
|
||||||
state.a || first.a,
|
state.a || first.a,
|
||||||
state.s
|
state.s
|
||||||
@ -344,6 +346,7 @@ export const computeHistory = (
|
|||||||
processTimelineEntity(
|
processTimelineEntity(
|
||||||
localize,
|
localize,
|
||||||
hass.locale,
|
hass.locale,
|
||||||
|
hass.entities,
|
||||||
entityId,
|
entityId,
|
||||||
stateInfo,
|
stateInfo,
|
||||||
currentState
|
currentState
|
||||||
|
@ -435,7 +435,13 @@ export const localizeStateMessage = (
|
|||||||
`${LOGBOOK_LOCALIZE_PATH}.changed_to_state`,
|
`${LOGBOOK_LOCALIZE_PATH}.changed_to_state`,
|
||||||
"state",
|
"state",
|
||||||
stateObj
|
stateObj
|
||||||
? computeStateDisplay(localize, stateObj, hass.locale, state)
|
? computeStateDisplay(
|
||||||
|
localize,
|
||||||
|
stateObj,
|
||||||
|
hass.locale,
|
||||||
|
hass.entities,
|
||||||
|
state
|
||||||
|
)
|
||||||
: state
|
: state
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -90,7 +90,12 @@ export const computeDisplayTimer = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stateObj.state === "idle" || timeRemaining === 0) {
|
if (stateObj.state === "idle" || timeRemaining === 0) {
|
||||||
return computeStateDisplay(hass.localize, stateObj, hass.locale);
|
return computeStateDisplay(
|
||||||
|
hass.localize,
|
||||||
|
stateObj,
|
||||||
|
hass.locale,
|
||||||
|
hass.entities
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let display = secondsToDuration(timeRemaining || 0);
|
let display = secondsToDuration(timeRemaining || 0);
|
||||||
@ -99,7 +104,8 @@ export const computeDisplayTimer = (
|
|||||||
display = `${display} (${computeStateDisplay(
|
display = `${display} (${computeStateDisplay(
|
||||||
hass.localize,
|
hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
hass.locale
|
hass.locale,
|
||||||
|
hass.entities
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ declare global {
|
|||||||
export type TranslationCategory =
|
export type TranslationCategory =
|
||||||
| "title"
|
| "title"
|
||||||
| "state"
|
| "state"
|
||||||
|
| "entity"
|
||||||
| "config"
|
| "config"
|
||||||
| "config_panel"
|
| "config_panel"
|
||||||
| "options"
|
| "options"
|
||||||
|
@ -37,7 +37,8 @@ export class HuiConfiguratorNotificationItem extends LitElement {
|
|||||||
>${computeStateDisplay(
|
>${computeStateDisplay(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
this.notification,
|
this.notification,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)}</mwc-button
|
)}</mwc-button
|
||||||
>
|
>
|
||||||
</notification-item-template>
|
</notification-item-template>
|
||||||
|
@ -307,7 +307,9 @@ export const provideHass = (
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
areas: {},
|
||||||
|
devices: {},
|
||||||
|
entities: {},
|
||||||
...overrideData,
|
...overrideData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -137,6 +137,8 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
super.hassConnected();
|
super.hassConnected();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this._loadHassTranslations(this.hass!.language, "state");
|
this._loadHassTranslations(this.hass!.language, "state");
|
||||||
|
// @ts-ignore
|
||||||
|
this._loadHassTranslations(this.hass!.language, "entity");
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"visibilitychange",
|
"visibilitychange",
|
||||||
|
@ -205,7 +205,8 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
|||||||
${computeStateDisplay(
|
${computeStateDisplay(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)}
|
)}
|
||||||
</span>`
|
</span>`
|
||||||
: ""}
|
: ""}
|
||||||
|
@ -167,7 +167,8 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
|
|||||||
: computeStateDisplay(
|
: computeStateDisplay(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)}</span
|
)}</span
|
||||||
>${showUnit
|
>${showUnit
|
||||||
? html`
|
? html`
|
||||||
|
@ -335,7 +335,8 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
|||||||
: computeStateDisplay(
|
: computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass!.locale
|
this.hass!.locale,
|
||||||
|
this.hass!.entities
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
@ -160,7 +160,8 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
${computeStateDisplay(
|
${computeStateDisplay(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
@ -121,7 +121,8 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
|
|||||||
const entityState = computeStateDisplay(
|
const entityState = computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
);
|
);
|
||||||
|
|
||||||
let footer: TemplateResult | string = "";
|
let footer: TemplateResult | string = "";
|
||||||
|
@ -255,7 +255,8 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
|
|||||||
title=${`${computeStateName(stateObj)} : ${computeStateDisplay(
|
title=${`${computeStateName(stateObj)} : ${computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass!.locale
|
this.hass!.locale,
|
||||||
|
this.hass!.entities
|
||||||
)}`}
|
)}`}
|
||||||
>
|
>
|
||||||
<ha-state-icon
|
<ha-state-icon
|
||||||
@ -277,7 +278,8 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
|
|||||||
: computeStateDisplay(
|
: computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass!.locale
|
this.hass!.locale,
|
||||||
|
this.hass!.entities
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
|
@ -201,7 +201,8 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
|
|||||||
return computeStateDisplay(
|
return computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass!.locale
|
this.hass!.locale,
|
||||||
|
this.hass!.entities
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,8 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
|||||||
${computeStateDisplay(
|
${computeStateDisplay(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div class="name" .title=${name}>${name}</div>
|
<div class="name" .title=${name}>${name}</div>
|
||||||
|
@ -83,7 +83,12 @@ class HuiStateLabelElement extends LitElement implements LovelaceElement {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
${this._config.prefix}${!this._config.attribute
|
${this._config.prefix}${!this._config.attribute
|
||||||
? computeStateDisplay(this.hass.localize, stateObj, this.hass.locale)
|
? computeStateDisplay(
|
||||||
|
this.hass.localize,
|
||||||
|
stateObj,
|
||||||
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
|
)
|
||||||
: stateObj.attributes[this._config.attribute]}${this._config.suffix}
|
: stateObj.attributes[this._config.attribute]}${this._config.suffix}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -69,7 +69,8 @@ class HuiGroupEntityRow extends LitElement implements LovelaceRow {
|
|||||||
${computeStateDisplay(
|
${computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
|
@ -100,6 +100,7 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
|
|||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
|
this.hass.entities,
|
||||||
stateObj.state
|
stateObj.state
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
@ -193,7 +193,12 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.config=${this._config}
|
.config=${this._config}
|
||||||
.secondaryText=${mediaDescription ||
|
.secondaryText=${mediaDescription ||
|
||||||
computeStateDisplay(this.hass.localize, stateObj, this.hass.locale)}
|
computeStateDisplay(
|
||||||
|
this.hass.localize,
|
||||||
|
stateObj,
|
||||||
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
${supportsFeature(stateObj, SUPPORT_TURN_ON) &&
|
${supportsFeature(stateObj, SUPPORT_TURN_ON) &&
|
||||||
|
@ -104,6 +104,7 @@ class HuiNumberEntityRow extends LitElement implements LovelaceRow {
|
|||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
|
this.hass.entities,
|
||||||
stateObj.state
|
stateObj.state
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
@ -83,7 +83,8 @@ class HuiSensorEntityRow extends LitElement implements LovelaceRow {
|
|||||||
: computeStateDisplay(
|
: computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</hui-generic-entity-row>
|
</hui-generic-entity-row>
|
||||||
|
@ -49,7 +49,12 @@ class HuiSimpleEntityRow extends LitElement implements LovelaceRow {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
||||||
${computeStateDisplay(this.hass!.localize, stateObj, this.hass.locale)}
|
${computeStateDisplay(
|
||||||
|
this.hass!.localize,
|
||||||
|
stateObj,
|
||||||
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
|
)}
|
||||||
</hui-generic-entity-row>
|
</hui-generic-entity-row>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,8 @@ class HuiToggleEntityRow extends LitElement implements LovelaceRow {
|
|||||||
${computeStateDisplay(
|
${computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass!.locale
|
this.hass!.locale,
|
||||||
|
this.hass!.entities
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
|
@ -120,7 +120,8 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
|
|||||||
? computeStateDisplay(
|
? computeStateDisplay(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)
|
)
|
||||||
: html`
|
: html`
|
||||||
${formatNumber(
|
${formatNumber(
|
||||||
|
@ -58,7 +58,12 @@ class StateCardConfigurator extends LocalizeMixin(PolymerElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_localizeState(stateObj) {
|
_localizeState(stateObj) {
|
||||||
return computeStateDisplay(this.hass.localize, stateObj, this.hass.locale);
|
return computeStateDisplay(
|
||||||
|
this.hass.localize,
|
||||||
|
stateObj,
|
||||||
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
customElements.define("state-card-configurator", StateCardConfigurator);
|
customElements.define("state-card-configurator", StateCardConfigurator);
|
||||||
|
@ -52,7 +52,8 @@ export class StateCardDisplay extends LitElement {
|
|||||||
: computeStateDisplay(
|
: computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
this.stateObj,
|
this.stateObj,
|
||||||
this.hass.locale
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -165,6 +165,7 @@ class StateCardInputNumber extends mixinBehaviors(
|
|||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
newVal,
|
newVal,
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
|
this.hass.entities,
|
||||||
newVal.state
|
newVal.state
|
||||||
),
|
),
|
||||||
mode: String(newVal.attributes.mode),
|
mode: String(newVal.attributes.mode),
|
||||||
|
@ -85,7 +85,12 @@ class StateCardMediaPlayer extends LocalizeMixin(PolymerElement) {
|
|||||||
computePrimaryText(localize, playerObj) {
|
computePrimaryText(localize, playerObj) {
|
||||||
return (
|
return (
|
||||||
playerObj.primaryTitle ||
|
playerObj.primaryTitle ||
|
||||||
computeStateDisplay(localize, playerObj.stateObj, this.hass.locale)
|
computeStateDisplay(
|
||||||
|
localize,
|
||||||
|
playerObj.stateObj,
|
||||||
|
this.hass.locale,
|
||||||
|
this.hass.entities
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
category: Parameters<typeof getHassTranslations>[2],
|
category: Parameters<typeof getHassTranslations>[2],
|
||||||
integration?: Parameters<typeof getHassTranslations>[3],
|
integration?: Parameters<typeof getHassTranslations>[3],
|
||||||
configFlow?: Parameters<typeof getHassTranslations>[4],
|
configFlow?: Parameters<typeof getHassTranslations>[4],
|
||||||
force = false
|
force = true
|
||||||
): Promise<LocalizeFunc> {
|
): Promise<LocalizeFunc> {
|
||||||
if (
|
if (
|
||||||
__BACKWARDS_COMPAT__ &&
|
__BACKWARDS_COMPAT__ &&
|
||||||
|
@ -31,7 +31,7 @@ describe("computeStateDisplay", () => {
|
|||||||
attributes: {},
|
attributes: {},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"component.binary_sensor.state._.off"
|
"component.binary_sensor.state._.off"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -45,7 +45,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"component.binary_sensor.state.moisture.off"
|
"component.binary_sensor.state.moisture.off"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -65,7 +65,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||||
"component.binary_sensor.state.invalid_device_class.off"
|
"component.binary_sensor.state.invalid_device_class.off"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -79,7 +79,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"123 m"
|
"123 m"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -93,7 +93,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"1,234.5 m"
|
"1,234.5 m"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -107,7 +107,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"1,234.5"
|
"1,234.5"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -127,7 +127,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||||
"state.default.unknown"
|
"state.default.unknown"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -147,7 +147,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||||
"state.default.unavailable"
|
"state.default.unavailable"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -165,7 +165,7 @@ describe("computeStateDisplay", () => {
|
|||||||
attributes: {},
|
attributes: {},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||||
"component.sensor.state._.custom_state"
|
"component.sensor.state._.custom_state"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -187,14 +187,14 @@ describe("computeStateDisplay", () => {
|
|||||||
};
|
};
|
||||||
it("Uses am/pm time format", () => {
|
it("Uses am/pm time format", () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"November 18, 2017 at 11:12 PM"
|
"November 18, 2017 at 11:12 PM"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("Uses 24h time format", () => {
|
it("Uses 24h time format", () => {
|
||||||
localeData.time_format = TimeFormat.twenty_four;
|
localeData.time_format = TimeFormat.twenty_four;
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"November 18, 2017 at 23:12"
|
"November 18, 2017 at 23:12"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -216,7 +216,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"November 18, 2017"
|
"November 18, 2017"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -239,14 +239,14 @@ describe("computeStateDisplay", () => {
|
|||||||
it("Uses am/pm time format", () => {
|
it("Uses am/pm time format", () => {
|
||||||
localeData.time_format = TimeFormat.am_pm;
|
localeData.time_format = TimeFormat.am_pm;
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"11:12 PM"
|
"11:12 PM"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("Uses 24h time format", () => {
|
it("Uses 24h time format", () => {
|
||||||
localeData.time_format = TimeFormat.twenty_four;
|
localeData.time_format = TimeFormat.twenty_four;
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData),
|
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||||
"23:12"
|
"23:12"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -273,6 +273,7 @@ describe("computeStateDisplay", () => {
|
|||||||
localize,
|
localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
localeData,
|
localeData,
|
||||||
|
{},
|
||||||
"2021-07-04 15:40:03"
|
"2021-07-04 15:40:03"
|
||||||
),
|
),
|
||||||
"July 4, 2021 at 3:40 PM"
|
"July 4, 2021 at 3:40 PM"
|
||||||
@ -285,6 +286,7 @@ describe("computeStateDisplay", () => {
|
|||||||
localize,
|
localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
localeData,
|
localeData,
|
||||||
|
{},
|
||||||
"2021-07-04 15:40:03"
|
"2021-07-04 15:40:03"
|
||||||
),
|
),
|
||||||
"July 4, 2021 at 15:40"
|
"July 4, 2021 at 15:40"
|
||||||
@ -308,7 +310,7 @@ describe("computeStateDisplay", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData, "2021-07-04"),
|
computeStateDisplay(localize, stateObj, localeData, {}, "2021-07-04"),
|
||||||
"July 4, 2021"
|
"July 4, 2021"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -331,14 +333,14 @@ describe("computeStateDisplay", () => {
|
|||||||
it("Uses am/pm time format", () => {
|
it("Uses am/pm time format", () => {
|
||||||
localeData.time_format = TimeFormat.am_pm;
|
localeData.time_format = TimeFormat.am_pm;
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData, "17:05:07"),
|
computeStateDisplay(localize, stateObj, localeData, {}, "17:05:07"),
|
||||||
"5:05 PM"
|
"5:05 PM"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("Uses 24h time format", () => {
|
it("Uses 24h time format", () => {
|
||||||
localeData.time_format = TimeFormat.twenty_four;
|
localeData.time_format = TimeFormat.twenty_four;
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(localize, stateObj, localeData, "17:05:07"),
|
computeStateDisplay(localize, stateObj, localeData, {}, "17:05:07"),
|
||||||
"17:05"
|
"17:05"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -357,7 +359,7 @@ describe("computeStateDisplay", () => {
|
|||||||
attributes: {},
|
attributes: {},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||||
"state.default.unavailable"
|
"state.default.unavailable"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -372,8 +374,26 @@ describe("computeStateDisplay", () => {
|
|||||||
attributes: {},
|
attributes: {},
|
||||||
};
|
};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||||
"My Custom State"
|
"My Custom State"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Localizes using translation key", () => {
|
||||||
|
const stateObj: any = {
|
||||||
|
entity_id: "sensor.test",
|
||||||
|
state: "custom_state",
|
||||||
|
attributes: {},
|
||||||
|
};
|
||||||
|
const entities: any = {
|
||||||
|
"sensor.test": {
|
||||||
|
translation_key: "custom_translation",
|
||||||
|
platform: "custom_integration",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
assert.strictEqual(
|
||||||
|
computeStateDisplay(localize, stateObj, localeData, entities),
|
||||||
|
"component.custom_integration.entity.sensor.custom_translation.state.custom_state"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user