@@ -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
8686export const entityStyles = ( config ) =>
0 commit comments