From c377c01c650dcca358096af96d9d9e2154fabd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Fri, 5 Feb 2021 21:39:18 +0100 Subject: [PATCH] Handle unavailable states --- src/data/history.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/data/history.ts b/src/data/history.ts index 1589aae9a2..0f1f3f81a9 100644 --- a/src/data/history.ts +++ b/src/data/history.ts @@ -4,6 +4,7 @@ import { computeStateDomain } from "../common/entity/compute_state_domain"; import { computeStateName } from "../common/entity/compute_state_name"; import { LocalizeFunc } from "../common/translations/localize"; import { HomeAssistant } from "../types"; +import { UNAVAILABLE_STATES } from "./entity"; const DOMAINS_USE_LAST_UPDATED = ["climate", "humidifier", "water_heater"]; const LINE_ATTRIBUTES_TO_KEEP = [ @@ -201,10 +202,18 @@ const processLineChartEntities = ( }; const isNumberValued = (states: HassEntity[]): boolean => { - for (const state of states) { - if (isNaN(parseFloat(state.state))) { - return false; - } + if (states.every((state) => UNAVAILABLE_STATES.includes(state.state))) { + return false; + } + + if ( + states.some( + (state) => + isNaN(parseFloat(state.state)) && + !UNAVAILABLE_STATES.includes(state.state) + ) + ) { + return false; } return true; };