Expression [MethodCallExpression] is not allowed: cmd.getClass()

@gopher.ny can this be unblocked so we can use it in custom code?
The workaround is to use .class which works on every object except a map. On a map it tries to get a key named class instead of the getClass method.

Expression [MethodCallExpression] is not allowed: cmd.getClass()

image

Do you know about getObjectClassName()? That is basically the sandbox-allowed equivalent of this call.

I thought I figured out a way to do it in the past and just assumed it was .class, it may very well have been that. I will switch it over to that, thanks.

Was trying to use it to add to my catch-all zwaveEvent to see the exact object name getting handed over. .class works but not .getObjectClassName()

void zwaveEvent(hubitat.zwave.Command cmd, ep=0) {
	logDebug "Unhandled zwaveEvent: $cmd (ep ${ep}) [${(cmd).getObjectClassName()}]"
}

groovy.lang.MissingMethodException: No signature of method: hubitat.zwave.commands.doorlockv1.DoorLockOperationReport.getObjectClassName() is applicable for argument types: () values: []

But this works:

void zwaveEvent(hubitat.zwave.Command cmd, ep=0) {
	logDebug "Unhandled zwaveEvent: $cmd (ep ${ep}) [${(cmd).class}]"
}

Office Door Lock: Unhandled zwaveEvent: DoorLockOperationReport(doorLockMode: 255, outsideDoorHandlesMode: 0, insideDoorHandlesMode: 0, doorCondition: 0, lockTimeoutMinutes: 254, lockTimeoutSeconds: 254) (ep 0) [class hubitat.zwave.commands.doorlockv1.DoorLockOperationReport]

Nevermind, I should try reading the docs... I was trying to use it wrong. Will try again.

Working function:

void zwaveEvent(hubitat.zwave.Command cmd, ep=0) {
	logDebug "Unhandled zwaveEvent: $cmd (ep ${ep}) [${getObjectClassName(cmd)}]"
}
2 Likes