@@ -29,8 +29,8 @@ export const entityStateDisplay = (hass, stateObj, config) => {
2929 return hass . localize ( `state.default.${ stateObj . state } ` ) ;
3030 }
3131
32- const value = config . attribute ? stateObj . attributes [ config . attribute ] : stateObj . state ;
33- const unit =
32+ let value = config . attribute ? stateObj . attributes [ config . attribute ] : stateObj . state ;
33+ let unit =
3434 config . unit === false
3535 ? undefined
3636 : config . attribute !== undefined
@@ -39,23 +39,27 @@ export const entityStateDisplay = (hass, stateObj, config) => {
3939
4040 if ( config . format ) {
4141 if ( isNaN ( parseFloat ( value ) ) || ! isFinite ( value ) ) {
42- return value ;
43- }
44- if ( config . format === 'brightness' ) {
45- return `${ Math . round ( ( value / 255 ) * 100 ) } %` ;
46- }
47- if ( config . format === 'duration' ) {
48- return secondsToDuration ( value ) ;
49- }
50- if ( config . format . startsWith ( 'precision' ) ) {
42+ // do nothing if not a number
43+ } else if ( config . format === 'brightness' ) {
44+ value = Math . round ( ( value / 255 ) * 100 ) ;
45+ unit = '%' ;
46+ } else if ( config . format . startsWith ( 'duration' ) ) {
47+ value = secondsToDuration ( config . format === 'duration-m' ? value / 1000 : value ) ;
48+ unit = undefined ;
49+ } else if ( config . format . startsWith ( 'precision' ) ) {
5150 const precision = parseInt ( config . format . slice ( - 1 ) , 10 ) ;
52- const formatted = formatNumber ( parseFloat ( value ) , hass . locale , {
51+ value = formatNumber ( parseFloat ( value ) , hass . locale , {
5352 minimumFractionDigits : precision ,
5453 maximumFractionDigits : precision ,
5554 } ) ;
56- return `${ formatted } ${ unit ? ` ${ unit } ` : '' } ` ;
55+ } else if ( config . format === 'kilo' ) {
56+ value = formatNumber ( value / 1000 , hass . locale , { maximumFractionDigits : 2 } ) ;
57+ } else if ( config . format === 'invert' ) {
58+ value = value - value * 2 ;
59+ } else if ( config . format === 'position' ) {
60+ value = 100 - value ;
5761 }
58- return value ;
62+ return ` ${ value } ${ unit ? ` ${ unit } ` : '' } ` ;
5963 }
6064
6165 if ( config . attribute ) {
0 commit comments