support for unknown value and uom

This commit is contained in:
proddy
2024-10-10 21:21:35 +01:00
parent d39fc8221e
commit 2bdd4afd23

View File

@@ -27,12 +27,16 @@ const formatDurationMin = (LL: TranslationFunctions, duration_min: number) => {
export function formatValue( export function formatValue(
LL: TranslationFunctions, LL: TranslationFunctions,
value: unknown, value?: unknown,
uom: DeviceValueUOM uom?: DeviceValueUOM
) { ) {
if (typeof value !== 'number') { if (typeof value !== 'number' || uom === undefined || value === undefined) {
return (value === undefined ? '' : value) as string; if (value === undefined || typeof value === 'boolean') {
return '';
}
return value as string;
} }
switch (uom) { switch (uom) {
case DeviceValueUOM.HOURS: case DeviceValueUOM.HOURS:
return value ? formatDurationMin(LL, value * 60) : LL.NUM_HOURS({ num: 0 }); return value ? formatDurationMin(LL, value * 60) : LL.NUM_HOURS({ num: 0 });