Log.info reports a "closure" where the line before it reported a string?

I'm struggling with Lists. I've tried numerous syntax for the DescList(index) and this one gives me an output. However I do not understand why the line:

log.info "sData: ${sData}"

does not log "Outside Humidity =" as it did in the previous line.

Can anyone explain where I'm going wrong? And why a simple List does not seem to work as the groovy documentation suggests?


@Field static List<String> DescList = ['Outside Temp = ', 'Outside Humidity = ', 'Outside Dew Point = ','Pressure = ','Inside Temp = ', 'Inside Humidity = ', 'Alarm Status: ']
.
.
.
.
.
def handlerButton(evt) {
    
    int index = 1
    log.info "DescList_1 = ${DescList[index]}"  // log.info =>  Outside Humidity =
    String sData = {DescList(index)}
    log.info "sData:  ${sData}"                 // logs => user_app_hubitat__Testing_App_1768$_handlerButton_closure3@d38161
    
    String xData = sData.getBytes("UTF-8").encodeHex()
    xData = "01" + xData
    log.info "xData: ${xData}"
    BDlen = xData.length()/2    // rtns a BigDecimal because of the division.
    String HexLen = hubitat.helper.HexUtils.integerToHexString(BDlen.intValue(), 1)
    String HexDataString = HexLen + xData
    log.info "full HEX string = $HexDataString"
    UARTdriver.WriteAttr_(HexDataString)
}

@JohnRob I took your code from your other post and loaded it in my Dev hub. Again modified your String sData assignment to:

String sData = DescList[index]

Logging worked. Those curly brackets shouldn't be there and to get an element from an array/list you always use [ ]:

1 Like

Sorry to post the same problem again. I think the always use for the index of a List in Hubitat did not sink in,
Perhaps I had the groovy examples that seemed to use ( ) stuck somewhere in my mind.

Thanks
John

1 Like