diff --git a/devicetypes/bspranger/xiaomi-button.src/xiaomi-button.groovy b/devicetypes/bspranger/xiaomi-button.src/xiaomi-button.groovy index 3951cb28..fc5f6332 100644 --- a/devicetypes/bspranger/xiaomi-button.src/xiaomi-button.groovy +++ b/devicetypes/bspranger/xiaomi-button.src/xiaomi-button.groovy @@ -191,31 +191,24 @@ private Map parseReadAttrMessage(String description) { // Check catchall for battery voltage data to pass to getBatteryResult for conversion to percentage report private Map parseCatchAllMessage(String description) { - def i - Map resultMap = [:] - def cluster = zigbee.parse(description) - log.debug cluster - if (cluster) { - switch(cluster.clusterId) { - case 0x0000: - def MsgLength = cluster.data.size(); - for (i = 0; i < (MsgLength-3); i++) - { - // Original Xiaomi CatchAll does not have identifiers, first UINT16 is Battery - if ((cluster.data.get(0) == 0x02) && (cluster.data.get(1) == 0xFF)) - { - if (cluster.data.get(i) == 0x21) // check the data ID and data type - { - // next two bytes are the battery voltage. - resultMap = getBatteryResult((cluster.data.get(i+2)<<8) + cluster.data.get(i+1)) - return resultMap - } - } - } - break - } - } - return resultMap + Map resultMap = [:] + def catchall = zigbee.parse(description) + log.debug catchall + + if (catchall.clusterId == 0x0000) { + def MsgLength = catchall.data.size() + // Xiaomi CatchAll does not have identifiers, first UINT16 is Battery + if ((catchall.data.get(0) == 0x01 || catchall.data.get(0) == 0x02) && (catchall.data.get(1) == 0xFF)) { + for (int i = 4; i < (MsgLength-3); i++) { + if (catchall.data.get(i) == 0x21) { // check the data ID and data type + // next two bytes are the battery voltage + resultMap = getBatteryResult((catchall.data.get(i+2)<<8) + catchall.data.get(i+1)) + } + break + } + } + } + return resultMap } // Convert raw 4 digit integer voltage value into percentage based on minVolts/maxVolts range