Since I am really a beginner and this is not my written code, would be great to get your advice which parameters has to be add in the <>. I marked them with quesitonmarks…
var org.eclipse.xtext.xbase.lib.Functions$Function2<?,?> makeTimer = [
int myDelay,
org.eclipse.xtext.xbase.lib.Functions$Function2<?,?> makeTimer2 |
if(myDelay>0) {
postUpdate(garden_Timer_Remaining, myDelay)
// to save processes I only update UI once a minute
timerFon=createTimer(now.plusMinutes(1)) [|
postUpdate(garden_Timer_Remaining, myDelay-1)
makeTimer2.apply(myDelay-1, makeTimer2)
]
}else {
// timer reach zero
postUpdate(garden_Timer_Selector,0)
// what I want to happen when the timer stops
//sendCommand(Socket_02, OFF)
Kamin_Light.sendCommand(OFF)
postUpdate(garden_Timer_DateTime_Stop, new DateTimeType())
}
]
As a beginner, I would suggest not use Functions in Rules DSL. They’re error prone and unhelpful about why they might have gone wrong.
Also as a beginner, someone else will be along in a minute to advise you not to put too much effort into learning Rules DSL, and suggest using the alternative Jython rules system.
You can get rid of one of the the warnings (and make it a little simpler) by defining the lambdas as:
import org.eclipse.xtext.xbase.lib.Functions
val makeTimer = [Integer myDelay, Functions$Function2 makerTimer2 |
It’s still going to complain about the makerTimer2’s Functions$Function type though but it’s going to be impossible to deal with that because the stuff in < > expands infinitely. So the warnings simply cannot be elimianted.
Frankly, this code stinks. It made sense to do it like this at one point but I cannot recommend this approach any more. I kind of dislike lambdas for something like this and I really dislike passing lambdas to lambdas. And there is absolutely no need to use two timers for this. rossko57’s Countdown Timer is far simpler and far less brittle than this.
If you use Scripted Automation, I’ve a reusable library version that implements rossko57’s DP. All you have to do is import it and give it the amount of time to run, the Item to update with the time remaining, and the function to call when it’s done. https://github.com/openhab-scripters/openhab-helper-libraries/pull/237