Handle unavailable states

This commit is contained in:
Thomas Lovén 2021-02-05 21:39:18 +01:00
parent aaf65e0599
commit c377c01c65

View File

@ -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;
};