From 77330d03b36ee1326e5b62f10381a9922752b67e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 31 Mar 2018 12:09:22 -0700 Subject: [PATCH] Guard for both undefined and null (#1053) --- src/components/ha-climate-state.html | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/ha-climate-state.html b/src/components/ha-climate-state.html index a1c2b38663..0ecac3b056 100644 --- a/src/components/ha-climate-state.html +++ b/src/components/ha-climate-state.html @@ -51,15 +51,16 @@ class HaClimateState extends Polymer.Element { } computeTarget(stateObj) { - if ('target_temp_low' in stateObj.attributes && - 'target_temp_high' in stateObj.attributes) { + // We're using "!= null" on purpose so that we match both null and undefined. + if (stateObj.attributes.target_temp_low != null && + stateObj.attributes.target_temp_high != null) { return `${stateObj.attributes.target_temp_low} - ${stateObj.attributes.target_temp_high} ${stateObj.attributes.unit_of_measurement}`; - } else if ('temperature' in stateObj.attributes) { + } else if (stateObj.attributes.temperature != null) { return `${stateObj.attributes.temperature} ${stateObj.attributes.unit_of_measurement}`; - } else if ('target_humidity_low' in stateObj.attributes && - 'target_humidity_high' in stateObj.attributes) { + } else if (stateObj.attributes.target_humidity_low != null && + stateObj.attributes.target_humidity_high != null) { return `${stateObj.attributes.target_humidity_low} - ${stateObj.attributes.target_humidity_high} ${stateObj.attributes.unit_of_measurement}`; - } else if ('humidity' in stateObj.attributes) { + } else if (stateObj.attributes.humidity != null) { return `${stateObj.attributes.humidity} ${stateObj.attributes.unit_of_measurement}`; }