From 980bef6879fd7beb94119dbf5f6bcec8bef7d36b Mon Sep 17 00:00:00 2001 From: Stephen Stack Date: Fri, 21 Apr 2017 15:40:04 -0500 Subject: [PATCH] DVCSMP-2573: Acceleration axis validation (Multi sensor DTH) In certain cases the SmartSense Multi Sensors are missing the Y and Z axis, causing an exception during .parseAxis(). This change checks that all 3 axis are present before processing the rest of the message. --- .../smartsense-multi-sensor.groovy | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy b/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy index 62a7fc3..033708a 100644 --- a/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy +++ b/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy @@ -192,6 +192,10 @@ private List parseAxis(List attrData) { def y = hexToSignedInt(attrData.find { it.attrInt == 0x0013 }?.value) def z = hexToSignedInt(attrData.find { it.attrInt == 0x0014 }?.value) + if ([x, y ,z].any { it == null }) { + return [] + } + def xyzResults = [:] if (device.getDataValue("manufacturer") == "SmartThings") { // This mapping matches the current behavior of the Device Handler for the Centralite sensors @@ -372,6 +376,10 @@ def updated() { } private hexToSignedInt(hexVal) { + if (!hexVal) { + return null + } + def unsignedVal = hexToInt(hexVal) unsignedVal > 32767 ? unsignedVal - 65536 : unsignedVal }