Skip to content

Commit

Permalink
Rename Javascript libraries
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Rushworth <[email protected]>
  • Loading branch information
Scott Rushworth committed May 25, 2019
1 parent f80dedc commit b3d77c9
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 361 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

var Thread = Java.type("java.lang.Thread");
var log = Java.type("org.slf4j.LoggerFactory").getLogger("jsr223.javascript.core.startup_delay");

Expand Down
7 changes: 4 additions & 3 deletions Core/automation/lib/javascript/core/PersistenceExtensions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* Functions to aid in using PersistenceExtensions
*
* Copyright (c) 2019 Contributors to the openHAB Scripters project
*
* @author Helmut Lehmeyer
* @author Helmut Lehmeyer - initial contribution
*/

'use strict';

var PersistenceExtensions = Java.type("org.eclipse.smarthome.model.persistence.extensions.PersistenceExtensions");
Expand Down Expand Up @@ -171,4 +172,4 @@ var PersistenceExtensions = Java.type("org.eclipse.smarthome.model.persistence.e
return null;
};

})(this);
})(this);
39 changes: 39 additions & 0 deletions Core/automation/lib/javascript/core/conditions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Functions for creating Conditions
*
* Copyright (c) 2019 Contributors to the openHAB Scripters project
*
* @author Helmut Lehmeyer - initial contribution
*/
'use strict';

scriptExtension.importPreset("RuleSupport");

// Get Triggers and Conditions module output
// http://localhost:8080/rest/module-types

// Examles:
// see: org.eclipse.smarthome.automation.sample.extension.java.internal.WelcomeHomeRulesProvider.createLightsRule()

if(ModuleBuilder == undefined)var ModuleBuilder = Java.type("org.eclipse.smarthome.automation.core.util.ModuleBuilder");

// ### stateCondition ###
var ItemStateCondition = function(itemName, state, condName){
return ModuleBuilder.createCondition().withId(getTrName(condName)).withTypeUID("core.ItemStateCondition").withConfiguration( new Configuration({
"itemName": itemName,
"operator": "=",
"state": state
})).build();
}
var stateCondition = ItemStateCondition;

// ### GenericCompareCondition ###
var GenericCompareCondition = function(itemName, state, operator, condName){
return ModuleBuilder.createCondition().withId(getTrName(condName)).withTypeUID("core.GenericCompareCondition").withConfiguration( new Configuration({
"itemName": itemName,
"operator": operator,// matches, ==, <, >, =<, =>
"state": state
})).build();
}
//compareCondition("itemName", OFF, "==", "condNameOfCompareCondition")
var compareCondition = GenericCompareCondition;
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
/**
* Functions for creating rules
*
* Copyright (c) 2019 Contributors to the openHAB Scripters project
*
* @author Helmut Lehmeyer
* @author Helmut Lehmeyer - initial contribution
*/
'use strict';

'use strict';

se.importPreset("RuleSupport"); //https://www.openhab.org/docs/configuration/jsr223.html#overview
se.importPreset("RuleSimple");
se.importPreset("RuleFactories");
se.importPreset("default");
scriptExtension.importPreset("RuleSupport"); //https://www.openhab.org/docs/configuration/jsr223.html#overview
scriptExtension.importPreset("RuleSimple");
scriptExtension.importPreset("RuleFactories");
scriptExtension.importPreset("default");

var OPENHAB_CONF = Java.type("java.lang.System").getenv("OPENHAB_CONF");
load(OPENHAB_CONF+'/automation/lib/javascript/core/helper.js');
load(OPENHAB_CONF+'/automation/lib/javascript/core/triggersAndConditions.js');
load(OPENHAB_CONF+'/automation/lib/javascript/core/utils.js');
load(OPENHAB_CONF+'/automation/lib/javascript/core/triggers.js');
load(OPENHAB_CONF+'/automation/lib/javascript/core/conditions.js');

//https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html
//var StSimpleRule = Java.type("org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule");
Expand Down Expand Up @@ -150,4 +152,4 @@ return RuleBuilder.create(ruleDto.uid)
.build();
}

}) (this);
}) (this);
162 changes: 0 additions & 162 deletions Core/automation/lib/javascript/core/triggersAndConditions.js

This file was deleted.

Loading

0 comments on commit b3d77c9

Please sign in to comment.