Hi,
I am trying to create a methods, that returns to distinct set of values, device and device type. here is the method
def findDevice(device) {
log.debug "trying to find device - $device"
def foundDevice
// first search in switches
log.debug "finding id - ${device.id}"
def switchDevice = switches.find{it.id == device.id}
if (switchDevice) {
log.debug "Found ${switchDevice.displayName} in switches"
// group the type, and device to return back
foundDevice.type = "switch"
foundDevice.device = switchDevice
}
// look for device in thermostat
def thermDevice = thermostats.find(it.id == device.id)
if (thermDevice) {
log.debug "Found ${thermDevice.displayName} in thermostats"
// group the type, and device to return back
foundDevice.type = "thermostat"
foundDevice.device = thermDevice
}
return foundDevice
}
I create a def for foundDevice and added type. and device as properties of it so that I can later access them. I know that classes are not supported in ST. But is something this straight forward supported one way or another. The code compiles but I get a runtime error when setting the type resulting nullPointerExpection for the foundDevice.
Does ST or groovy allow me to return different items if I cannot create my own class or struct.
thanks