Fix JRuby examples (#2128)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
pull/2129/head
jimtng 2023-08-28 02:52:36 +10:00 committed by GitHub
parent b4ae138e7d
commit e5e110a00c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 47 deletions

View File

@ -273,7 +273,7 @@ Other times the helper library must be installed separately, searching in the co
The following code snippets implement the examples from the top of this page using UI rules, [DSL rules](/docs/configuration/rules-dsl), [JRuby Scripting](/addons/automation/jrubyscripting/), and [JS Scripting](https://openhab.org/addons/automation/jsscripting). The following code snippets implement the examples from the top of this page using UI rules, [DSL rules](/docs/configuration/rules-dsl), [JRuby Scripting](/addons/automation/jrubyscripting/), and [JS Scripting](https://openhab.org/addons/automation/jsscripting).
The code from the JS Scripting examples can be used in file-based scripts that are created inside the `/automation/js` folder and have `.js` as their file extension. The code from the JS Scripting examples can be used in file-based scripts that are created inside the `/automation/js` folder and have `.js` as their file extension.
The same applies for the JRuby examples, but they have to be placed inside `/automation/jsr223/ruby/personal` with `.rb` as the file extension. The same applies for the JRuby examples, but they have to be placed inside `/automation/ruby` with `.rb` as the file extension.
The Rules DSL examples can be places in the `rules` folder and have `.rules` as their file extension. The Rules DSL examples can be places in the `rules` folder and have `.rules` as their file extension.
Each UI rule will have a "code" tab showing the full rule definition. Each UI rule will have a "code" tab showing the full rule definition.
@ -340,14 +340,12 @@ end
::: tab JRuby ::: tab JRuby
```ruby ```ruby
require 'openhab' rule "Raise the blinds & adjust temperature on sunrise" do
channel "astro:sun:home:rise#event", triggered: "START"
rule 'Raise the blinds & adjust temperature on sunrise' do run do
channel 'astro:sun:home:rise#event' gBlinds.up
run { gThermostat.increase
gBlinds << up end
gThermostat << increase
}
end end
``` ```
@ -433,14 +431,12 @@ end
::: tab JRuby ::: tab JRuby
```ruby ```ruby
require 'openhab' rule "Turn off the lights & adjust temperature on leaving" do
received_command Presence, command: OFF
rule 'Turn off the lights & adjust temperature on leaving' do run do
received_command Presence, command: off gLights.off
run { gThermostat.decrease
gLights << off end
gThermostat << decrease
}
end end
``` ```
@ -522,14 +518,10 @@ end
::: tab JRuby ::: tab JRuby
```ruby ```ruby
require 'openhab' rule "Play music on arrival, but only on afternoon" do
received_command Presence, command: ON
rule 'Play music on arrival, but only on afternoon' do only_if { LocalTime.now.between? "1pm".."6pm" }
received_command Presence, command: on run { Soundbar.on }
run {
Soundbar >> on
}
only_if { TimeOfDay.now.between? 1pm..6pm }
end end
``` ```
@ -629,17 +621,12 @@ end
::: tab JRuby ::: tab JRuby
```ruby ```ruby
require 'openhab' rule "Window open reminder" do
changed gWindows.members, to: OPEN, for: 1.hour
rule 'Window open reminder' do run do |event|
changed: gWindows, to: open # Item guaranteed to be OPEN here, no need to check
run { notify("#{event.item.label} is open for an hour!")
after 1.hour do end
if item.state.open?
notify("#{item.label} is open for an hour!")
end
end
}
end end
``` ```
@ -755,18 +742,15 @@ end
::: tab JRuby ::: tab JRuby
```ruby ```ruby
require 'openhab' rule "Movie Scene" do
rule 'Movie Scene' do
received_command MovieScene, command: ON received_command MovieScene, command: ON
run { run do
LivingRoom_Blinds >> '90%' LivingRoom_Blinds.command(90)
LivingRoom_MainLight >> off LivingRoom_MainLight.off
LivingRoom_LEDStripe >> '50%' LivingRoom_LEDStripe.command(50)
Soundbar >> on Soundbar.on
TV >> on TV.on
Soundbar >> ON end
}
end end
``` ```