a4refillpad / Xiaomi

my Xiaomi Device Handlers for Smartthings
Apache License 2.0
248 stars 1.84k forks source link

BigDecimal error #15

Closed thenemal closed 6 years ago

thenemal commented 6 years ago

Hi,

I have the following error, maybe since the last ST hub upgrade:

f3dff9ae-9346-4e28-8ed5-10:46:47 AM: debug Parse returned Guest room Temp & Humidity humidity is 35% f3dff9ae-9346-4e28-8ed5-10:46:47 AM: debug Evencreated: humidity, 35, % f3dff9ae-9346-4e28-8ed5-10:46:47 AM: debug Parsevalue: 35 f3dff9ae-9346-4e28-8ed5-10:46:47 AM: debug Parsename: humidity f3dff9ae-9346-4e28-8ed5-10:46:47 AM: debug RAW: humidity: 35.1% f3dff9ae-9346-4e28-8ed5-10:46:47 AM: error groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.math.BigDecimal#plus. Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [class java.lang.Character] [class java.lang.String] [class java.lang.Number] [class java.math.MathContext] f3dff9ae-9346-4e28-8ed5-10:46:47 AM: debug Parsename: temperature f3dff9ae-9346-4e28-8ed5- 10:46:47 AM: debug RAW: temperature: 20.42 f3dff9ae-9346-4e28-8ed5- 10:19:04 AM: debug Sending enroll response f3dff9ae-9346-4e28-8ed5-10:19:04 AM: debug refresh called

I have the latest A4refillpad Xiaomi Temperature Humidity Sensor. I see one call to BigData:

private String parseValue(String description) {

if (description?.startsWith("temperature: ")) {
    def value = ((description - "temperature: ").trim()) as Float 

    if (getTemperatureScale() == "C") {
        if (tempOffset) {
            return (Math.round(value * 10))/ 10 + tempOffset as Float
        } else {
            return (Math.round(value * 10))/ 10 as Float
        }               
    } else {
        if (tempOffset) {
            return (Math.round(value * 90/5))/10 + 32 + offset as Float
        } else {
            return (Math.round(value * 90/5))/10 + 32 as Float
        }               
    }        

} else if (description?.startsWith("humidity: ")) {
    def pct = (description - "humidity: " - "%").trim()

    if (pct.isNumber()) {
        return Math.round(new BigDecimal(pct)).toString()
    }
} else if (description?.startsWith("catchall: ")) {
    return parseCatchAllMessage(description)
} else {
log.debug "unknown: $description"
sendEvent(name: "unknown", value: description)
}
null

}

Any idea?

thenemal commented 6 years ago

I am in the US. Is it related to the C to F conversion?

thenemal commented 6 years ago

Found the error in function parseValue, line 163: the variable used to offset the temp in F is wrong and should be replaced by "tempOffset", instead of "offset".

This bug only affects you if you are using F degrees - you don't need this fix if you are using C degrees.

Not sure how to properly include this in the original code.

thenemal commented 6 years ago

https://github.com/a4refillpad/Xiaomi/pull/13/commits/b31521bef415b13758de0dfba5e1fc8f99677c5f