]> git.basschouten.com Git - openhab-addons.git/commitdiff
[groovyscripting] Update Groovy to 3.0.7 and add more docs (#9708)
authorWouter Born <github@maindrain.net>
Wed, 6 Jan 2021 07:46:43 +0000 (08:46 +0100)
committerGitHub <noreply@github.com>
Wed, 6 Jan 2021 07:46:43 +0000 (08:46 +0100)
Fixes #8951

Signed-off-by: Wouter Born <github@maindrain.net>
bundles/org.openhab.automation.groovyscripting/README.md
bundles/org.openhab.automation.groovyscripting/pom.xml

index d23cb9ac123e883f701b594f22ed0b503b4635a9..b9b7511f044240862d2f7c6a098df66f9a89c690 100644 (file)
@@ -1,3 +1,43 @@
 # Groovy Scripting
 
-This add-on provides support for [Groovy](https://groovy-lang.org/) 3.x scripts in openHAB.
+This add-on provides support for [Groovy](https://groovy-lang.org/) 3.0.7 that can be used as a scripting language within automation rules and which eliminates the need to manually install Groovy.
+
+## Creating Groovy Scripts
+
+When this add-on is installed, you can select Groovy as a scripting language when creating a script action within the rule editor of the UI.
+
+Alternatively, you can create scripts in the `automation/jsr223` configuration directory.
+If you create an empty file called `test.groovy`, you will see a log line with information similar to:
+
+```text
+    ... [INFO ] [.a.m.s.r.i.l.ScriptFileWatcher:150  ] - Loading script 'test.groovy'
+```
+
+To enable debug logging, use the [console logging]({{base}}/administration/logging.html) commands to enable debug logging for the automation functionality:
+
+```text
+log:set DEBUG org.openhab.core.automation
+```
+
+For more information on the available APIs in scripts see the [JSR223 Scripting]({{base}}/configuration/jsr223.html) documentation.
+
+## Script Examples
+
+Groovy scripts provide access to almost all the functionality in an openHAB runtime environment.
+As a simple example, the following script logs "Hello, World!".
+Note that `System.out.println` will usually not work since the output has no terminal to display the text.
+The openHAB server uses the [SLF4J](https://www.slf4j.org/) library for logging.
+
+```groovy
+import org.slf4j.LoggerFactory
+
+LoggerFactory.getLogger("org.openhab.core.automation.examples").info("Hello world!")
+```
+
+Depending on the openHAB logging configuration, you may need to prefix logger names with `org.openhab.core.automation` for them to show up in the log file (or you modify the logging configuration).
+
+The script uses the [LoggerFactory](https://www.slf4j.org/apidocs/org/slf4j/Logger.html) to obtain a named logger and then logs a message like:
+
+```text
+    ... [INFO ] [.openhab.core.automation.examples:-2   ] - Hello world!
+```
index 4bf691e80e2fa72eb9fa18b278eb696049c6ff7a..ead53f098b5a7127ad0ed397dea50f55818e833c 100644 (file)
@@ -16,7 +16,7 @@
 
   <properties>
     <bnd.importpackage>com.ibm.icu.*;resolution:=optional,groovy.runtime.metaclass;resolution:=optional,groovyjarjarantlr4.stringtemplate;resolution:=optional,org.abego.treelayout.*;resolution:=optional,org.apache.ivy.*;resolution:=optional,org.stringtemplate.v4.*;resolution:=optional</bnd.importpackage>
-    <groovy.version>3.0.6</groovy.version>
+    <groovy.version>3.0.7</groovy.version>
   </properties>
 
   <dependencies>