Skip to content

Commit

Permalink
Fix to battery parse to avoid erroneous value
Browse files Browse the repository at this point in the history
  • Loading branch information
veeceeoh authored Feb 12, 2018
1 parent 0d17969 commit 8d5820c
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions devicetypes/bspranger/xiaomi-button.src/xiaomi-button.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d5820c

Please sign in to comment.