Guard for non numeric states (#10775)

Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
This commit is contained in:
Bram Kragten 2021-12-03 12:53:50 +01:00 committed by GitHub
parent e99f20c4f3
commit 46a9e36516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -188,7 +188,10 @@ export class HuiAreaCard
} }
let uom; let uom;
const values = entities.filter((entity) => { const values = entities.filter((entity) => {
if (!entity.attributes.unit_of_measurement) { if (
!entity.attributes.unit_of_measurement ||
isNaN(Number(entity.state))
) {
return false; return false;
} }
if (!uom) { if (!uom) {
@ -200,7 +203,10 @@ export class HuiAreaCard
if (!values.length) { if (!values.length) {
return undefined; return undefined;
} }
const sum = values.reduce((a, b) => a + Number(b.state), 0); const sum = values.reduce(
(total, entity) => total + Number(entity.state),
0
);
return `${formatNumber(sum / values.length, this.hass!.locale, { return `${formatNumber(sum / values.length, this.hass!.locale, {
maximumFractionDigits: 1, maximumFractionDigits: 1,
})} ${uom}`; })} ${uom}`;