Problem with roomName

When I access the roomName property of a device, I get this error:
"java.lang.NullPointerException: Cannot get property 'roomId' on null object on line ..."

Here a minimal app to reproduce the error:

definition name:'jsTest', namespace:'de.schwider', author:'', description:'', iconUrl:'', iconX2Url:''

preferences
{
  page(name:'test', title:'', install:true, uninstall:true)
  {
    section('')
    {
      input 'batteryDevices', 'capability.battery', title:'Battery Devices:', multiple:true, required:true
    }
  }
}

void installed()
{
  for (def device in batteryDevices)
    log.info '- ' + device.roomName  // <-- BOOM!
}

void updated()
{
  installed ()
}

void uninstalled() {}

But no problems when I replace device.roomName with device.displayName...

Very strange: When I replace the complete line

  log.info '- ' + device.roomName

with

  log.info device.displayName + ' - ' + device.roomName

it's working!?! :thinking:

It seems that roomName needs some kind of initializing before working...?
Dear @Hubitat_Staff, could you please review the implementation?

Try device.properties.roomName

2 Likes

Yes, that works: By using properties it seems that all the device properties are initialized (like using displayName). :thinking:

IMHO it should be an easy fix to make roomName consistent to displayName etc., shouldn't it? :wink:

Download the Hubitat app