openhab-scripting 2.9.1 → 2.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/version.rb +1 -1
  3. metadata +1 -61
  4. data/.github/workflows/workflow.yml +0 -327
  5. data/.gitignore +0 -17
  6. data/.java-version +0 -1
  7. data/.rspec +0 -1
  8. data/.yardopts +0 -1
  9. data/CHANGELOG.md +0 -113
  10. data/Gemfile +0 -28
  11. data/Gemfile.lock +0 -245
  12. data/Guardfile +0 -35
  13. data/LICENSE +0 -277
  14. data/README.md +0 -23
  15. data/Rakefile +0 -406
  16. data/bin/console +0 -15
  17. data/bin/setup +0 -8
  18. data/config/userdata/config/org/openhab/restauth.config +0 -3
  19. data/cucumber.yml +0 -1
  20. data/docs/_config.yml +0 -135
  21. data/docs/contributing/index.md +0 -47
  22. data/docs/examples/conversions.md +0 -123
  23. data/docs/examples/index.md +0 -61
  24. data/docs/index.md +0 -19
  25. data/docs/installation/index.md +0 -26
  26. data/docs/motivation/index.md +0 -27
  27. data/docs/usage/execution.md +0 -9
  28. data/docs/usage/execution/delay.md +0 -48
  29. data/docs/usage/execution/otherwise.md +0 -30
  30. data/docs/usage/execution/run.md +0 -70
  31. data/docs/usage/execution/triggered.md +0 -48
  32. data/docs/usage/guards.md +0 -51
  33. data/docs/usage/guards/between.md +0 -30
  34. data/docs/usage/guards/not_if.md +0 -41
  35. data/docs/usage/guards/only_if.md +0 -40
  36. data/docs/usage/index.md +0 -11
  37. data/docs/usage/items.md +0 -66
  38. data/docs/usage/items/contact.md +0 -84
  39. data/docs/usage/items/dimmer.md +0 -147
  40. data/docs/usage/items/groups.md +0 -76
  41. data/docs/usage/items/number.md +0 -225
  42. data/docs/usage/items/string.md +0 -49
  43. data/docs/usage/items/switch.md +0 -85
  44. data/docs/usage/misc.md +0 -7
  45. data/docs/usage/misc/actions.md +0 -108
  46. data/docs/usage/misc/duration.md +0 -21
  47. data/docs/usage/misc/gems.md +0 -25
  48. data/docs/usage/misc/logging.md +0 -21
  49. data/docs/usage/misc/metadata.md +0 -128
  50. data/docs/usage/misc/store_states.md +0 -42
  51. data/docs/usage/misc/time_of_day.md +0 -69
  52. data/docs/usage/misc/timers.md +0 -67
  53. data/docs/usage/rule.md +0 -43
  54. data/docs/usage/things.md +0 -29
  55. data/docs/usage/triggers.md +0 -8
  56. data/docs/usage/triggers/changed.md +0 -57
  57. data/docs/usage/triggers/channel.md +0 -54
  58. data/docs/usage/triggers/command.md +0 -69
  59. data/docs/usage/triggers/cron.md +0 -19
  60. data/docs/usage/triggers/every.md +0 -76
  61. data/docs/usage/triggers/updated.md +0 -78
  62. data/openhab-scripting.gemspec +0 -30
  63. data/openhab_rules/warmup.rb +0 -5
