rspec-openhab-scripting 0.0.6-java → 0.0.7-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36b9bb280e4fd6893f93a5ca0197dd4a7a08c286b4cc6835c44f81c487e497fe
4
- data.tar.gz: 6390495a9d8ff5a522f86f4e1d50155bf93d45a14a59b9ba3b9147c49cd27548
3
+ metadata.gz: 76dfb6fa24e9d5efd4f0857cde57ae0c299f7ff5b6c16d08981fe04aa5ab3f52
4
+ data.tar.gz: b587bf33488da0f9a095eba35997ae4e615b6f8729ed11e1f8c514d1a195e7e1
5
5
  SHA512:
6
- metadata.gz: c571aa03ed3fc7521be9e65924b274204a7ab4382101467af88847350632a7cc159795cbb238765af6fd6b0abb41b2934b656037571de5a3936972905784255e
7
- data.tar.gz: 757a9bcfbbe1d5361500413b5e6cd74b6a1eda00df2483abb22e200f4d1ae3845fa6bfafcb4501b3b1060f91710a721e1727db3a695447a90aa7f91ef3b8643a
6
+ metadata.gz: 80961c7142353a5cd237414ed8a854a1ce33ef4fe0a32c758bf3a41921e6a3cf92e811fc635b9c72cc5e2d59cf1eb92710ad0a8cbb6cf6a357400180e8c4ba56
7
+ data.tar.gz: a3cef22e84c40c6f9780830873a0ac1c548e7076c81df9afe9d8fbe9e9bb30e9c316dc6352d329e1c7d95c0be470ebb319f2a7d2c3668c9b8462b24e7e45ebca
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ module Actions
6
+ # redefine these to do nothing so that rules won't fail
7
+ def notify(msg, email: nil) # rubocop:disable Lint/UnusedMethodArgument:
8
+ logger.debug("notify: #{msg}")
9
+ end
10
+
11
+ def say(text, voice: nil, sink: nil, volume: nil) # rubocop:disable Lint/UnusedMethodArgument:
12
+ logger.debug("say: #{text}")
13
+ end
14
+
15
+ def play_sound(filename, sink: nil, volume: nil) # rubocop:disable Lint/UnusedMethodArgument:
16
+ logger.debug("play_sound: #{filename}")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -213,10 +213,11 @@ module OpenHAB
213
213
  se = org.openhab.core.automation.module.script.rulesupport.internal
214
214
  .RuleSupportScriptExtension.new(rr, srp, scmhf, scmtp, spmhf)
215
215
  sew = ScriptExtensionManagerWrapper.new(se)
216
- $se = $scriptExtension = sew # rubocop:disable Style/GlobalVars
216
+ $se = $scriptExtension = sew
217
217
 
218
218
  # need to create some singletons referencing registries
219
- org.openhab.core.model.script.ScriptServiceUtil.new(ir, tr, ep, nil, nil)
219
+ scheduler = org.openhab.core.internal.scheduler.SchedulerImpl.new
220
+ org.openhab.core.model.script.ScriptServiceUtil.new(ir, tr, ep, nil, scheduler)
220
221
  org.openhab.core.model.script.internal.engine.action.SemanticsActionService.new(ir)
221
222
 
222
223
  # link up event bus infrastructure
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Style/GlobalVars
4
3
  module RSpec
5
4
  module OpenHAB
6
5
  module Items
@@ -76,4 +75,3 @@ module RSpec
76
75
  end
77
76
  end
78
77
  end
79
- # rubocop:enable Style/GlobalVars
@@ -1,11 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
- org.openhab.core.items.GenericItem.field_reader :eventPublisher
5
-
6
- # rubocop:disable Style/GlobalVars
7
4
  config.before(:each) do
8
- ep = $ir.eventPublisher
5
+ ep = $ir.event_publisher
9
6
 
10
7
  # stash event publishers to avoid triggering any rules
11
8
  $ir.for_each do |_provider, item|
@@ -20,5 +17,4 @@ RSpec.configure do |config|
20
17
  item.event_publisher = ep
21
18
  end
22
19
  end
23
- # rubocop:enable Style/GlobalVars
24
20
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:each) do
5
+ OpenHAB::DSL::Timers.timer_manager.cancel_all
6
+ end
7
+ config.after(:each) do
8
+ OpenHAB::DSL::Timers.timer_manager.cancel_all
9
+ end
10
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OpenHAB
5
- VERSION = "0.0.6"
5
+ VERSION = "0.0.7"
6
6
  end
7
7
  end
@@ -34,10 +34,10 @@ maven_require do
34
34
  require "jar tech.units, indriya, 2.1.3"
35
35
 
36
36
  require "jar org.openhab.core.bundles, org.openhab.core, #{openhab_version}"
37
- require "jar org.openhab.core.bundles, org.openhab.core.config.core, #{openhab_version}"
38
37
  require "jar org.openhab.core.bundles, org.openhab.core.automation, #{openhab_version}"
39
38
  require "jar org.openhab.core.bundles, org.openhab.core.automation.module.script, #{openhab_version}"
40
39
  require "jar org.openhab.core.bundles, org.openhab.core.automation.module.script.rulesupport, #{openhab_version}"
40
+ require "jar org.openhab.core.bundles, org.openhab.core.config.core, #{openhab_version}"
41
41
  require "jar org.openhab.core.bundles, org.openhab.core.io.monitor, #{openhab_version}"
