openhab-jrubyscripting 5.0.0.rc2 → 5.0.0.rc3
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/core/items/generic_item.rb +13 -5
- data/lib/openhab/core/items/metadata/hash.rb +17 -34
- data/lib/openhab/core/items/persistence.rb +2 -0
- data/lib/openhab/core/items/semantics/enumerable.rb +6 -4
- data/lib/openhab/core/profile_factory.rb +2 -0
- data/lib/openhab/core/provider.rb +8 -1
- data/lib/openhab/core/rules/provider.rb +25 -0
- data/lib/openhab/core/rules/registry.rb +76 -0
- data/lib/openhab/core/rules/rule.rb +150 -0
- data/lib/openhab/core/rules.rb +25 -0
- data/lib/openhab/core/timer.rb +5 -7
- data/lib/openhab/core/types.rb +1 -1
- data/lib/openhab/core.rb +0 -16
- data/lib/openhab/core_ext/java/list.rb +436 -0
- data/lib/openhab/core_ext/java/map.rb +66 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +1 -2
- data/lib/openhab/core_ext/ruby/date.rb +2 -0
- data/lib/openhab/core_ext/ruby/date_time.rb +53 -0
- data/lib/openhab/core_ext/ruby/time.rb +88 -86
- data/lib/openhab/dsl/events/watch_event.rb +1 -1
- data/lib/openhab/dsl/items/builder.rb +8 -3
- data/lib/openhab/dsl/items/ensure.rb +6 -2
- data/lib/openhab/dsl/items/timed_command.rb +10 -11
- data/lib/openhab/dsl/rules/automation_rule.rb +36 -13
- data/lib/openhab/dsl/rules/builder.rb +99 -8
- data/lib/openhab/dsl/rules/name_inference.rb +0 -5
- data/lib/openhab/dsl/rules/terse.rb +1 -2
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +17 -53
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +0 -3
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +1 -1
- data/lib/openhab/dsl/rules.rb +0 -21
- data/lib/openhab/dsl/thread_local.rb +2 -2
- data/lib/openhab/dsl/timer_manager.rb +3 -1
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +12 -105
- data/lib/openhab/log.rb +2 -2
- data/lib/openhab/rspec/example_group.rb +42 -0
- data/lib/openhab/rspec/helpers.rb +31 -8
- data/lib/openhab/rspec/hooks.rb +3 -6
- data/lib/openhab/rspec/karaf.rb +45 -27
- data/lib/openhab/rspec/mocks/synchronous_executor.rb +11 -4
- data/lib/openhab/rspec/mocks/timer.rb +2 -1
- data/lib/openhab/rspec/suspend_rules.rb +4 -2
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce249607265a008aa969e2edbd56302edd70a67a01dfebaec9ad67b7e5f1ad27
|
4
|
+
data.tar.gz: ac0c8d25509a8be8374a3f15fecd2e575da8cb08b82268aef41414f64f7a3b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c082f0949b6bc55ebf48b1489eade3f6bbcf25181d6741e29697dbb5ef5221abf583c78fb8ad46596b5ea10957e9d4b5d2d5dfe35097eea004f005d06683d48
|
7
|
+
data.tar.gz: ee7e740d0dd1233462521313c31145971bed68e2830c765bad27b8762d064bdf154993a2d733fc7743240bd55aec9e0eecd8cb4f2d569dbd0c599e765140cd06
|
@@ -65,16 +65,23 @@ module OpenHAB
|
|
65
65
|
#
|
66
66
|
# Send a command to this item
|
67
67
|
#
|
68
|
+
# When this method is chained after the {OpenHAB::DSL::Items::Ensure::Ensurable#ensure ensure}
|
69
|
+
# method, or issued inside an {OpenHAB::DSL.ensure_states ensure_states} block,
|
70
|
+
# the command will only be sent if the item is not already in the same state.
|
71
|
+
#
|
68
72
|
# @param [Command] command command to send to the item
|
69
|
-
# @return [self]
|
73
|
+
# @return [self, nil] nil when `ensure` is in effect and the item was already in the same state,
|
74
|
+
# otherwise the item.
|
70
75
|
#
|
71
|
-
# @see DSL::Items::TimedCommand#command
|
76
|
+
# @see DSL::Items::TimedCommand#command Timed Command
|
77
|
+
# @see OpenHAB::DSL.ensure_states ensure_states
|
78
|
+
# @see DSL::Items::Ensure::Ensurable#ensure ensure
|
72
79
|
#
|
73
80
|
def command(command)
|
74
81
|
command = format_command(command)
|
75
82
|
logger.trace "Sending Command #{command} to #{name}"
|
76
83
|
$events.send_command(self, command)
|
77
|
-
self
|
84
|
+
Proxy.new(self)
|
78
85
|
end
|
79
86
|
|
80
87
|
# not an alias to allow easier stubbing and overriding
|
@@ -88,13 +95,14 @@ module OpenHAB
|
|
88
95
|
# Send an update to this item
|
89
96
|
#
|
90
97
|
# @param [State] state
|
91
|
-
# @return [self]
|
98
|
+
# @return [self, nil] nil when `ensure` is in effect and the item was already in the same state,
|
99
|
+
# otherwise the item.
|
92
100
|
#
|
93
101
|
def update(state)
|
94
102
|
state = format_update(state)
|
95
103
|
logger.trace "Sending Update #{state} to #{name}"
|
96
104
|
$events.post_update(self, state)
|
97
|
-
self
|
105
|
+
Proxy.new(self)
|
98
106
|
end
|
99
107
|
|
100
108
|
#
|
@@ -26,7 +26,7 @@ module OpenHAB
|
|
26
26
|
|
27
27
|
extend Forwardable
|
28
28
|
def_delegators :@metadata, :configuration, :hash, :to_s, :uid, :value
|
29
|
-
|
29
|
+
private :configuration
|
30
30
|
|
31
31
|
# @!method to_hash
|
32
32
|
# Implicit conversion to {::Hash}.
|
@@ -37,6 +37,9 @@ module OpenHAB
|
|
37
37
|
# still others (mutators) must be manually implemented below.
|
38
38
|
def_delegators :configuration,
|
39
39
|
:any?,
|
40
|
+
:compact,
|
41
|
+
:compare_by_identity?,
|
42
|
+
:deconstruct_keys,
|
40
43
|
:default,
|
41
44
|
:default_proc,
|
42
45
|
:each,
|
@@ -47,6 +50,8 @@ module OpenHAB
|
|
47
50
|
:filter,
|
48
51
|
:flatten,
|
49
52
|
:has_value?,
|
53
|
+
:invert,
|
54
|
+
:key,
|
50
55
|
:keys,
|
51
56
|
:length,
|
52
57
|
:rassoc,
|
@@ -57,8 +62,10 @@ module OpenHAB
|
|
57
62
|
:to_a,
|
58
63
|
:to_h,
|
59
64
|
:to_hash,
|
65
|
+
:transform_keys,
|
66
|
+
:transform_values,
|
67
|
+
:values,
|
60
68
|
:value?
|
61
|
-
def_delegators :to_h, :invert, :merge, :transform_keys, :transform_values
|
62
69
|
|
63
70
|
def_delegator :uid, :namespace
|
64
71
|
|
@@ -88,7 +95,7 @@ module OpenHAB
|
|
88
95
|
end
|
89
96
|
|
90
97
|
# @!visibility private
|
91
|
-
def initialize(metadata)
|
98
|
+
def initialize(metadata = nil)
|
92
99
|
@metadata = metadata
|
93
100
|
end
|
94
101
|
|
@@ -156,7 +163,7 @@ module OpenHAB
|
|
156
163
|
return false unless value == other.value
|
157
164
|
end
|
158
165
|
|
159
|
-
|
166
|
+
configuration < other
|
160
167
|
end
|
161
168
|
|
162
169
|
# @!visibility private
|
@@ -166,7 +173,7 @@ module OpenHAB
|
|
166
173
|
return false unless value == other.value
|
167
174
|
end
|
168
175
|
|
169
|
-
|
176
|
+
configuration <= other
|
170
177
|
end
|
171
178
|
|
172
179
|
# @!visibility private
|
@@ -176,7 +183,7 @@ module OpenHAB
|
|
176
183
|
|
177
184
|
return configuration == other.configuration
|
178
185
|
elsif value.empty? && other.respond_to?(:to_hash)
|
179
|
-
return configuration
|
186
|
+
return configuration == other.to_hash
|
180
187
|
end
|
181
188
|
false
|
182
189
|
end
|
@@ -188,7 +195,7 @@ module OpenHAB
|
|
188
195
|
return false unless value == other.value
|
189
196
|
end
|
190
197
|
|
191
|
-
|
198
|
+
configuration > other
|
192
199
|
end
|
193
200
|
|
194
201
|
# @!visibility private
|
@@ -198,7 +205,7 @@ module OpenHAB
|
|
198
205
|
return false unless value == other.value
|
199
206
|
end
|
200
207
|
|
201
|
-
|
208
|
+
configuration >= other
|
202
209
|
end
|
203
210
|
|
204
211
|
# @!visibility private
|
@@ -226,13 +233,9 @@ module OpenHAB
|
|
226
233
|
replace({})
|
227
234
|
end
|
228
235
|
|
229
|
-
# @!visibility private
|
230
|
-
alias_method :compact, :to_h
|
231
|
-
|
232
236
|
# @!visibility private
|
233
237
|
def compact!
|
234
|
-
|
235
|
-
self
|
238
|
+
replace(compact)
|
236
239
|
end
|
237
240
|
|
238
241
|
# @!visibility private
|
@@ -240,16 +243,6 @@ module OpenHAB
|
|
240
243
|
raise NotImplementedError
|
241
244
|
end
|
242
245
|
|
243
|
-
# @!visibility private
|
244
|
-
def compare_by_identity?
|
245
|
-
false
|
246
|
-
end
|
247
|
-
|
248
|
-
# @!visibility private
|
249
|
-
def deconstruct_keys
|
250
|
-
self
|
251
|
-
end
|
252
|
-
|
253
246
|
# @!visibility private
|
254
247
|
def default=(*)
|
255
248
|
raise NotImplementedError
|
@@ -304,11 +297,6 @@ module OpenHAB
|
|
304
297
|
self
|
305
298
|
end
|
306
299
|
|
307
|
-
# @!visibility private
|
308
|
-
def key(value)
|
309
|
-
rassoc(value)&.first
|
310
|
-
end
|
311
|
-
|
312
300
|
# @!visibility private
|
313
301
|
def key?(key)
|
314
302
|
configuration.key?(key.to_s)
|
@@ -360,7 +348,7 @@ module OpenHAB
|
|
360
348
|
|
361
349
|
# @!visibility private
|
362
350
|
def slice(*keys)
|
363
|
-
|
351
|
+
configuration.slice(*keys.map(&:to_s))
|
364
352
|
end
|
365
353
|
|
366
354
|
# @!visibility private
|
@@ -380,11 +368,6 @@ module OpenHAB
|
|
380
368
|
replace(transform_values(&block))
|
381
369
|
end
|
382
370
|
|
383
|
-
# @!visibility private
|
384
|
-
def values
|
385
|
-
configuration.values.to_a
|
386
|
-
end
|
387
|
-
|
388
371
|
# @!visibility private
|
389
372
|
def values_at(*keys)
|
390
373
|
configuration.values_at(*keys.map(&:to_s))
|
@@ -72,15 +72,17 @@ module Enumerable
|
|
72
72
|
# @!group Items State and Command Methods
|
73
73
|
|
74
74
|
# Send a command to every item in the collection
|
75
|
-
# @return [self]
|
75
|
+
# @return [self, nil] nil when `ensure` is in effect and all the items were already in the same state,
|
76
|
+
# otherwise self
|
76
77
|
def command(command)
|
77
|
-
|
78
|
+
self if count { |i| i.command(command) }.positive?
|
78
79
|
end
|
79
80
|
|
80
81
|
# Update the state of every item in the collection
|
81
|
-
# @return [self]
|
82
|
+
# @return [self, nil] nil when `ensure` is in effect and all the items were already in the same state,
|
83
|
+
# otherwise self
|
82
84
|
def update(state)
|
83
|
-
|
85
|
+
self if count { |i| i.update(state) }.positive?
|
84
86
|
end
|
85
87
|
|
86
88
|
# @!method refresh
|
@@ -13,6 +13,7 @@ module OpenHAB
|
|
13
13
|
TYPE_TO_PROVIDER_TYPE = {
|
14
14
|
org.openhab.core.items.Item.java_class => :items,
|
15
15
|
org.openhab.core.items.Metadata.java_class => :metadata,
|
16
|
+
org.openhab.core.automation.Rule.java_class => :rules,
|
16
17
|
org.openhab.core.thing.Thing.java_class => :things,
|
17
18
|
org.openhab.core.thing.link.ItemChannelLink.java_class => :links
|
18
19
|
}.freeze
|
@@ -37,6 +38,7 @@ module OpenHAB
|
|
37
38
|
# @abstract
|
38
39
|
class Provider < org.openhab.core.common.registry.AbstractProvider
|
39
40
|
include org.openhab.core.common.registry.ManagedProvider
|
41
|
+
include Enumerable
|
40
42
|
include Singleton
|
41
43
|
public_class_method :new
|
42
44
|
|
@@ -140,6 +142,11 @@ module OpenHAB
|
|
140
142
|
end
|
141
143
|
end
|
142
144
|
|
145
|
+
# @!visibility private
|
146
|
+
def each(&block)
|
147
|
+
@elements.each_value(&block)
|
148
|
+
end
|
149
|
+
|
143
150
|
# @return [String]
|
144
151
|
def inspect
|
145
152
|
"#<#{self.class.name}:#{object_id}>"
|
@@ -192,7 +199,7 @@ module OpenHAB
|
|
192
199
|
def update(element)
|
193
200
|
old_element = @elements[element.uid]
|
194
201
|
if old_element
|
195
|
-
@elements[element.uid]
|
202
|
+
@elements[element.uid] = element
|
196
203
|
notify_listeners_about_updated_element(old_element, element)
|
197
204
|
end
|
198
205
|
old_element
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Rules
|
6
|
+
#
|
7
|
+
# Provides rules created in Ruby to openHAB
|
8
|
+
#
|
9
|
+
class Provider < Core::Provider
|
10
|
+
include org.openhab.core.automation.RuleProvider
|
11
|
+
|
12
|
+
class << self
|
13
|
+
#
|
14
|
+
# The Rule registry
|
15
|
+
#
|
16
|
+
# @return [org.openhab.core.automation.RuleRegistry]
|
17
|
+
#
|
18
|
+
def registry
|
19
|
+
$rules
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module Core
|
7
|
+
module Rules
|
8
|
+
#
|
9
|
+
# Provides access to all OpenHAB {Rule rules}, and acts like an array.
|
10
|
+
#
|
11
|
+
class Registry
|
12
|
+
include LazyArray
|
13
|
+
include Singleton
|
14
|
+
|
15
|
+
#
|
16
|
+
# Gets a specific Rule
|
17
|
+
#
|
18
|
+
# @param [String] uid Rule UID
|
19
|
+
# @return [Rule, nil]
|
20
|
+
#
|
21
|
+
def [](uid)
|
22
|
+
$rules.get(uid)
|
23
|
+
end
|
24
|
+
alias_method :include?, :[]
|
25
|
+
alias_method :key?, :[]
|
26
|
+
# @deprecated
|
27
|
+
alias_method :has_key?, :[]
|
28
|
+
|
29
|
+
#
|
30
|
+
# Explicit conversion to array
|
31
|
+
#
|
32
|
+
# @return [Array<Rule>]
|
33
|
+
#
|
34
|
+
def to_a
|
35
|
+
$rules.all.to_a
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Enter the Rule Builder DSL.
|
40
|
+
# @param (see Core::Provider.current)
|
41
|
+
# @yield Block executed in the context of a {DSL::Rules::Builder}.
|
42
|
+
# @return [Object] The result of the block.
|
43
|
+
#
|
44
|
+
def build(preferred_provider = nil, &block)
|
45
|
+
DSL::Rules::Builder.new(preferred_provider).instance_eval(&block)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Remove a Rule.
|
50
|
+
#
|
51
|
+
# The rule must be a managed thing (typically created by Ruby or in the UI).
|
52
|
+
#
|
53
|
+
# @param [String, Rule] rule_uid
|
54
|
+
# @return [Rule, nil] The removed rule, if found.
|
55
|
+
#
|
56
|
+
# @example
|
57
|
+
# my_rule = rule do
|
58
|
+
# every :day
|
59
|
+
# run { nil }
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# rules.remove(my_rule)
|
63
|
+
#
|
64
|
+
def remove(rule_uid)
|
65
|
+
rule_uid = rule_uid.uid if rule_uid.is_a?(Rule)
|
66
|
+
provider = Provider.registry.provider_for(rule_uid)
|
67
|
+
unless provider.is_a?(org.openhab.core.common.registry.ManagedProvider)
|
68
|
+
raise "Cannot remove rule #{rule_uid} from non-managed provider #{provider.inspect}"
|
69
|
+
end
|
70
|
+
|
71
|
+
provider.remove(rule_uid)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Rules
|
6
|
+
# @interface
|
7
|
+
java_import org.openhab.core.automation.Rule
|
8
|
+
|
9
|
+
#
|
10
|
+
# A {Rule} is a chunk of code that can execute when certain conditions are
|
11
|
+
# met, enabling the core dynamic functionality of openHAB.
|
12
|
+
#
|
13
|
+
module Rule
|
14
|
+
#
|
15
|
+
# @!method visible?
|
16
|
+
# Check if visibility == `VISIBLE`
|
17
|
+
# @return [true,false]
|
18
|
+
#
|
19
|
+
|
20
|
+
#
|
21
|
+
# @!method hidden?
|
22
|
+
# Check if visibility == `HIDDEN`
|
23
|
+
# @return [true,false]
|
24
|
+
#
|
25
|
+
|
26
|
+
#
|
27
|
+
# @!method expert?
|
28
|
+
# Check if visibility == `EXPERT`
|
29
|
+
# @return [true,false]
|
30
|
+
#
|
31
|
+
|
32
|
+
#
|
33
|
+
# @!method initializing?
|
34
|
+
# Check if rule status == `INITIALIZING`
|
35
|
+
# @return [true,false]
|
36
|
+
#
|
37
|
+
#
|
38
|
+
# @!method idle?
|
39
|
+
# Check if rule status == `IDLE`
|
40
|
+
# @return [true,false]
|
41
|
+
#
|
42
|
+
#
|
43
|
+
# @!method running?
|
44
|
+
# Check if rule status == `RUNNING`
|
45
|
+
# @return [true,false]
|
46
|
+
#
|
47
|
+
|
48
|
+
Visibility.constants.each do |visibility|
|
49
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
50
|
+
def #{visibility.to_s.downcase}? # def visibile?
|
51
|
+
visibility == Visibility::#{visibility} # visibility == Visibility::VISIBLE
|
52
|
+
end # end
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
|
56
|
+
RuleStatus.constants.each do |status|
|
57
|
+
next if status == :UNINITIALIZED
|
58
|
+
|
59
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
60
|
+
def #{status.to_s.downcase}? # def initializing?
|
61
|
+
status == RuleStatus::#{status} # status == RuleStatus::INITIALIZING
|
62
|
+
end # end
|
63
|
+
RUBY
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Check if rule status == `UNINITIALIZED`
|
68
|
+
#
|
69
|
+
# @return [true,false]
|
70
|
+
#
|
71
|
+
def uninitialized?
|
72
|
+
s = status
|
73
|
+
s.nil? || s == RuleStatus::UNINITIALIZED
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Enable the Rule
|
78
|
+
#
|
79
|
+
# @param [true, false] enabled
|
80
|
+
# @return [void]
|
81
|
+
#
|
82
|
+
def enable(enabled: true)
|
83
|
+
Rules.manager.set_enabled(uid, enabled)
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Disable the Rule
|
88
|
+
#
|
89
|
+
# @return [void]
|
90
|
+
#
|
91
|
+
def disable
|
92
|
+
enable(enabled: false)
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# Check if the rule's status detail == `DISABLED`
|
97
|
+
#
|
98
|
+
# @return [true, false]
|
99
|
+
#
|
100
|
+
def disabled?
|
101
|
+
info = status_info
|
102
|
+
info.nil? || info.status_detail == RuleStatusDetail::DISABLED
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# @!attribute [r] status
|
107
|
+
# @return [RuleStatus nil]
|
108
|
+
#
|
109
|
+
def status
|
110
|
+
Rules.manager.get_status(uid)
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# @!attribute [r] status_info
|
115
|
+
# @return [RuleStatusInfo, nil]
|
116
|
+
#
|
117
|
+
def status_info
|
118
|
+
Rules.manager.get_status_info(uid)
|
119
|
+
end
|
120
|
+
|
121
|
+
# @return [String]
|
122
|
+
def inspect
|
123
|
+
r = "#<OpenHAB::Core::Rules::Rule #{uid}"
|
124
|
+
r += " #{name.inspect}" if name
|
125
|
+
r += " #{visibility}" unless visible?
|
126
|
+
r += " #{status || "<detached>"}"
|
127
|
+
r += " (#{status_info.status_detail})" if status_info && status_info.status_detail != RuleStatusDetail::NONE
|
128
|
+
r += " tags=#{tags.to_a.inspect}" unless tags.empty?
|
129
|
+
r += " configuration=#{configuration.properties.to_h}" if configuration && !configuration.properties.empty?
|
130
|
+
"#{r}>"
|
131
|
+
end
|
132
|
+
|
133
|
+
# @return [String]
|
134
|
+
def to_s
|
135
|
+
uid
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# Manually trigger the rule
|
140
|
+
#
|
141
|
+
# @param [Object, nil] event The event to pass to the rule's execution blocks.
|
142
|
+
# @return [void]
|
143
|
+
#
|
144
|
+
def trigger(event = nil)
|
145
|
+
Rules.manager.run_now(uid, false, { "event" => event })
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
#
|
6
|
+
# Contains the core {Rule} as well as related infrastructure.
|
7
|
+
#
|
8
|
+
module Rules
|
9
|
+
java_import org.openhab.core.automation.RuleStatus,
|
10
|
+
org.openhab.core.automation.RuleStatusInfo,
|
11
|
+
org.openhab.core.automation.RuleStatusDetail,
|
12
|
+
org.openhab.core.automation.Visibility
|
13
|
+
|
14
|
+
class << self
|
15
|
+
#
|
16
|
+
# @!attribute [r] rule_manager
|
17
|
+
# @return [org.openhab.core.automation.RuleManager] The OpenHAB rule manager/engine
|
18
|
+
#
|
19
|
+
def manager
|
20
|
+
@manager ||= OSGi.service("org.openhab.core.automation.RuleManager")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/openhab/core/timer.rb
CHANGED
@@ -35,7 +35,6 @@ module OpenHAB
|
|
35
35
|
# @return [Object, nil]
|
36
36
|
attr_accessor :id
|
37
37
|
|
38
|
-
# @!visibility private
|
39
38
|
# @!visibility private
|
40
39
|
attr_reader :block
|
41
40
|
|
@@ -84,6 +83,7 @@ module OpenHAB
|
|
84
83
|
# @return [self]
|
85
84
|
#
|
86
85
|
def reschedule(time = nil)
|
86
|
+
Thread.current[:openhab_rescheduled_timer] = true if Thread.current[:openhab_rescheduled_timer] == self
|
87
87
|
DSL.timers.add(self)
|
88
88
|
@timer.reschedule(new_execution_time(time || @time))
|
89
89
|
self
|
@@ -119,12 +119,10 @@ module OpenHAB
|
|
119
119
|
# @return [void]
|
120
120
|
#
|
121
121
|
def execute
|
122
|
-
|
123
|
-
DSL::ThreadLocal.thread_local(**@thread_locals)
|
124
|
-
|
125
|
-
|
126
|
-
# don't remove ourselves if we were rescheduled in the block
|
127
|
-
DSL.timers.delete(self) if execution_time == last_execution_time
|
122
|
+
Thread.current[:openhab_rescheduled_timer] = self
|
123
|
+
DSL::ThreadLocal.thread_local(**@thread_locals) { @block.call(self) }
|
124
|
+
DSL.timers.delete(self) unless Thread.current[:openhab_rescheduled_timer] == true
|
125
|
+
Thread.current[:openhab_rescheduled_timer] = nil
|
128
126
|
end
|
129
127
|
|
130
128
|
#
|
data/lib/openhab/core/types.rb
CHANGED
@@ -13,7 +13,7 @@ module OpenHAB
|
|
13
13
|
# Types are the specific data types that commands and states are. They can be
|
14
14
|
# sent to items, be the current state of an item, or be the `command`, `state`,
|
15
15
|
# and `was` field of various
|
16
|
-
# {group::OpenHAB::DSL::Rules::
|
16
|
+
# {group::OpenHAB::DSL::Rules::BuilderDSL::Triggers triggers}.
|
17
17
|
# Some types have additional useful methods.
|
18
18
|
#
|
19
19
|
module Types
|
data/lib/openhab/core.rb
CHANGED
@@ -53,22 +53,6 @@ module OpenHAB
|
|
53
53
|
def automation_manager
|
54
54
|
$scriptExtension.get("automationManager")
|
55
55
|
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# @!attribute [r] rule_registry
|
59
|
-
# @return [org.openhab.core.automation.RuleRegistry] The OpenHAB rule registry
|
60
|
-
#
|
61
|
-
def rule_registry
|
62
|
-
$scriptExtension.get("ruleRegistry")
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# @!attribute [r] rule_manager
|
67
|
-
# @return [org.openhab.core.automation.RuleManager] The OpenHAB rule manager/engine
|
68
|
-
#
|
69
|
-
def rule_manager
|
70
|
-
@rule_manager ||= OSGi.service("org.openhab.core.automation.RuleManager")
|
71
|
-
end
|
72
56
|
end
|
73
57
|
end
|
74
58
|
end
|