data/README.md DELETED
@@ -1,23 +0,0 @@
1
- # JRuby OpenHAB Scripting Library
2
-
3
-
4
- <p align="center">
5
- <img alt="GitHub release (latest SemVer including pre-releases)" src="https://img.shields.io/github/v/release/boc-tothefuture/openhab-jruby?include_prereleases"/>
6
- <img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/boc-tothefuture/openhab-jruby/Openhab-JRuby-Scripting"/>
7
- <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/boc-tothefuture/openhab-jruby"/>
8
- <img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/boc-tothefuture/openhab-jruby">
9
- <img alt="SemVer version observance" src="https://img.shields.io/badge/semver-2.0.0-blue"/>
10
- <a href="https://conventionalcommits.org"/>
11
- <img alt="Convention commits observance" src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg"/>
12
- </a>
13
- </p>
14
-
15
-
16
- ## Usage
17
- Usage documentation is located [here](https://boc-tothefuture.github.io/openhab-jruby/).
18
-
19
- ## Discussion
20
- Please see [this thread](https://community.openhab.org/t/jruby-openhab-rules-system/110598) on the OpenHAB forum for further discussion. Ideas and suggestions are welcome.
21
-
22
- ## Library Status
23
- This is an alpha and syntax and all elements are subject to change as the library evolves.
data/Rakefile DELETED
@@ -1,406 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rake/packagetask'
4
- require 'rubocop/rake_task'
5
- require 'bundler/gem_tasks'
6
- require 'yard'
7
- require 'English'
8
- require 'time'
9
- require 'cucumber'
10
- require 'cucumber/rake/task'
11
- require 'open-uri'
12
- require 'tty-command'
13
- require 'process_exists'
14
- require 'cuke_linter'
15
- require 'erb'
16
-
17
- require_relative 'lib/openhab/version'
18
-
19
- PACKAGE_DIR = 'pkg'
20
- TMP_DIR = 'tmp'
21
- OPENHAB_DIR = File.join(TMP_DIR, 'openhab')
22
- DOCS_DIR = 'doc'
23
- OPENHAB_VERSION = '3.0.0'
24
- JRUBY_BUNDLE = File.realpath(Dir.glob('bundle/*.jar').first)
25
- KARAF_CLIENT_PATH = File.join(OPENHAB_DIR, 'runtime/bin/client')
26
- KARAF_CLIENT_ARGS = [KARAF_CLIENT_PATH, '-p', 'habopen'].freeze
27
- KARAF_CLIENT = KARAF_CLIENT_ARGS.join(' ')
28
-
29
- DEPLOY_DIR = File.join(OPENHAB_DIR, 'conf/automation/jsr223/ruby/personal')
30
- LIB_DIR = File.join(OPENHAB_DIR, 'conf/automation/lib/ruby/lib/')
31
- STATE_DIR = File.join(OPENHAB_DIR, 'rake_state')
32
- YARD_DIR = File.join('docs', 'yard')
33
- CUCUMBER_LOGS = File.join(TMP_DIR, 'cucumber_logs')
34
- SERVICES_CONFIG = File.join(OPENHAB_DIR, 'conf/services/jruby.cfg')
35
-
36
- CLEAN << PACKAGE_DIR
37
- CLEAN << DEPLOY_DIR
38
- CLEAN << CUCUMBER_LOGS
39
- CLEAN << YARD_DIR
40
- CLEAN << '.yardoc'
41
-
42
- CLOBBER << OPENHAB_DIR
43
-
44
- desc 'Generate Yard docs'
45
- task :yard do
46
- YARD::Rake::YardocTask.new do |t|
47
- t.files = ['lib/**/*.rb'] # optional
48
- t.stats_options = ['--list-undoc'] # optional
49
- end
50
- end
51
-
52
- RuboCop::RakeTask.new do |task|
53
- task.patterns = ['lib/**/*.rb', 'test/**/*.rb']
54
- task.fail_on_error = false
55
- end
56
-
57
- desc 'Lint Code'
58
- task :lint do
59
- Rake::Task['rubocop'].invoke
60
- CukeLinter.lint
61
- end
62
-
63
- desc 'Start Documentation Server'
64
- task docs: :yard do
65
- sh 'bundle exec jekyll clean'
66
- sh 'bundle exec jekyll server --config docs/_config.yml'
67
- end
68
-
69
- task :yard_server do
70
- sh 'bundle exec guard'
71
- end
72
-
73
- desc 'Run Cucumber Features'
74
- task :features, [:feature] => ['openhab:warmup', 'openhab:deploy', CUCUMBER_LOGS] do |_, args|
75
- # Rake::Task['openhab:warmup'].execute
76
- Cucumber::Rake::Task.new(:features) do |t|
77
- t.cucumber_opts = "--tags 'not @wip and not @not_implemented' --format pretty #{args[:feature]}"
78
- end
79
- end
80
-
81
- desc 'Get OpenHAB-JRuby Version'
82
- task :version do
83
- puts OpenHAB::VERSION
84
- end
85
-
86
- namespace :gh do
87
- zip_path = ''
88
-
89
- directory PACKAGE_DIR
90
-
91
- desc 'Package for release'
92
- task package: [PACKAGE_DIR] do
93
- zip_filename = "OpenHABJRuby-#{OpenHAB::VERSION}.zip"
94
- zip_path = File.join(PACKAGE_DIR, zip_filename)
95
- target_dir = 'lib/'
96
- sh 'zip', '-r', zip_path, target_dir
97
- end
98
-
99
- desc 'Package for release'
100
- task release: :package do
101
- sh 'gh', 'release', 'create', OpenHAB::VERSION, '-p', '-F', 'CHANGELOG.md', zip_path, JRUBY_BUNDLE
102
- end
103
- end
104
-
105
- namespace :openhab do
106
- def command_success?(command)
107
- cmd = TTY::Command.new(printer: :null)
108
- cmd.run!(command).success?
109
- end
110
-
111
- def running?(fail_on_error: false)
112
- karaf_status = File.join(OPENHAB_DIR, 'runtime/bin/status')
113
-
114
- return false unless File.exist? karaf_status
115
-
116
- if fail_on_error
117
- fail_on_error(karaf_status)
118
- true
119
- else
120
- command_success? karaf_status
121
- end
122
- end
123
-
124
- # There can be a delay between when OpenHAB is running and ready to process commands
125
- def ready?(fail_on_error: false)
126
- return unless running?
127
-
128
- if fail_on_error
129
- fail_on_error("#{KARAF_CLIENT} 'system:version'")
130
- true
131
- else
132
- cmd = TTY::Command.new(printer: :null)
133
- cmd.run!("#{KARAF_CLIENT} 'system:version'").success?
134
- end
135
- end
136
-
137
- def ensure_openhab_running
138
- abort('Openhab not running') unless running?
139
- end
140
-
141
- def print_and_flush(string)
142
- print string
143
- $stdout.flush
144
- end
145
-
146
- def fail_on_error(command, env = {})
147
- cmd = TTY::Command.new
148
- out, = cmd.run(command, env: env, only_output_on_error: true)
149
- out
150
- end
151
-
152
- def karaf(command)
153
- fail_on_error("#{KARAF_CLIENT} '#{command}'")
154
- end
155
-
156
- def wait_for(duration, task)
157
- print_and_flush "Waiting for up to #{duration} seconds for #{task}"
158
- duration.times do
159
- if yield
160
- puts ''
161
- return true
162
- end
163
-
164
- print_and_flush '.'
165
- sleep 1
166
- end
167
- puts ''
168
- false
169
- end
170
-
171
- def gem_home
172
- full_path = File.realpath OPENHAB_DIR
173
- File.join(full_path, '/conf/automation/lib/ruby/gem_home')
174
- end
175
-
176
- def ruby_env
177
- # { 'RUBYLIB' => File.join(full_path, '/conf/automation/lib/ruby/lib'),
178
- { 'GEM_HOME' => gem_home }
179
- end
180
-
181
- def state(task)
182
- Rake::Task[STATE_DIR.to_s].execute
183
- task_file = File.join(STATE_DIR, task)
184
- if File.exist? task_file
185
- puts "Skipping task(#{task}), task already up to date"
186
- else
187
- yield
188
- touch task_file
189
- end
190
- end
191
-
192
- directory OPENHAB_DIR
193
- directory DEPLOY_DIR
194
- directory LIB_DIR
195
- directory STATE_DIR
196
- directory CUCUMBER_LOGS
197
-
198
- desc 'Download Openhab and unzip it'
199
- task download: [OPENHAB_DIR] do |task|
200
- state(task.name) do
201
- openhab_zip = "openhab-#{OPENHAB_VERSION}.zip"
202
- Dir.chdir(OPENHAB_DIR) do
203
- puts "Downloading #{openhab_zip}"
204
- IO.copy_stream(
205
- open("https://openhab.jfrog.io/openhab/libs-release/org/openhab/distro/openhab/#{OPENHAB_VERSION}/openhab-#{OPENHAB_VERSION}.zip"), openhab_zip
206
- )
207
- fail_on_error("unzip #{openhab_zip}")
208
- rm openhab_zip
209
- end
210
- end
211
- end
212
-
213
- desc 'Add RubyLib and GEM_HOME to start.sh'
214
- task rubylib: :download do |task|
215
- # state(task.name) do
216
- # paths = ruby_env
217
- # Dir.chdir(OPENHAB_DIR) do
218
- # start_file = 'start.sh'
219
- #
220
- # settings = {
221
- # /^export RUBYLIB=/ => "export RUBYLIB=#{paths['RUBYLIB']}\n",
222
- # /^export GEM_HOME=/ => "export GEM_HOME=#{paths['GEM_HOME']}\n"
223
- # }
224
- #
225
- # settings.each do |regex, line|
226
- # lines = File.readlines(start_file)
227
- # unless lines.grep(regex).any?
228
- # lines.insert(-2, line)
229
- # File.write(start_file, lines.join)
230
- # end
231
- # end
232
- # end
233
- # end
234
- end
235
-
236
- desc 'Setup services config'
237
- task services: :download do |task|
238
- state(task.name) do
239
- services_config = ERB.new <<~EOF
240
- org.openhab.automation.jrubyscripting:gem_home=<%= gem_home %>
241
- EOF
242
- File.write(SERVICES_CONFIG, services_config.result)
243
- end
244
- end
245
-
246
- def bundle_id
247
- karaf('bundle:list --no-format org.openhab.automation.jrubyscripting').lines.last[/^\d\d\d/].chomp
248
- end
249
-
250
- desc 'Install JRuby Bundle'
251
- task install: [:download, :rubylib, :services, DEPLOY_DIR] do |task|
252
- state(task.name) do
253
- start
254
- if karaf('bundle:list --no-format org.openhab.automation.jrubyscripting').include?('Active')
255
- puts 'Bundle Active, no action taken'
256
- else
257
- unless karaf('bundle:list --no-format org.openhab.automation.jrubyscripting').include?('Installed')
258
- karaf("bundle:install file://#{JRUBY_BUNDLE}")
259
- end
260
- karaf("bundle:start #{bundle_id}")
261
- end
262
- end
263
- end
264
-
265
- desc 'Upgrade JRuby Bundle'
266
- task :upgrade, [:file] do |_, args|
267
- start
268
- if karaf('bundle:list --no-format org.openhab.automation.jrubyscripting').include?('Active')
269
- karaf("bundle:update #{bundle_id} file://#{args[:file]}")
270
- else
271
- abort "Bundle not installed, can't upgrade"
272
- end
273
- end
274
-
275
- desc 'Configure'
276
- task configure: %i[download] do |task|
277
- # Set log levels
278
- state(task.name) do
279
- start
280
- karaf('log:set TRACE jsr223')
281
- karaf('log:set TRACE org.openhab.core.automation')
282
- karaf('log:set TRACE org.openhab.binding.jrubyscripting')
283
- karaf('openhab:users add foo foo administrator')
284
- sh 'rsync', '-aih', 'config/userdata/', File.join(OPENHAB_DIR, 'userdata')
285
- end
286
- end
287
-
288
- def start
289
- if running?
290
- puts 'OpenHAB already running'
291
- return
292
- end
293
-
294
- env = ruby_env
295
- env = env.merge({ 'KARAF_REDIRECT' => File.join(File.realpath(TMP_DIR), 'karaf.log'),
296
- 'EXTRA_JAVA_OPTS' => '-Xmx4g' })
297
-
298
- Dir.chdir(OPENHAB_DIR) do
299
- puts 'Starting OpenHAB'
300
- pid = spawn(env, 'runtime/bin/start')
301
- Process.detach(pid)
302
- end
303
-
304
- wait_for(20, 'OpenHAB to start') { running? }
305
- abort 'Unable to start OpenHAB' unless running?(fail_on_error: true)
306
-
307
- wait_for(20, 'OpenHAB to become ready') { ready? }
308
- abort 'OpenHAB did not become ready' unless ready?(fail_on_error: true)
309
-
310
- puts 'OpenHAB started and ready'
311
- end
312
-
313
- desc 'Start OpenHAB'
314
- task start: %i[download] do
315
- start
316
- end
317
-
318
- def stop
319
- if running?
320
- pid = File.read(File.join(OPENHAB_DIR, 'userdata/tmp/karaf.pid')).chomp.to_i
321
- Dir.chdir(OPENHAB_DIR) do
322
- fail_on_error('runtime/bin/stop')
323
- end
324
- stopped = wait_for(20, 'OpenHAB to stop') { Process.exists?(pid) == false }
325
- abort 'Unable to stop OpenHAB' unless stopped
326
- end
327
-
328
- puts 'OpenHAB Stopped'
329
- end
330
-
331
- desc 'Stop OpenHAB'
332
- task :stop do
333
- stop
334
- end
335
-
336
- def restart
337
- puts 'Restarting OpenHAB'
338
- stop
339
- start
340
- puts 'OpenHAB Restarted'
341
- end
342
-
343
- desc 'Clobber local Openhab'
344
- task :clobber do
345
- stop if running?
346
-
347
- rm_rf OPENHAB_DIR
348
- end
349
-
350
- desc 'Create a Dev Dump in OpenHAB and wait until its complete'
351
- task :dump do
352
- dumps = File.join(OPENHAB_DIR, 'userdata', '*.zip')
353
-
354
- puts 'Deleting any existing dumps'
355
- dump = Dir[dumps].each { |dump_file| rm dump_file }
356
-
357
- karaf('dev:dump-create')
358
-
359
- wait_for(30, 'Dump to be created') do
360
- Dir[dumps].any?
361
- end
362
- dump = Dir[dumps].first
363
- puts "Found dev dump #{dump}"
364
- dump_sizes = Array.new(10)
365
- wait_for(120, 'Dump size to not increase for 10 seconds') do
366
- dump_sizes << File.size(dump)
367
- dump_sizes.last(10).uniq.length == 1
368
- end
369
- end
370
-
371
- desc 'Warmup OpenHab environment'
372
- task warmup: [:prepare, DEPLOY_DIR] do
373
- start
374
- openhab_log = File.join(OPENHAB_DIR, 'userdata/logs/openhab.log')
375
-
376
- file = File.join('openhab_rules', 'warmup.rb')
377
- dest_file = File.join(DEPLOY_DIR, "#{File.basename(file, '.rb')}_#{Time.now.to_i}.rb")
378
- cp file, dest_file
379
- wait_for(20, 'OpenHAB to warmup') do
380
- File.foreach(openhab_log).grep(/OpenHAB warmup complete/).any?
381
- end
382
- rm dest_file
383
- end
384
-
385
- desc 'Prepare local Openhab'
386
- task prepare: [:download, :rubylib, :install, :configure, :deploy, CUCUMBER_LOGS]
387
-
388
- desc 'Setup local Openhab'
389
- task setup: %i[prepare stop]
390
-
391
- desc 'Deploy to local Openhab'
392
- task deploy: %i[download build] do |_task|
393
- gem_file = File.join(PACKAGE_DIR, "openhab-scripting-#{OpenHAB::VERSION}.gem")
394
- fail_on_error("gem install #{gem_file}", ruby_env)
395
- end
396
-
397
- desc 'Deploy adhoc test Openhab'
398
- task adhoc: :deploy do
399
- mkdir_p DEPLOY_DIR
400
- Dir.glob(File.join(DEPLOY_DIR, '*.rb')) { |file| rm file }
401
- Dir.glob(File.join('test/', '*.rb')) do |file|
402
- dest_name = "#{File.basename(file, '.rb')}_#{Time.now.to_i}.rb"
403
- cp file, File.join(deploy_dir, dest_name)
404
- end
405
- end
406
- end
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'openhab/scripting'
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here