openhab-jrubyscripting 5.0.0.rc5 → 5.0.0.rc8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/core/actions.rb +6 -6
  3. data/lib/openhab/core/dependency_tracking.rb +34 -0
  4. data/lib/openhab/core/entity_lookup.rb +132 -78
  5. data/lib/openhab/core/events/item_channel_link.rb +2 -2
  6. data/lib/openhab/core/events/item_command_event.rb +1 -1
  7. data/lib/openhab/core/events/item_event.rb +2 -2
  8. data/lib/openhab/core/events/item_state_changed_event.rb +1 -1
  9. data/lib/openhab/core/events/thing.rb +1 -1
  10. data/lib/openhab/core/items/accepted_data_types.rb +2 -2
  11. data/lib/openhab/core/items/contact_item.rb +1 -1
  12. data/lib/openhab/core/items/dimmer_item.rb +2 -2
  13. data/lib/openhab/core/items/generic_item.rb +45 -224
  14. data/lib/openhab/core/items/group_item.rb +5 -3
  15. data/lib/openhab/core/items/image_item.rb +2 -2
  16. data/lib/openhab/core/items/item.rb +219 -0
  17. data/lib/openhab/core/items/metadata/hash.rb +1 -1
  18. data/lib/openhab/core/items/persistence.rb +4 -5
  19. data/lib/openhab/core/items/provider.rb +2 -2
  20. data/lib/openhab/core/items/proxy.rb +68 -7
  21. data/lib/openhab/core/items/registry.rb +6 -6
  22. data/lib/openhab/core/items/semantics/enumerable.rb +6 -6
  23. data/lib/openhab/core/items/semantics.rb +8 -7
  24. data/lib/openhab/core/items.rb +2 -1
  25. data/lib/openhab/core/provider.rb +14 -7
  26. data/lib/openhab/core/rules/registry.rb +2 -2
  27. data/lib/openhab/core/rules.rb +1 -1
  28. data/lib/openhab/core/script_handling.rb +6 -6
  29. data/lib/openhab/core/things/channel.rb +1 -1
  30. data/lib/openhab/core/things/channel_uid.rb +2 -2
  31. data/lib/openhab/core/things/item_channel_link.rb +2 -2
  32. data/lib/openhab/core/things/links/provider.rb +2 -2
  33. data/lib/openhab/core/things/registry.rb +1 -1
  34. data/lib/openhab/core/things/thing.rb +1 -1
  35. data/lib/openhab/core/types/date_time_type.rb +4 -4
  36. data/lib/openhab/core/types/hsb_type.rb +2 -2
  37. data/lib/openhab/core/types/quantity_type.rb +1 -1
  38. data/lib/openhab/core/types.rb +1 -1
  39. data/lib/openhab/core/uid.rb +1 -1
  40. data/lib/openhab/core/value_cache.rb +188 -0
  41. data/lib/openhab/core.rb +57 -15
  42. data/lib/openhab/core_ext/ruby/symbol.rb +7 -0
  43. data/lib/openhab/dsl/items/builder.rb +17 -10
  44. data/lib/openhab/dsl/items/ensure.rb +5 -5
  45. data/lib/openhab/dsl/items/timed_command.rb +4 -4
  46. data/lib/openhab/dsl/rules/automation_rule.rb +53 -39
  47. data/lib/openhab/dsl/rules/builder.rb +128 -79
  48. data/lib/openhab/dsl/rules/guard.rb +5 -5
  49. data/lib/openhab/dsl/rules/name_inference.rb +20 -1
  50. data/lib/openhab/dsl/rules/rule_triggers.rb +3 -3
  51. data/lib/openhab/dsl/rules/terse.rb +1 -0
  52. data/lib/openhab/dsl/rules/triggers/changed.rb +26 -23
  53. data/lib/openhab/dsl/rules/triggers/command.rb +6 -5
  54. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +2 -2
  55. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +2 -2
  56. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +6 -6
  57. data/lib/openhab/dsl/rules/triggers/updated.rb +5 -5
  58. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +11 -12
  59. data/lib/openhab/dsl/things/builder.rb +73 -14
  60. data/lib/openhab/dsl/version.rb +2 -2
  61. data/lib/openhab/dsl.rb +43 -17
  62. data/lib/openhab/log.rb +5 -5
  63. data/lib/openhab/rspec/configuration.rb +5 -5
  64. data/lib/openhab/rspec/example_group.rb +1 -1
  65. data/lib/openhab/rspec/helpers.rb +4 -4
  66. data/lib/openhab/rspec/hooks.rb +19 -1
  67. data/lib/openhab/rspec/karaf.rb +12 -19
  68. data/lib/openhab/rspec/suspend_rules.rb +2 -1
  69. metadata +7 -3
