[auromation] Fix createTimer for DSL rules (#3172)
* Fix createTimer for DSL rules Signed-off-by: Jan N. Klug <github@klug.nrw>pull/3177/head
parent
bf38f4d2b1
commit
f6e36c1852
|
@ -16,7 +16,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.xtext.xbase.XExpression;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures;
|
||||
import org.openhab.core.automation.module.script.action.Timer;
|
||||
import org.openhab.core.model.core.ModelRepository;
|
||||
import org.openhab.core.model.script.ScriptServiceUtil;
|
||||
import org.openhab.core.model.script.engine.Script;
|
||||
|
@ -75,21 +74,21 @@ public class ScriptExecution {
|
|||
|
||||
@ActionDoc(text = "create a timer")
|
||||
public static Timer createTimer(ZonedDateTime zonedDateTime, Procedures.Procedure0 closure) {
|
||||
return ScriptExecutionActionService.getScriptExecution().createTimer(zonedDateTime, closure::apply);
|
||||
return new Timer(ScriptExecutionActionService.getScriptExecution().createTimer(zonedDateTime, closure::apply));
|
||||
}
|
||||
|
||||
@ActionDoc(text = "create an identifiable timer ")
|
||||
public static Timer createTimer(@Nullable String identifier, ZonedDateTime zonedDateTime, Procedures.Procedure0 closure) {
|
||||
return ScriptExecutionActionService.getScriptExecution().createTimer(identifier, zonedDateTime, closure::apply);
|
||||
return new Timer(ScriptExecutionActionService.getScriptExecution().createTimer(identifier, zonedDateTime, closure::apply));
|
||||
}
|
||||
|
||||
@ActionDoc(text = "create a timer with argument")
|
||||
public static Timer createTimerWithArgument(ZonedDateTime zonedDateTime, Object arg1, Procedures.Procedure1 closure) {
|
||||
return ScriptExecutionActionService.getScriptExecution().createTimerWithArgument(zonedDateTime, arg1, closure::apply);
|
||||
return new Timer(ScriptExecutionActionService.getScriptExecution().createTimerWithArgument(zonedDateTime, arg1, closure::apply));
|
||||
}
|
||||
|
||||
@ActionDoc(text = "create an identifiable timer with argument")
|
||||
public static Timer createTimerWithArgument(@Nullable String identifier, ZonedDateTime zonedDateTime, Object arg1, Procedures.Procedure1 closure) {
|
||||
return ScriptExecutionActionService.getScriptExecution().createTimerWithArgument(identifier, zonedDateTime, arg1, closure::apply);
|
||||
return new Timer(ScriptExecutionActionService.getScriptExecution().createTimerWithArgument(identifier, zonedDateTime, arg1, closure::apply));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* Copyright (c) 2010-2022 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.core.model.script.actions;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* The {@link Timer} is a wrapper for the {@link org.openhab.core.automation.module.script.action.Timer}
|
||||
* interface. This is necessary because the implementation methods of an interface can't be called from
|
||||
* the script engine if the implementation is not in a public package or internal to the model bundle
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Timer {
|
||||
|
||||
private final org.openhab.core.automation.module.script.action.Timer timer;
|
||||
|
||||
public Timer(org.openhab.core.automation.module.script.action.Timer timer) {
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
public boolean cancel() {
|
||||
return timer.cancel();
|
||||
}
|
||||
|
||||
public @Nullable ZonedDateTime getExecutionTime() {
|
||||
return timer.getExecutionTime();
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return timer.isActive();
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return timer.isCancelled();
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return timer.isRunning();
|
||||
}
|
||||
|
||||
public boolean hasTerminated() {
|
||||
return timer.hasTerminated();
|
||||
}
|
||||
|
||||
public boolean reschedule(ZonedDateTime newTime) {
|
||||
return timer.reschedule(newTime);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue