openhab-scripting 4.19.1 → 4.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96e1f3f4c2dd1c8239dcc6d72ac704fd06037f79367213210bd6854963449df0
4
- data.tar.gz: 75199e81a2b830e125056280c54703aae2db59a7a63aa290efc03f1bc17fcbbc
3
+ metadata.gz: 48c997bfb2b0275d7c7666b905eb1599e020c9d434965d9093613540b77460b1
4
+ data.tar.gz: a81a610e16bb811762faf1e7317432a86e7c332d7356b1b2bea827d674f1442c
5
5
  SHA512:
6
- metadata.gz: 78c8cfe716265aaecb8f96ec3470fb177ff3fd80f0f94611515482254970669d6ac43a0a62033b7e16e887a49a9ca2a56b56b54632dfddd96b0c2919017963bc
7
- data.tar.gz: e422f430aa68218e79b4f7b278fa613ea930361207da72ccfe467ff6597dd902b585e5ecb9e3a014eb20f10dd99132b294faeb380dd50768ccf001efcb6c8949
6
+ metadata.gz: ae48e5f3f7e607c81fd2343a094b88e1b6c2041dc398357401ede48a41f0259f60d7c100afc4e3bd3d5217f635cf0d31e77cf072fbbe2b3871bf4f2d85477d94
7
+ data.tar.gz: 2ad2e05fa15ebc3a6de85ed5de804935d7d48d3b3e6a442dce0846fb0ccf993d07c04d09bed6861d4eb0d1b247a4d20a2d045156f150c9e76105fa7f9a75c361
@@ -38,6 +38,7 @@ module OpenHAB
38
38
  config.guard = Guard::Guard.new(only_if: config.only_if, not_if: config.not_if)
39
39
  logger.trace { config.inspect }
40
40
  process_rule_config(config)
41
+ nil # Must return something other than the rule object. See https://github.com/boc-tothefuture/openhab-jruby/issues/438
41
42
  rescue StandardError => e
42
43
  re_raise_with_backtrace(e)
43
44
  end
@@ -41,7 +41,7 @@ module OpenHAB
41
41
 
42
42
  semaphore.synchronize do
43
43
  @timer = ScriptExecution.createTimer(
44
- ZonedDateTime.now.plus(@duration), timer_block(semaphore, &block)
44
+ ZonedDateTime.now.plus(to_duration(@duration)), timer_block(semaphore, &block)
45
45
  )
46
46
  @rule_timers = Thread.current[:rule_timers]
47
47
  super(@timer)
@@ -57,15 +57,13 @@ module OpenHAB
57
57
  # @return [Timer] Rescheduled timer instances
58
58
  #
59
59
  def reschedule(duration = nil)
60
- unless duration.nil? || duration.is_a?(Java::JavaTimeTemporal::TemporalAmount)
61
- raise ArgumentError, 'Supplied argument must be a duration'
62
- end
63
-
64
60
  duration ||= @duration
61
+
65
62
  Timers.timer_manager.add(self)
66
- @timer.reschedule(ZonedDateTime.now.plus(duration))
63
+ @timer.reschedule(ZonedDateTime.now.plus(to_duration(duration)))
67
64
  end
68
65
 
66
+ #
69
67
  # Cancel timer
70
68
  #
71
69
  # @return [Boolean] True if cancel was successful, false otherwise
@@ -92,6 +90,27 @@ module OpenHAB
92
90
  end
93
91
  }
94
92
  end
93
+
94
+ #
95
+ # Convert argument to a duration
96
+ #
97
+ # @params [Java::JavaTimeTemporal::TemporalAmount, #to_f, #to_i, nil] duration Duration
98
+ #
99
+ # @raise if duration cannot be used for a timer
100
+ #
101
+ # @return Argument converted to seconds if it responds to #to_f or #to_i, otherwise duration unchanged
102
+ #
103
+ def to_duration(duration)
104
+ if duration.nil? || duration.is_a?(Java::JavaTimeTemporal::TemporalAmount)
105
+ duration
106
+ elsif duration.respond_to?(:to_f)
107
+ duration.to_f.seconds
108
+ elsif duration.respond_to?(:to_i)
109
+ duration.to_i.seconds
110
+ else
111
+ raise ArgumentError, "Supplied argument '#{duration}' cannot be converted to a duration"
112
+ end
113
+ end
95
114
  end
96
115
  end
97
116
  end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.19.1'
8
+ VERSION = '4.20.0'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.19.1
4
+ version: 4.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell