openhab-scripting 4.19.1 → 4.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/dsl/rules/rule.rb +1 -0
- data/lib/openhab/dsl/timers/timer.rb +25 -6
- data/lib/openhab/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c997bfb2b0275d7c7666b905eb1599e020c9d434965d9093613540b77460b1
|
4
|
+
data.tar.gz: a81a610e16bb811762faf1e7317432a86e7c332d7356b1b2bea827d674f1442c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/openhab/version.rb
CHANGED