Add sharedCache and privateCache to file-based RulesDSL (#4525)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
pull/4530/head
jimtng 2024-12-31 21:39:24 +10:00 committed by GitHub
parent fe730b3918
commit 321d3a5f04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 2 deletions

View File

@ -31,6 +31,7 @@ Import-Package: \
org.openhab.core.model.persistence.extensions,\
org.openhab.core.model.script,\
org.openhab.core.model.script.engine.action,\
org.openhab.core.automation.module.script.rulesupport.shared,\
com.google.common.base;version="14",\
javax.measure,\
javax.measure.quantity,\

View File

@ -20,6 +20,11 @@
<artifactId>org.openhab.core.model.script</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.automation.module.script.rulesupport</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory
import org.eclipse.xtext.common.types.JvmFormalParameter
import org.eclipse.emf.common.util.EList
import org.openhab.core.events.Event
import org.openhab.core.automation.module.script.rulesupport.shared.ValueCache
/**
* <p>Infers a JVM model from the source model.</p>
@ -130,6 +131,10 @@ class RulesJvmModelInferrer extends ScriptJvmModelInferrer {
members += ruleModel.rules.map [ rule |
rule.toMethod("_" + rule.name, ruleModel.newTypeRef(Void.TYPE)) [
static = true
val privateCacheTypeRef = ruleModel.newTypeRef(ValueCache)
parameters += rule.toParameter(VAR_PRIVATE_CACHE, privateCacheTypeRef)
val sharedCacheTypeRef = ruleModel.newTypeRef(ValueCache)
parameters += rule.toParameter(VAR_SHARED_CACHE, sharedCacheTypeRef)
if ((containsCommandTrigger(rule)) || (containsStateChangeTrigger(rule)) || (containsStateUpdateTrigger(rule))) {
val groupTypeRef = ruleModel.newTypeRef(Item)
parameters += rule.toParameter(VAR_TRIGGERING_GROUP, groupTypeRef)

View File

@ -169,8 +169,10 @@ public class DSLScriptEngine implements javax.script.ScriptEngine {
Map<String, Object> cachePreset = scriptExtensionAccessor.findPreset("cache",
(String) context.getAttribute("oh.engine-identifier", ScriptContext.ENGINE_SCOPE));
evalContext.newValue(QualifiedName.create("sharedCache"), cachePreset.get("sharedCache"));
evalContext.newValue(QualifiedName.create("privateCache"), cachePreset.get("privateCache"));
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_SHARED_CACHE),
cachePreset.get("sharedCache"));
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_PRIVATE_CACHE),
cachePreset.get("privateCache"));
// now add specific implicit vars, where we have to map the right content
Object value = context.getAttribute(OUTPUT_EVENT);
if (value instanceof ChannelTriggeredEvent event) {