Guard for both undefined and null (#1053)

This commit is contained in:
Paulus Schoutsen 2018-03-31 12:09:22 -07:00 committed by GitHub
parent 88ad376045
commit 77330d03b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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