From 046a9ef6f20f88a44fe9e2cdc3fec971dff1f68a Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 16 Jul 2021 16:26:58 +0200 Subject: [PATCH] show dallas-temperatures always with digit on web --- interface/src/project/EMSESPDevicesForm.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/interface/src/project/EMSESPDevicesForm.tsx b/interface/src/project/EMSESPDevicesForm.tsx index b9bcb422b..9db3de44a 100644 --- a/interface/src/project/EMSESPDevicesForm.tsx +++ b/interface/src/project/EMSESPDevicesForm.tsx @@ -118,7 +118,7 @@ export const formatDuration = (duration_min: number) => { const pluralize = (count: number, noun: string, suffix = 's') => ` ${count} ${noun}${count !== 1 ? suffix : ''} `; -function formatValue(value: any, uom: number) { +function formatValue(value: any, uom: number, digit: number) { switch (uom) { case DeviceValueUOM.HOURS: return value ? formatDuration(value * 60) : '0 hours'; @@ -131,6 +131,14 @@ function formatValue(value: any, uom: number) { return new Intl.NumberFormat().format(value); case DeviceValueUOM.BOOLEAN: return value ? 'on' : 'off'; + case DeviceValueUOM.DEGREES: + return ( + new Intl.NumberFormat(undefined, { + minimumFractionDigits: digit + }).format(value) + + ' ' + + DeviceValueUOM_s[uom] + ); default: return ( new Intl.NumberFormat().format(value) + ' ' + DeviceValueUOM_s[uom] @@ -313,7 +321,7 @@ class EMSESPDevicesForm extends Component< {sensorData.id} - {formatValue(sensorData.temp, DeviceValueUOM.DEGREES)} + {formatValue(sensorData.temp, DeviceValueUOM.DEGREES, 1)} ))} @@ -476,7 +484,7 @@ class EMSESPDevicesForm extends Component< {item.n} - {formatValue(item.v, item.u)} + {formatValue(item.v, item.u, 0)} ))}