@@ -52,7 +52,7 @@ module OpenHAB
52
52
  module RSpec
53
53
  #
54
54
  # Provides helper methods for use in specs, to easily work with and adjust
55
- # the OpenHAB environment.
55
+ # the openHAB environment.
56
56
  #
57
57
  # These methods are automatically available in RSpec spec blocks, as well
58
58
  # as other per-spec hooks like `before` and `after`. You can also call them
@@ -175,7 +175,7 @@ module OpenHAB
175
175
  end
176
176
 
177
177
  #
178
- # Require all files configured to be autorequired with the jrubyscripting addon in OpenHAB.
178
+ # Require all files configured to be autorequired with the jrubyscripting addon in openHAB.
179
179
  #
180
180
  # This method is normally called by RSpec hooks.
181
181
  #
@@ -306,7 +306,7 @@ module OpenHAB
306
306
  end
307
307
 
308
308
  #
309
- # Install an OpenHAB addon
309
+ # Install an openHAB addon
310
310
  #
311
311
  # @param [String] addon_id The addon id, such as "binding-mqtt"
312
312
  # @param [true,false] wait Wait until OSGi has confirmed the bundle is installed and running before returning.
@@ -348,7 +348,7 @@ module OpenHAB
348
348
  end
349
349
  end
350
350
 
351
- # @return [String] The filename of the OpenHAB log.
351
+ # @return [String] The filename of the openHAB log.
352
352
  def log_file
353
353
  "#{java.lang.System.get_property("openhab.logdir", nil)}/openhab.log"
354
354
  end
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  #
5
5
  # This module contains helper methods, hooks, and infrastracture to
6
- # boot OpenHAB inside of JRuby, and run RSpec (or other Ruby processes)
6
+ # boot openHAB inside of JRuby, and run RSpec (or other Ruby processes)
7
7
  # in that context.
8
8
  #
9
9
  # @see file:testing.md Testing Your Rules
@@ -11,6 +11,14 @@ module OpenHAB
11
11
  module RSpec
12
12
  Object.include Helpers if defined?(IRB)
13
13
 
14
+ # @!visibility private
15
+ module Hooks
16
+ class << self
17
+ attr_accessor :cache_script_extension
18
+ end
19
+ self.cache_script_extension = nil
20
+ end
21
+
14
22
  Helpers.launch_karaf(
15
23
  include_bindings: Configuration.include_bindings,
16
24
  include_jsondb: Configuration.include_jsondb,
@@ -28,6 +36,15 @@ module OpenHAB
28
36
  Helpers.send(:set_up_autoupdates)
29
37
  Helpers.load_transforms
30
38
  Helpers.load_rules
39
+
40
+ if DSL.shared_cache
41
+ Hooks.cache_script_extension = OSGi.service(
42
+ "org.openhab.core.automation.module.script.ScriptExtensionProvider",
43
+ filter:
44
+ "(component.name=org.openhab.core.automation.module.script.rulesupport.internal.CacheScriptExtension)"
45
+ )
46
+ Hooks.cache_script_extension.class.field_reader :sharedCache
47
+ end
31
48
  end
32
49
 
33
50
  config.before do
@@ -79,6 +96,7 @@ module OpenHAB
79
96
  Timecop.return
80
97
  restore_autoupdate_items
81
98
  Mocks::PersistenceService.instance.reset
99
+ Hooks.cache_script_extension.sharedCache.clear if DSL.shared_cache
82
100
  end
83
101
  end
84
102
  end
@@ -20,6 +20,14 @@ module OpenHAB
20
20
  def get(type)
21
21
  @manager.get(type, "jruby")
22
22
  end
23
+
24
+ def default_presets
25
+ @manager.default_presets
26
+ end
27
+
28
+ def import_preset(preset)
29
+ @manager.find_preset(preset, "rspec")
30
+ end
23
31
  end
24
32
  private_constant :ScriptExtensionManagerWrapper
25
33
 
@@ -73,7 +81,7 @@ module OpenHAB
73
81
  service = org.apache.karaf.instance.core.internal.InstanceServiceImpl.new
74
82
  settings = org.apache.karaf.instance.core.InstanceSettings.new(0, 0, 0, path, nil, nil, nil)
75
83
  root_instance = service.instances.find(&:root?)
76
- raise ArgumentError "No root instance found to clone... has OpenHAB run yet?" unless root_instance
84
+ raise ArgumentError "No root instance found to clone... has openHAB run yet?" unless root_instance
77
85
 
78
86
  return if service.get_instance("rspec")
79
87
 
@@ -121,7 +129,7 @@ module OpenHAB
121
129
  launch_karaf
122
130
  at_exit do
123
131
  @main.destroy
124
- # OSGi/OpenHAB leave a ton of threads around. Kill ourselves ASAP
132
+ # OSGi/openHAB leave a ton of threads around. Kill ourselves ASAP
125
133
  code = if $!.nil? || ($!.is_a?(SystemExit) && $!.success?)
126
134
  0
127
135
  elsif $!.is_a?(SystemExit)
@@ -566,21 +574,6 @@ module OpenHAB
566
574
  wait_for_service("org.openhab.core.automation.module.script.internal.ScriptExtensionManager") do |sem|
567
575
  # since we're not created by the ScriptEngineManager, this never gets set; manually set it
568
576
  $se = $scriptExtension = ScriptExtensionManagerWrapper.new(sem)
569
- scope_values = sem.find_default_presets("rspec")
570
- scope_values = scope_values.entry_set.to_a
571
-
572
- scope_values.each do |entry|
573
- key = entry.key
574
- value = entry.value
575
- # convert Java classes to Ruby classes
576
- value = value.ruby_class if value.is_a?(java.lang.Class) # rubocop:disable Lint/UselessAssignment
577
- # variables are globals; constants go into the global namespace
578
- key = case key[0]
579
- when "a".."z" then "$#{key}"
580
- when "A".."Z" then "::#{key}"
581
- end
582
- eval("#{key} = value unless defined?(#{key})", nil, __FILE__, __LINE__) # rubocop:disable Security/Eval
583
- end
584
577
  end
585
578
  end
586
579
 
@@ -731,7 +724,7 @@ module OpenHAB
731
724
  sls = OSGi.service("org.openhab.core.service.StartLevelService")
732
725
 
733
726
  unless sls
734
- # try a different (hacky!) way to get it, since in OpenHAB 3.2.0 it's not exposed as a service
727
+ # try a different (hacky!) way to get it, since in openHAB 3.2.0 it's not exposed as a service
735
728
  scr = OSGi.service("org.osgi.service.component.runtime.ServiceComponentRuntime")
736
729
  scr.class.field_reader :componentRegistry
737
730
  cr = scr.componentRegistry
@@ -771,7 +764,7 @@ module OpenHAB
771
764
  File.write("#{oh_userdata}/etc/org.apache.karaf.features.xml", <<~XML)
772
765
  <?xml version="1.0" encoding="UTF-8"?>
773
766
  <featuresProcessing xmlns="http://karaf.apache.org/xmlns/features-processing/v1.0.0" xmlns:f="http://karaf.apache.org/xmlns/features/v1.6.0">
774
- <!-- From OpenHAB 3.2.0 -->
767
+ <!-- From openHAB 3.2.0 -->
775
768
  <bundleReplacements>
776
769
  <bundle originalUri="mvn:org.ops4j.pax.logging/pax-logging-api/[0,2.0.13)" replacement="mvn:org.ops4j.pax.logging/pax-logging-api/2.0.13" mode="maven" />
777
770
  <bundle originalUri="mvn:org.ops4j.pax.logging/pax-logging-log4j2/[0,2.0.13)" replacement="mvn:org.ops4j.pax.logging/pax-logging-log4j2/2.0.13" mode="maven" />
@@ -18,7 +18,8 @@ module OpenHAB
18
18
  logger.trace { "Execute called with mod (#{mod&.to_string}) and inputs (#{inputs.inspect})" }
19
19
  logger.trace { "Event details #{inputs["event"].inspect}" } if inputs&.key?("event")
20
20
  trigger_conditions(inputs).process(mod: mod, inputs: inputs) do
21
- process_queue(create_queue(inputs), mod, inputs)
21
+ event = extract_event(inputs)
22
+ process_queue(create_queue(event), mod, event)
22
23
  end
23
24
  rescue Exception => e
24
25
  raise if defined?(::RSpec) && ::RSpec.current_example.example_group.propagate_exceptions?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-jrubyscripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.rc5
4
+ version: 5.0.0.rc8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-29 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -327,6 +327,7 @@ extra_rdoc_files: []
327
327
  files:
328
328
  - lib/openhab/core.rb
329
329
  - lib/openhab/core/actions.rb
330
+ - lib/openhab/core/dependency_tracking.rb
330
331
  - lib/openhab/core/entity_lookup.rb
331
332
  - lib/openhab/core/events.rb
332
333
  - lib/openhab/core/events/abstract_event.rb
@@ -346,6 +347,7 @@ files:
346
347
  - lib/openhab/core/items/generic_item.rb
347
348
  - lib/openhab/core/items/group_item.rb
348
349
  - lib/openhab/core/items/image_item.rb
350
+ - lib/openhab/core/items/item.rb
349
351
  - lib/openhab/core/items/location_item.rb
350
352
  - lib/openhab/core/items/metadata.rb
351
353
  - lib/openhab/core/items/metadata/hash.rb
@@ -408,6 +410,7 @@ files:
408
410
  - lib/openhab/core/types/un_def_type.rb
409
411
  - lib/openhab/core/types/up_down_type.rb
410
412
  - lib/openhab/core/uid.rb
413
+ - lib/openhab/core/value_cache.rb
411
414
  - lib/openhab/core_ext.rb
412
415
  - lib/openhab/core_ext/between.rb
413
416
  - lib/openhab/core_ext/java/class.rb
@@ -429,6 +432,7 @@ files:
429
432
  - lib/openhab/core_ext/ruby/date_time.rb
430
433
  - lib/openhab/core_ext/ruby/numeric.rb
431
434
  - lib/openhab/core_ext/ruby/range.rb
435
+ - lib/openhab/core_ext/ruby/symbol.rb
432
436
  - lib/openhab/core_ext/ruby/time.rb
433
437
  - lib/openhab/dsl.rb
434
438
  - lib/openhab/dsl/events.rb
@@ -528,5 +532,5 @@ requirements: []
528
532
  rubygems_version: 3.3.7
529
533
  signing_key:
530
534
  specification_version: 4
531
- summary: JRuby Helper Libraries for OpenHAB Scripting
535
+ summary: JRuby Helper Libraries for openHAB Scripting
532
536
  test_files: []