Skip to content

Commit a58005d

Browse files
committed
Use localization on attribute values (#178)
1 parent 6b596f4 commit a58005d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/entity.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,23 @@ export const entityStateDisplay = (hass, stateObj, config) => {
3535
return hass.localize(`state.default.${stateObj.state}`);
3636
}
3737

38+
const domain = computeStateDomain(stateObj);
39+
const computeDisplay = (value) =>
40+
(stateObj.attributes.device_class &&
41+
hass.localize(`component.${domain}.state.${stateObj.attributes.device_class}.${value}`)) ||
42+
hass.localize(`component.${domain}.state._.${value}`) ||
43+
value;
44+
3845
if (config.attribute) {
3946
return config.attribute in stateObj.attributes
40-
? `${stateObj.attributes[config.attribute]}${config.unit ? ` ${config.unit}` : ''}`
47+
? `${computeDisplay(stateObj.attributes[config.attribute])}${config.unit ? ` ${config.unit}` : ''}`
4148
: hass.localize('state.default.unavailable');
4249
}
4350

4451
if (config.unit !== false && (config.unit || stateObj.attributes.unit_of_measurement)) {
4552
return `${stateObj.state} ${config.unit || stateObj.attributes.unit_of_measurement}`;
4653
}
4754

48-
const domain = computeStateDomain(stateObj);
49-
5055
if (domain === 'input_datetime') {
5156
let date;
5257
if (!stateObj.attributes.has_time) {
@@ -75,12 +80,7 @@ export const entityStateDisplay = (hass, stateObj, config) => {
7580
return formatDateTime(date, hass.language);
7681
}
7782

78-
return (
79-
(stateObj.attributes.device_class &&
80-
hass.localize(`component.${domain}.state.${stateObj.attributes.device_class}.${stateObj.state}`)) ||
81-
hass.localize(`component.${domain}.state._.${stateObj.state}`) ||
82-
stateObj.state
83-
);
83+
return computeDisplay(stateObj.state);
8484
};
8585

8686
export const entityStyles = (config) =>

0 commit comments

Comments
 (0)