From 38b817bd67c3bb79c00f95d52e97323dbfd1875d Mon Sep 17 00:00:00 2001 From: On Freund Date: Tue, 24 Sep 2019 11:34:13 +0300 Subject: [PATCH] Green shade in climate history for platforms that don't support `hvac_action` (#3787) * Green shade in climate history for platforms that don't support HVAC_ACTION * The presence of hvac_action can change over time * Move static condition out of anon function --- src/components/state-history-chart-line.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/state-history-chart-line.js b/src/components/state-history-chart-line.js index f88b48053b..f94507c2df 100644 --- a/src/components/state-history-chart-line.js +++ b/src/components/state-history-chart-line.js @@ -155,15 +155,21 @@ class StateHistoryChartLine extends LocalizeMixin(PolymerElement) { domain === "climate" || domain === "water_heater" ) { + const hasHvacAction = states.states.some( + (state) => state.attributes && state.attributes.hvac_action + ); + const isHeating = - domain === "climate" + domain === "climate" && hasHvacAction ? (state) => state.attributes.hvac_action === "heating" : (state) => state.state === "heat"; const isCooling = - domain === "climate" + domain === "climate" && hasHvacAction ? (state) => state.attributes.hvac_action === "cooling" : (state) => state.state === "cool"; + const hasHeat = states.states.some(isHeating); + const hasCool = states.states.some(isCooling); // We differentiate between thermostats that have a target temperature // range versus ones that have just a target temperature @@ -174,8 +180,6 @@ class StateHistoryChartLine extends LocalizeMixin(PolymerElement) { state.attributes.target_temp_high !== state.attributes.target_temp_low ); - const hasHeat = states.states.some(isHeating); - const hasCool = states.states.some(isCooling); addColumn(name + " current temperature", true); if (hasHeat) {