I’m converting some rules using timers today and have a question I can’t find an answer to.
With the rules dsl I could define a timer like this;
away_timer = createTimer(now.plusMinutes(10)) [|
logInfo("presence.rules", "No presence detected for 10 minutes. Setting Presence to OFF")
Presence.sendCommand(OFF)
]
I haven’t found an example of a lambda in Python like this consisting of more than one statement. The only way I’ve been able to do this is by creating a separate function and calling it in the lambda like so;
away_timer = ScriptExecution.createTimer(DateTime.now().plusMinutes(10), lambda: turn_presence_off())
#########
def turn_presence_off():
LogAction.logInfo("presence.rules", "No presence detected for 10 minutes. Setting Presence to OFF")
events.sendCommand("Presence", "OFF")
While there will be occasions where it will be nice to have the lambda call a function in this manner, for one-off non-reusable functions it feels convoluted. Is there syntax that allows me to do this all in the original lambda?