I see a few things worth comment, though none of these should be a problem.
- Use the newer (since OH 2.3) syntax. It’s cleaner and easier to figure out what it does. You also don’t need any special imports.
val shadingStart = [GroupItem shutter |
...
]
-
As rossko57 identified, you must pass 1filename
and
logPrefix` (and any other variable whether it’s a global or not) to the lambda if the lambda is declared as a global. -
I would actually recommend creating the lambda as a variable inside your Rule. I’m assuming that this lambda is only called from this one Rule. If you declare it inside the Rule then the lambda can inherit and be aware of any variables that are declared before it so logPrefix won’t need to be passed to it. It will also be less prone to certain types of run time errors.
-
If you apply some of the techniques discussed in Design Pattern: DRY, How Not to Repeat Yourself in Rules DSL, particularly Design Pattern: How to Structure a Rule you ought to be able to eliminate the need for the lambda in the first place.
-
Add logging before and after the call to the lambda. Add a simple log statement as the first line of the lambda.
-
Consider putting the body of your lambda inside a try/catch and log any errors, just in case you are losing any errors generated inside the lambda. This won’t catch all errors/exceptions (e.g. type exceptions are caught outside your Rule) but it can help.