42
42
  require "jar org.openhab.core.bundles, org.openhab.core.model.core, #{openhab_version}"
43
43
  require "jar org.openhab.core.bundles, org.openhab.core.model.script, #{openhab_version}"
@@ -64,13 +64,11 @@ OpenHAB::DSL::Imports.import_presets
64
64
 
65
65
  require "openhab"
66
66
 
67
+ require "rspec/openhab/actions"
67
68
  require "rspec/openhab/core/cron_scheduler"
68
69
 
69
- # openhab-scripting uses a require_relative, so our override doesn't get used
70
- OpenHAB::DSL.send(:remove_const, :Timer)
71
- require_relative "rspec/openhab/dsl/timers/timer"
72
-
73
70
  # RSpec additions
71
+ require "rspec/core"
74
72
  require "rspec/openhab/dsl/rules/rspec"
75
73
  require "rspec/openhab/state"
76
74
  require "rspec/openhab/trigger"
@@ -92,6 +90,6 @@ OPENHAB_AUTOMATION_PATH = "#{org.openhab.core.OpenHAB.config_folder}/automation/
92
90
  Dir["#{OPENHAB_AUTOMATION_PATH}/*.rb"].each do |f|
93
91
  load f
94
92
  rescue Exception => e # rubocop:disable Lint/RescueException
95
- warn "Failed loading #{f}: #{e}"
93
+ warn "Failed loading #{f}: #{e.inspect}"
96
94
  warn e.backtrace
97
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: java
6
6
  authors:
7
7
  - Cody Cutrer
@@ -172,6 +172,7 @@ extra_rdoc_files: []
172
172
  files:
173
173
  - lib/rspec-openhab-scripting.rb
174
174
  - lib/rspec-openhab-scripting_jars.rb
175
+ - lib/rspec/openhab/actions.rb
175
176
  - lib/rspec/openhab/api.rb
176
177
  - lib/rspec/openhab/core/cron_scheduler.rb
177
178
  - lib/rspec/openhab/core/load_path.rb
@@ -181,9 +182,9 @@ files:
181
182
  - lib/rspec/openhab/core/script_handling.rb
182
183
  - lib/rspec/openhab/dsl/imports.rb
183
184
  - lib/rspec/openhab/dsl/rules/rspec.rb
184
- - lib/rspec/openhab/dsl/timers/timer.rb
185
185
  - lib/rspec/openhab/items.rb
186
186
  - lib/rspec/openhab/state.rb
187
+ - lib/rspec/openhab/timer.rb
187
188
  - lib/rspec/openhab/trigger.rb
188
189
  - lib/rspec/openhab/version.rb
189
190
  - lib/rspec/openhab/wait.rb
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- class Timer
6
- #
7
- # Create a new Timer Object
8
- #
9
- # @param [Duration] duration Duration until timer should fire
10
- # @param [Block] block Block to execute when timer fires
11
- #
12
- def initialize(duration:, thread_locals: {}, &block) # rubocop:disable Lint/UnusedMethodArgument
13
- @duration = duration
14
-
15
- Timers.timer_manager.add(self)
16
- end
17
-
18
- def reschedule(_duration = nil)
19
- Timers.timer_manager.add(self)
20
- end
21
-
22
- #
23
- # Cancel timer
24
- #
25
- # @return [Boolean] True if cancel was successful, false otherwise
26
- #
27
- def cancel
28
- Timers.timer_manager.delete(self)
29
- end
30
-
31
- def terminated?; end
32
- alias_method :has_terminated, :terminated?
33
-
34
- def is_active # rubocop:disable Naming/PredicateName
35
- false
36
- end
37
-
38
- private
39
-
40
- def timer_block
41
- proc do
42
- Timers.timer_manager.delete(self)
43
- yield(self)
44
- end
45
- end
46
- end
47
-
48
- #
49
- # Convert TemporalAmount (Duration), seconds (float, integer), and Ruby Time to ZonedDateTime
50
- # Note: TemporalAmount is added to now
51
- #
52
- # @param [Object] timestamp to convert
53
- #
54
- # @return [ZonedDateTime]
55
- #
56
- def self.to_zdt(timestamp)
57
- logger.trace("Converting #{timestamp} (#{timestamp.class}) to ZonedDateTime")
58
- return unless timestamp
59
-
60
- case timestamp
61
- when Java::JavaTimeTemporal::TemporalAmount then ZonedDateTime.now.plus(timestamp)
62
- when ZonedDateTime then timestamp
63
- when Time then timestamp.to_java(ZonedDateTime)
64
- else
65
- to_zdt(seconds_to_duration(timestamp)) ||
66
- raise(ArgumentError, "Timestamp must be a ZonedDateTime, a Duration, a Numeric, or a Time object")
67
- end
68
- end
69
-
70
- #
71
- # Convert numeric seconds to a Duration object
72
- #
73
- # @param [Float, Integer] secs The number of seconds in integer or float
74
- #
75
- # @return [Duration]
76
- #
77
- def self.seconds_to_duration(secs)
78
- return unless secs
79
-
80
- if secs.respond_to?(:to_f)
81
- secs.to_f.seconds
82
- elsif secs.respond_to?(:to_i)
83
- secs.to_i.seconds
84
- end
85
- end
86
- end
87
- end