openhab-scripting 4.35.0 → 4.36.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 +4 -4
- data/lib/openhab/dsl/items/persistence.rb +4 -8
- data/lib/openhab/dsl/timers/timer.rb +39 -25
- data/lib/openhab/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f8ae7a88299903d5fe44ecc1a1bf2f16bdeb659545a567d1e86dfc908367694
|
4
|
+
data.tar.gz: 94db08cd7ee03e382db6d7b4ebed8b240ae4e354a7b62073b0a81cc1b7228cdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f8ea8b5f0ab16e602f002cf749102c4250bb3525fc6f7e18f11eafe294125d198d6a85c5565bfc29629024dad0f5823ef0a298e7e90f7aa776030b84df4a25f
|
7
|
+
data.tar.gz: 9a04fb5c20858fbe6b1e63dbdff39207f8de7a7809b26000eef663cc3ff146e75e9e6717df1e2485b087fe92736af248f9352085b472d64e931008d60b7eb89c
|
@@ -76,19 +76,15 @@ module OpenHAB
|
|
76
76
|
private
|
77
77
|
|
78
78
|
#
|
79
|
-
# Convert timestamp to ZonedDateTime
|
79
|
+
# Convert timestamp to ZonedDateTime with duration negated to indicate a time in the past
|
80
80
|
#
|
81
|
-
# @param [Object] timestamp to convert
|
81
|
+
# @param [Object] timestamp timestamp to convert
|
82
82
|
#
|
83
83
|
# @return [ZonedDateTime]
|
84
84
|
#
|
85
85
|
def to_zdt(timestamp)
|
86
|
-
if timestamp.is_a? Java::
|
87
|
-
|
88
|
-
Java::JavaTime::ZonedDateTime.now.minus(timestamp)
|
89
|
-
else
|
90
|
-
timestamp
|
91
|
-
end
|
86
|
+
timestamp = timestamp.negated if timestamp.is_a? Java::JavaTime::Duration
|
87
|
+
OpenHAB::DSL.to_zdt(timestamp)
|
92
88
|
end
|
93
89
|
|
94
90
|
#
|
@@ -29,7 +29,6 @@ module OpenHAB
|
|
29
29
|
# @param [Duration] duration Duration until timer should fire
|
30
30
|
# @param [Block] block Block to execute when timer fires
|
31
31
|
#
|
32
|
-
# rubocop: disable Metrics/MethodLength
|
33
32
|
def initialize(duration:, thread_locals: {}, &block)
|
34
33
|
@duration = duration
|
35
34
|
@thread_locals = thread_locals
|
@@ -39,15 +38,12 @@ module OpenHAB
|
|
39
38
|
semaphore = Mutex.new
|
40
39
|
|
41
40
|
semaphore.synchronize do
|
42
|
-
@timer = ScriptExecution.createTimer(
|
43
|
-
ZonedDateTime.now.plus(to_duration(@duration)), timer_block(semaphore, &block)
|
44
|
-
)
|
41
|
+
@timer = ScriptExecution.createTimer(OpenHAB::DSL.to_zdt(@duration), timer_block(semaphore, &block))
|
45
42
|
@rule_timers = Thread.current[:rule_timers]
|
46
43
|
super(@timer)
|
47
44
|
Timers.timer_manager.add(self)
|
48
45
|
end
|
49
46
|
end
|
50
|
-
# rubocop: enable Metrics/MethodLength
|
51
47
|
|
52
48
|
#
|
53
49
|
# Reschedule timer
|
@@ -60,7 +56,7 @@ module OpenHAB
|
|
60
56
|
duration ||= @duration
|
61
57
|
|
62
58
|
Timers.timer_manager.add(self)
|
63
|
-
@timer.reschedule(
|
59
|
+
@timer.reschedule(OpenHAB::DSL.to_zdt(duration))
|
64
60
|
end
|
65
61
|
|
66
62
|
#
|
@@ -92,26 +88,44 @@ module OpenHAB
|
|
92
88
|
end
|
93
89
|
}
|
94
90
|
end
|
91
|
+
end
|
95
92
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
93
|
+
#
|
94
|
+
# Convert TemporalAmount (Duration), seconds (float, integer), and Ruby Time to ZonedDateTime
|
95
|
+
# Note: TemporalAmount is added to now
|
96
|
+
#
|
97
|
+
# @param [Object] timestamp to convert
|
98
|
+
#
|
99
|
+
# @return [ZonedDateTime]
|
100
|
+
#
|
101
|
+
def self.to_zdt(timestamp)
|
102
|
+
logger.trace("Converting #{timestamp} (#{timestamp.class}) to ZonedDateTime")
|
103
|
+
return unless timestamp
|
104
|
+
|
105
|
+
case timestamp
|
106
|
+
when Java::JavaTimeTemporal::TemporalAmount then ZonedDateTime.now.plus(timestamp)
|
107
|
+
when ZonedDateTime then timestamp
|
108
|
+
when Time then timestamp.to_java(ZonedDateTime)
|
109
|
+
else
|
110
|
+
to_zdt(seconds_to_duration(timestamp)) ||
|
111
|
+
raise(ArgumentError, 'Timestamp must be a ZonedDateTime, a Duration, a Numeric, or a Time object')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
# Convert numeric seconds to a Duration object
|
117
|
+
#
|
118
|
+
# @param [Float, Integer] secs The number of seconds in integer or float
|
119
|
+
#
|
120
|
+
# @return [Duration]
|
121
|
+
#
|
122
|
+
def self.seconds_to_duration(secs)
|
123
|
+
return unless secs
|
124
|
+
|
125
|
+
if secs.respond_to?(:to_f)
|
126
|
+
secs.to_f.seconds
|
127
|
+
elsif secs.respond_to?(:to_i)
|
128
|
+
secs.to_i.seconds
|
115
129
|
end
|
116
130
|
end
|
117
131
|
end
|
data/lib/openhab/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openhab-scripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian O'Connell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03
|
11
|
+
date: 2022-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|