From aff1fedc9d7ca76574588f1c8bfbd1fb07dae313 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Fri, 27 Feb 2026 14:59:14 +0100 Subject: [PATCH] Fix monetary device class state display with non-ISO 4217 currency symbols (#29887) --- src/common/entity/compute_state_display.ts | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/common/entity/compute_state_display.ts b/src/common/entity/compute_state_display.ts index 16ab18ff4a..d875dc4b48 100644 --- a/src/common/entity/compute_state_display.ts +++ b/src/common/entity/compute_state_display.ts @@ -133,33 +133,34 @@ const computeStateToPartsFromEntityAttributes = ( ), }); } catch (_err) { - // fallback to default + // fallback to default numeric formatting below } - const TYPE_MAP: Record = { - integer: "value", - group: "value", - decimal: "value", - fraction: "value", - literal: "literal", - currency: "unit", - }; + if (parts.length) { + const TYPE_MAP: Record = { + integer: "value", + group: "value", + decimal: "value", + fraction: "value", + literal: "literal", + currency: "unit", + }; - const valueParts: ValuePart[] = []; + const valueParts: ValuePart[] = []; - for (const part of parts) { - const type = TYPE_MAP[part.type]; - if (!type) continue; - const last = valueParts[valueParts.length - 1]; - // Merge consecutive numeric parts (e.g. "1" + "," + "234" + "." + "56" → "1,234.56") - if (type === "value" && last?.type === "value") { - last.value += part.value; - } else { - valueParts.push({ type, value: part.value }); + for (const part of parts) { + const type = TYPE_MAP[part.type]; + if (!type) continue; + const last = valueParts[valueParts.length - 1]; + // Merge consecutive numeric parts (e.g. "1" + "," + "234" + "." + "56" → "1,234.56") + if (type === "value" && last?.type === "value") { + last.value += part.value; + } else { + valueParts.push({ type, value: part.value }); + } } + return valueParts; } - - return valueParts; } // default processing of numeric values