Format monetary sensor as currency (#9633)

This commit is contained in:
Bram Kragten 2021-07-28 18:34:03 +02:00 committed by GitHub
parent 521d5df064
commit 9c31b749d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,16 @@ export const computeStateDisplay = (
}
if (stateObj.attributes.unit_of_measurement) {
if (stateObj.attributes.device_class === "monetary") {
try {
return formatNumber(compareState, locale, {
style: "currency",
currency: stateObj.attributes.unit_of_measurement,
});
} catch (_err) {
// fallback to default
}
}
return `${formatNumber(compareState, locale)} ${
stateObj.attributes.unit_of_measurement
}`;