SecurityException using TimeUnit

I’m working on some modifications to @bmmiller’s smarter laundry monitor app. It has some extra smarts to deal with my HE washer where power drops to the idle value many times during the cycle:
https://github.com/edalquist/SmartThings/blob/master/smartapps/edalquist/laundry-monitor.src/laundry-monitor.groovy

There are a bunch of places in the code where I have to covert between minutes/seconds/milliseconds in a few different sets. I figured I’d try to avoid making mistakes and use java.util.concurrent.TimeUnit I didn’t see it on the list of things not allowed in the sandbox

That said when I try to use TimeUnit I get the following error in my logs: Getting properties on class java.lang.Class is not allowed

Is this a side effect of referencing an Enum?

The existing code should handle dropping to idle. That’s what “Minimum amount of below wattage time to trigger off” represents and functions as since most machines obviously idle for a brief period during the load. You would simply make that var longer than your longest idle and it skips those. It delays the actual notification, but knowing when the laundry is done isn’t exactly something that has to be accurate to the second.

Regardless though, Groovy isn’t a fully fledged java language and most of the built in functions of java won’t be available. Did you try an import call?

So the existing code didn’t handle the case where the power values go something like:

HHHLLLHHHLLLHHHLLL
....^...........^.

If the time between those two carrots was 60s then the existing code claims that the laundry is done. What I added is some more state tracking so that if the power goes high after a low it resets the last-low timestamp.

I also added a callback and a timer to check if the value is still low after the timeout. The other behavior I saw with the original script is that my drier would be done and just turn off. It would only have a few seconds below the min power threshold. Since the original app only checked/updated on power change events this meant I never actually got the alert that laundry is done. That may be to different hardware, I’m using the SmartThings Outlet which only sends power events when the power value changes.

I did have the import, here is the commit I removed it in. The SecurityException is something that would be thrown by the SmartThings sandbox due to how they have the Java PolicyManager configured. Things that are valid Java but not valid Groovy are more gotchas like new keywords, array initialization, etc.

I did some more looking at the Enum source code and I’m guessing that SmartThings has a blanket blacklist on .class and .getClass and Enum uses .class to load the list of values when the class is first loaded. You can see that use here: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/Enum.java#186

Ah, I get you, that makes sense then.

If you want, submit a Pull Request when you’re done and I can update the original app for others.

Will do, I’ll do a bit more testing and send a PR