openhab-scripting 5.35.1 → 5.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/console/irb.rb +105 -0
- data/lib/openhab/console/jline.rb +104 -0
- data/lib/openhab/console/registry.rb +12 -0
- data/lib/openhab/console/stdio.rb +178 -0
- data/lib/openhab/console.rb +5 -0
- data/lib/openhab/core/emulate_hash.rb +11 -11
- data/lib/openhab/core/entity_lookup.rb +2 -4
- data/lib/openhab/core/events/item_state_updated_event.rb +0 -3
- data/lib/openhab/core/events/item_time_series_updated_event.rb +0 -3
- data/lib/openhab/core/events/startlevel_event.rb +0 -3
- data/lib/openhab/core/events/timer_event.rb +0 -3
- data/lib/openhab/core/items/generic_item.rb +14 -154
- data/lib/openhab/core/items/group_item.rb +2 -2
- data/lib/openhab/core/items/image_item.rb +5 -21
- data/lib/openhab/core/items/item.rb +161 -7
- data/lib/openhab/core/items/persistence.rb +8 -10
- data/lib/openhab/core/items/provider.rb +1 -1
- data/lib/openhab/core/items/proxy.rb +33 -94
- data/lib/openhab/core/items/registry.rb +1 -1
- data/lib/openhab/core/items/semantics/enumerable.rb +1 -1
- data/lib/openhab/core/items/semantics/provider.rb +1 -5
- data/lib/openhab/core/items/semantics/semantic_tag.rb +0 -3
- data/lib/openhab/core/items/semantics.rb +105 -141
- data/lib/openhab/core/items/switch_item.rb +1 -1
- data/lib/openhab/core/items.rb +22 -22
- data/lib/openhab/core/lazy_array.rb +4 -4
- data/lib/openhab/core/profile_factory.rb +16 -25
- data/lib/openhab/core/provider.rb +3 -4
- data/lib/openhab/core/proxy.rb +160 -4
- data/lib/openhab/core/rules/registry.rb +2 -2
- data/lib/openhab/core/rules/rule.rb +4 -8
- data/lib/openhab/core/script_handling.rb +2 -2
- data/lib/openhab/core/sitemaps/provider.rb +1 -1
- data/lib/openhab/core/things/channel.rb +0 -28
- data/lib/openhab/core/things/profile_callback.rb +3 -3
- data/lib/openhab/core/things/proxy.rb +8 -51
- data/lib/openhab/core/things/registry.rb +1 -1
- data/lib/openhab/core/things/thing.rb +3 -5
- data/lib/openhab/core/types/command_description.rb +31 -0
- data/lib/openhab/core/types/date_time_type.rb +5 -10
- data/lib/openhab/core/types/decimal_type.rb +1 -1
- data/lib/openhab/core/types/hsb_type.rb +3 -5
- data/lib/openhab/core/types/point_type.rb +1 -1
- data/lib/openhab/core/types/quantity_type.rb +22 -2
- data/lib/openhab/core/types/raw_type.rb +10 -4
- data/lib/openhab/core/types/state_description.rb +54 -0
- data/lib/openhab/core/types/time_series.rb +0 -3
- data/lib/openhab/core/types.rb +2 -2
- data/lib/openhab/core/value_cache.rb +3 -3
- data/lib/openhab/core.rb +3 -5
- data/lib/openhab/core_ext/java/duration.rb +27 -8
- data/lib/openhab/core_ext/java/list.rb +1 -1
- data/lib/openhab/core_ext/java/local_date.rb +6 -2
- data/lib/openhab/core_ext/java/local_time.rb +4 -2
- data/lib/openhab/core_ext/java/map.rb +2 -2
- data/lib/openhab/core_ext/java/period.rb +9 -6
- data/lib/openhab/core_ext/java/temporal_amount.rb +5 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +12 -6
- data/lib/openhab/core_ext/ruby/date.rb +8 -7
- data/lib/openhab/core_ext/ruby/date_time.rb +2 -2
- data/lib/openhab/core_ext/ruby/time.rb +2 -2
- data/lib/openhab/core_ext.rb +1 -1
- data/lib/openhab/dsl/config_description/builder.rb +1 -1
- data/lib/openhab/dsl/items/builder.rb +5 -13
- data/lib/openhab/dsl/items/ensure.rb +3 -5
- data/lib/openhab/dsl/items/timed_command.rb +4 -4
- data/lib/openhab/dsl/rules/automation_rule.rb +3 -3
- data/lib/openhab/dsl/rules/builder.rb +40 -52
- data/lib/openhab/dsl/rules/rule_triggers.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/changed.rb +16 -15
- data/lib/openhab/dsl/rules/triggers/channel.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/command.rb +2 -2
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +4 -4
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +4 -14
- data/lib/openhab/dsl/rules/triggers/updated.rb +6 -6
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +69 -124
- data/lib/openhab/dsl/sitemaps/builder.rb +7 -17
- data/lib/openhab/dsl/things/builder.rb +8 -8
- data/lib/openhab/dsl/timer_manager.rb +2 -2
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +14 -15
- data/lib/openhab/log.rb +3 -3
- data/lib/openhab/osgi.rb +1 -1
- data/lib/openhab/rspec/helpers.rb +3 -3
- data/lib/openhab/rspec/hooks.rb +2 -8
- data/lib/openhab/rspec/jruby.rb +1 -1
- data/lib/openhab/rspec/karaf.rb +5 -27
- data/lib/openhab/rspec/mocks/persistence_service.rb +5 -5
- data/lib/openhab/yard/html_helper.rb +1 -1
- data/lib/openhab/yard.rb +1 -1
- metadata +18 -13
- data/lib/openhab/core/items/semantics/tag_class_methods.rb +0 -73
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +0 -118
@@ -15,12 +15,7 @@ module OpenHAB
|
|
15
15
|
include Singleton
|
16
16
|
|
17
17
|
class Profile
|
18
|
-
|
19
|
-
if OpenHAB::Core.version >= OpenHAB::Core::V4_1
|
20
|
-
include org.openhab.core.thing.profiles.TimeSeriesProfile
|
21
|
-
else
|
22
|
-
include org.openhab.core.thing.profiles.StateProfile
|
23
|
-
end
|
18
|
+
include org.openhab.core.thing.profiles.TimeSeriesProfile
|
24
19
|
include org.openhab.core.thing.profiles.TriggerProfile
|
25
20
|
|
26
21
|
def initialize(callback, context, uid, thread_locals, block)
|
@@ -43,7 +38,7 @@ module OpenHAB
|
|
43
38
|
|
44
39
|
# @!visibility private
|
45
40
|
def onCommandFromItem(command)
|
46
|
-
return unless process_event(:command_from_item, command:
|
41
|
+
return unless process_event(:command_from_item, command:) == true
|
47
42
|
|
48
43
|
logger.trace("Forwarding original command")
|
49
44
|
@callback.handle_command(command)
|
@@ -51,7 +46,7 @@ module OpenHAB
|
|
51
46
|
|
52
47
|
# @!visibility private
|
53
48
|
def onStateUpdateFromHandler(state)
|
54
|
-
return unless process_event(:state_from_handler, state:
|
49
|
+
return unless process_event(:state_from_handler, state:) == true
|
55
50
|
|
56
51
|
logger.trace("Forwarding original update")
|
57
52
|
@callback.send_update(state)
|
@@ -59,7 +54,7 @@ module OpenHAB
|
|
59
54
|
|
60
55
|
# @!visibility private
|
61
56
|
def onCommandFromHandler(command)
|
62
|
-
return unless process_event(:command_from_handler, command:
|
57
|
+
return unless process_event(:command_from_handler, command:) == true
|
63
58
|
|
64
59
|
logger.trace("Forwarding original command")
|
65
60
|
callback.send_command(command)
|
@@ -67,7 +62,7 @@ module OpenHAB
|
|
67
62
|
|
68
63
|
# @!visibility private
|
69
64
|
def onStateUpdateFromItem(state)
|
70
|
-
process_event(:state_from_item, state:
|
65
|
+
process_event(:state_from_item, state:)
|
71
66
|
end
|
72
67
|
|
73
68
|
# @!visibility private
|
@@ -75,12 +70,9 @@ module OpenHAB
|
|
75
70
|
process_event(:trigger_from_handler, trigger: event)
|
76
71
|
end
|
77
72
|
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
def onTimeSeriesFromHandler(time_series)
|
82
|
-
process_event(:time_series_from_handler, time_series: time_series)
|
83
|
-
end
|
73
|
+
# @!visibility private
|
74
|
+
def onTimeSeriesFromHandler(time_series)
|
75
|
+
process_event(:time_series_from_handler, time_series:)
|
84
76
|
end
|
85
77
|
|
86
78
|
private
|
@@ -99,8 +91,7 @@ module OpenHAB
|
|
99
91
|
params[:state] ||= nil
|
100
92
|
params[:command] ||= nil
|
101
93
|
params[:trigger] ||= nil
|
102
|
-
|
103
|
-
params[:time_series] ||= nil if OpenHAB::Core.version >= OpenHAB::Core::V4_1
|
94
|
+
params[:time_series] ||= nil
|
104
95
|
|
105
96
|
kwargs = {}
|
106
97
|
@block.parameters.each do |(param_type, name)|
|
@@ -154,10 +145,10 @@ module OpenHAB
|
|
154
145
|
|
155
146
|
@profiles[uid] = {
|
156
147
|
thread_locals: DSL::ThreadLocal.persist,
|
157
|
-
label
|
158
|
-
type
|
159
|
-
config_description
|
160
|
-
block:
|
148
|
+
label:,
|
149
|
+
type:,
|
150
|
+
config_description:,
|
151
|
+
block:
|
161
152
|
}
|
162
153
|
@uri_to_uid[uri] = uid
|
163
154
|
end
|
@@ -175,7 +166,7 @@ module OpenHAB
|
|
175
166
|
|
176
167
|
# @!visibility private
|
177
168
|
def getProfileTypes(_locale)
|
178
|
-
@profiles.
|
169
|
+
@profiles.filter_map do |uid, profile|
|
179
170
|
next if profile[:label].nil?
|
180
171
|
|
181
172
|
if profile[:type] == :trigger
|
@@ -183,12 +174,12 @@ module OpenHAB
|
|
183
174
|
else
|
184
175
|
org.openhab.core.thing.profiles.ProfileTypeBuilder.new_state(uid, "RUBY #{profile[:label]}").build
|
185
176
|
end
|
186
|
-
end
|
177
|
+
end
|
187
178
|
end
|
188
179
|
|
189
180
|
# @!visibility private
|
190
181
|
def getConfigDescriptions(_locale)
|
191
|
-
@profiles.values.
|
182
|
+
@profiles.values.filter_map { |profile| profile[:config_description] if profile[:label] }
|
192
183
|
end
|
193
184
|
|
194
185
|
# @!visibility private
|
@@ -144,8 +144,8 @@ module OpenHAB
|
|
144
144
|
end
|
145
145
|
|
146
146
|
# @!visibility private
|
147
|
-
def each(&
|
148
|
-
@elements.each_value(&
|
147
|
+
def each(&)
|
148
|
+
@elements.each_value(&)
|
149
149
|
end
|
150
150
|
|
151
151
|
# @return [String]
|
@@ -225,8 +225,7 @@ module OpenHAB
|
|
225
225
|
# @!visibility private
|
226
226
|
def unregister
|
227
227
|
clear
|
228
|
-
|
229
|
-
self.class.registry&.remove_provider(self)
|
228
|
+
self.class.registry.remove_provider(self)
|
230
229
|
end
|
231
230
|
|
232
231
|
private
|
data/lib/openhab/core/proxy.rb
CHANGED
@@ -24,6 +24,14 @@ module OpenHAB
|
|
24
24
|
# @!visibility private
|
25
25
|
#
|
26
26
|
module Proxy
|
27
|
+
# Error raised when an item is attempted to be accessed, but no longer
|
28
|
+
# exists
|
29
|
+
class StaleProxyError < RuntimeError
|
30
|
+
def initialize(type, uid)
|
31
|
+
super("#{type} #{uid} does not currently exist")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
27
35
|
#
|
28
36
|
# Registers and listens to openHAB bus events for objects getting
|
29
37
|
# added/updated/removed, and updates references from proxy objects
|
@@ -39,12 +47,15 @@ module OpenHAB
|
|
39
47
|
def initialize
|
40
48
|
@proxies = java.util.concurrent.ConcurrentHashMap.new
|
41
49
|
@parent_module = Object.const_get(self.class.name.split("::")[0..-3].join("::"), false)
|
42
|
-
|
50
|
+
object_type = @parent_module.name.split("::").last[0...-1]
|
51
|
+
@object_type = object_type.downcase.to_sym
|
52
|
+
@type = @parent_module.const_get(object_type, false)
|
43
53
|
|
44
54
|
@event_types = @parent_module::Proxy::EVENTS
|
45
55
|
@uid_method = @parent_module::Proxy::UID_METHOD
|
56
|
+
@uid_type = @parent_module::Proxy::UID_TYPE
|
46
57
|
@registry = @parent_module::Provider.registry
|
47
|
-
@registration = OSGi.register_service(self
|
58
|
+
@registration = OSGi.register_service(self)
|
48
59
|
ScriptHandling.script_unloaded { @registration.unregister }
|
49
60
|
end
|
50
61
|
|
@@ -67,9 +78,10 @@ module OpenHAB
|
|
67
78
|
#
|
68
79
|
def receive(event)
|
69
80
|
uid = event.__send__(@object_type).__send__(@uid_method)
|
70
|
-
|
81
|
+
uid = @uid_type.new(uid) unless @uid_type == String
|
71
82
|
|
72
83
|
@proxies.compute_if_present(uid) do |_, proxy_ref|
|
84
|
+
object = @registry.get(uid) unless event.class.simple_name == @event_types.last
|
73
85
|
proxy = resolve_ref(proxy_ref)
|
74
86
|
next nil unless proxy
|
75
87
|
|
@@ -84,7 +96,12 @@ module OpenHAB
|
|
84
96
|
def fetch(object)
|
85
97
|
result = nil
|
86
98
|
|
87
|
-
|
99
|
+
uid = if object.is_a?(@type)
|
100
|
+
object.__send__(@uid_method)
|
101
|
+
else
|
102
|
+
object
|
103
|
+
end
|
104
|
+
@proxies.compute(uid) do |_k, proxy_ref|
|
88
105
|
result = resolve_ref(proxy_ref)
|
89
106
|
proxy_ref = nil unless result
|
90
107
|
result ||= yield
|
@@ -119,12 +136,151 @@ module OpenHAB
|
|
119
136
|
klass.singleton_class.prepend(ClassMethods)
|
120
137
|
# define a sub-class of EventSubscriber as a child class of the including class
|
121
138
|
klass.const_set(:EventSubscriber, Class.new(EventSubscriber))
|
139
|
+
parent_module = Object.const_get(klass.name.split("::")[0..-2].join("::"), false)
|
140
|
+
object_type = parent_module.name.split("::").last[0...-1].to_sym
|
141
|
+
klass.const_set(:Type, parent_module.const_get(object_type, false))
|
122
142
|
end
|
123
143
|
|
124
144
|
# @!visibility private
|
125
145
|
def to_java
|
126
146
|
__getobj__
|
127
147
|
end
|
148
|
+
|
149
|
+
KERNEL_CLASS = ::Kernel.instance_method(:class)
|
150
|
+
KERNEL_IVAR_SET = ::Kernel.instance_method(:instance_variable_set)
|
151
|
+
private_constant :KERNEL_CLASS, :KERNEL_IVAR_SET
|
152
|
+
|
153
|
+
# @!visibility private
|
154
|
+
|
155
|
+
def initialize(target)
|
156
|
+
@klass = KERNEL_CLASS.bind_call(self)
|
157
|
+
|
158
|
+
if target.is_a?(@klass::Type)
|
159
|
+
super
|
160
|
+
KERNEL_IVAR_SET.bind_call(self, :"@#{@klass::UID_METHOD}", target&.__send__(@klass::UID_METHOD))
|
161
|
+
else
|
162
|
+
# dummy items; we were just passed the item name
|
163
|
+
super(nil)
|
164
|
+
KERNEL_IVAR_SET.bind_call(self, :"@#{@klass::UID_METHOD}", target)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# @!visibility private
|
169
|
+
def __setobj__(target)
|
170
|
+
@target = target
|
171
|
+
end
|
172
|
+
|
173
|
+
# @!visibility private
|
174
|
+
def __getobj__
|
175
|
+
@target
|
176
|
+
end
|
177
|
+
|
178
|
+
# overwrite these methods to handle "dummy" items:
|
179
|
+
# if it's a dummy item, and the method exists on Item,
|
180
|
+
# raise a StaleProxyError when you try to call it.
|
181
|
+
# if it doesn't exist on item, just let it raise NoMethodError
|
182
|
+
# as usual
|
183
|
+
# @!visibility private
|
184
|
+
def method_missing(method, ...)
|
185
|
+
target = __getobj__
|
186
|
+
if target.nil? && @klass::Type.method_defined?(method)
|
187
|
+
__raise__ StaleProxyError.new(@klass.name.split("::")[-2][0...-1], __send__(@klass::UID_METHOD))
|
188
|
+
end
|
189
|
+
|
190
|
+
if target_respond_to?(target, method, false)
|
191
|
+
target.__send__(method, ...)
|
192
|
+
elsif ::Kernel.method_defined?(method) || ::Kernel.private_method_defined?(method)
|
193
|
+
::Kernel.instance_method(method).bind_call(self, ...)
|
194
|
+
else
|
195
|
+
super
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# @!visibility private
|
200
|
+
def respond_to_missing?(method, include_private)
|
201
|
+
target = __getobj__
|
202
|
+
return true if target.nil? && @klass::Type.method_defined?(method)
|
203
|
+
|
204
|
+
r = target_respond_to?(target, method, include_private)
|
205
|
+
if r && include_private && !target_respond_to?(target, method, false)
|
206
|
+
warn "delegator does not forward private method ##{method}", uplevel: 3
|
207
|
+
return false
|
208
|
+
end
|
209
|
+
r
|
210
|
+
end
|
211
|
+
|
212
|
+
# @!visibility private
|
213
|
+
def respond_to?(method, include_private = false) # rubocop:disable Style/OptionalBooleanParameter
|
214
|
+
target = __getobj__
|
215
|
+
return true if target.nil? && @klass::Type.method_defined?(method)
|
216
|
+
|
217
|
+
target_respond_to?(target, method, include_private) || super
|
218
|
+
end
|
219
|
+
|
220
|
+
#
|
221
|
+
# Need to check if `self` _or_ the delegate is an instance of the
|
222
|
+
# given class
|
223
|
+
#
|
224
|
+
# So that {#==} can work
|
225
|
+
#
|
226
|
+
# @return [true, false]
|
227
|
+
#
|
228
|
+
# @!visibility private
|
229
|
+
def instance_of?(klass)
|
230
|
+
__getobj__.instance_of?(klass) || super
|
231
|
+
end
|
232
|
+
|
233
|
+
#
|
234
|
+
# Check if delegates are equal for comparison
|
235
|
+
#
|
236
|
+
# Otherwise items can't be used in Java maps
|
237
|
+
#
|
238
|
+
# @return [true, false]
|
239
|
+
#
|
240
|
+
# @!visibility private
|
241
|
+
def ==(other)
|
242
|
+
return __getobj__ == other.__getobj__ if other.instance_of?(@klass)
|
243
|
+
|
244
|
+
super
|
245
|
+
end
|
246
|
+
|
247
|
+
#
|
248
|
+
# Non equality comparison
|
249
|
+
#
|
250
|
+
# @return [true, false]
|
251
|
+
#
|
252
|
+
# @!visibility private
|
253
|
+
def !=(other)
|
254
|
+
!(self == other) # rubocop:disable Style/InverseMethods
|
255
|
+
end
|
256
|
+
|
257
|
+
# @return [String]
|
258
|
+
def to_s
|
259
|
+
target = __getobj__
|
260
|
+
return __send__(@klass::UID_METHOD) if target.nil?
|
261
|
+
|
262
|
+
target.to_s
|
263
|
+
end
|
264
|
+
|
265
|
+
# @return [String]
|
266
|
+
def inspect
|
267
|
+
target = __getobj__
|
268
|
+
return target.inspect unless target.nil?
|
269
|
+
|
270
|
+
"#<#{self.class.name} #{__send__(@klass::UID_METHOD)}>"
|
271
|
+
end
|
272
|
+
|
273
|
+
#
|
274
|
+
# Supports inspect from IRB when we're a dummy
|
275
|
+
#
|
276
|
+
# @return [void]
|
277
|
+
# @!visibility private
|
278
|
+
def pretty_print(printer)
|
279
|
+
target = __getobj__
|
280
|
+
return target.pretty_print(printer) unless target.nil?
|
281
|
+
|
282
|
+
printer.text(inspect)
|
283
|
+
end
|
128
284
|
end
|
129
285
|
end
|
130
286
|
end
|
@@ -41,8 +41,8 @@ module OpenHAB
|
|
41
41
|
# @yield Block executed in the context of a {DSL::Rules::Builder}.
|
42
42
|
# @return [Object] The result of the block.
|
43
43
|
#
|
44
|
-
def build(preferred_provider = nil, &
|
45
|
-
DSL::Rules::Builder.new(preferred_provider).instance_eval_with_dummy_items(&
|
44
|
+
def build(preferred_provider = nil, &)
|
45
|
+
DSL::Rules::Builder.new(preferred_provider).instance_eval_with_dummy_items(&)
|
46
46
|
end
|
47
47
|
|
48
48
|
#
|
@@ -132,7 +132,7 @@ module OpenHAB
|
|
132
132
|
tags.map! do |tag|
|
133
133
|
tag.is_a?(::Module) ? tag.simple_name : tag # ::Module to distinguish against Rule::Module!
|
134
134
|
end
|
135
|
-
|
135
|
+
!!self.tags.to_a.intersect?(tags)
|
136
136
|
end
|
137
137
|
|
138
138
|
#
|
@@ -178,16 +178,12 @@ module OpenHAB
|
|
178
178
|
# @return [Hash] A copy of the rule context, including possible return values.
|
179
179
|
#
|
180
180
|
def trigger(event = nil, consider_conditions: false, **context)
|
181
|
-
|
182
|
-
|
183
|
-
.createExecutionEvent(uid, nil, "manual")
|
184
|
-
rescue NameError
|
185
|
-
# @deprecated OH3.4 doesn't have AutomationEventFactory
|
186
|
-
end
|
181
|
+
event ||= org.openhab.core.automation.events.AutomationEventFactory
|
182
|
+
.createExecutionEvent(uid, nil, "manual")
|
187
183
|
context.transform_keys!(&:to_s)
|
188
184
|
# Unwrap any proxies and pass raw objects (items, things)
|
189
185
|
context.transform_values! { |value| value.is_a?(Delegator) ? value.__getobj__ : value }
|
190
|
-
context["event"] = event
|
186
|
+
context["event"] = event
|
191
187
|
Rules.manager.run_now(uid, consider_conditions, context)
|
192
188
|
end
|
193
189
|
alias_method :run, :trigger
|
@@ -90,7 +90,7 @@ module OpenHAB
|
|
90
90
|
#
|
91
91
|
# Executed when openHAB unloads a script file
|
92
92
|
#
|
93
|
-
def scriptUnloaded # rubocop:disable Naming/MethodName method name dictated by openHAB
|
93
|
+
def scriptUnloaded # rubocop:disable Naming/MethodName -- method name dictated by openHAB
|
94
94
|
logger.trace("Script unloaded")
|
95
95
|
ScriptHandlingCallbacks.script_unloaded_hooks.sort_by(&:first).flat_map(&:last).each do |hook|
|
96
96
|
hook.call
|
@@ -118,7 +118,7 @@ module OpenHAB
|
|
118
118
|
#
|
119
119
|
# Executed when openHAB loads a script file
|
120
120
|
#
|
121
|
-
def scriptLoaded(filename) # rubocop:disable Naming/MethodName method name dictated by openHAB
|
121
|
+
def scriptLoaded(filename) # rubocop:disable Naming/MethodName -- method name dictated by openHAB
|
122
122
|
logger.trace { "Script loaded: #{filename}" }
|
123
123
|
ScriptHandlingCallbacks.script_loaded_hooks.each do |hook|
|
124
124
|
hook.call
|
@@ -130,7 +130,7 @@ module OpenHAB
|
|
130
130
|
#
|
131
131
|
def build(update: true, &block)
|
132
132
|
builder_proxy = SimpleDelegator.new(nil) if block.arity == 1
|
133
|
-
builder = DSL::Sitemaps::Builder.new(self, builder_proxy, update:
|
133
|
+
builder = DSL::Sitemaps::Builder.new(self, builder_proxy, update:)
|
134
134
|
if block.arity == 1
|
135
135
|
builder_proxy.__setobj__(builder)
|
136
136
|
DSL::ThreadLocal.thread_local(openhab_create_dummy_items: true) do
|
@@ -176,34 +176,6 @@ module OpenHAB
|
|
176
176
|
|
177
177
|
provider.remove(link_to_delete.uid)
|
178
178
|
end
|
179
|
-
|
180
|
-
# @deprecated OH3.4 this whole section is not needed in OH4+. Also see Thing#config_eql?
|
181
|
-
if Core.version < Core::V4_0
|
182
|
-
# @!visibility private
|
183
|
-
module ChannelComparable
|
184
|
-
# @!visibility private
|
185
|
-
# This is only needed in OH3 because it is implemented in OH4 core
|
186
|
-
def ==(other)
|
187
|
-
return true if equal?(other)
|
188
|
-
return false unless other.is_a?(Channel)
|
189
|
-
|
190
|
-
%i[class
|
191
|
-
uid
|
192
|
-
label
|
193
|
-
description
|
194
|
-
kind
|
195
|
-
channel_type_uid
|
196
|
-
configuration
|
197
|
-
properties
|
198
|
-
default_tags
|
199
|
-
auto_update_policy
|
200
|
-
accepted_item_type].all? do |attr|
|
201
|
-
send(attr) == other.send(attr)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
org.openhab.core.thing.binding.builder.ChannelBuilder.const_get(:ChannelImpl).prepend(ChannelComparable)
|
206
|
-
end
|
207
179
|
end
|
208
180
|
end
|
209
181
|
end
|
@@ -18,7 +18,7 @@ module OpenHAB
|
|
18
18
|
@dummy_channel_item = DSL::Items::ItemBuilder.item_factory.create_item(link.channel.accepted_item_type, "")
|
19
19
|
end
|
20
20
|
command = @dummy_channel_item.format_command(command) if @dummy_channel_item
|
21
|
-
super
|
21
|
+
super
|
22
22
|
end
|
23
23
|
|
24
24
|
#
|
@@ -28,7 +28,7 @@ module OpenHAB
|
|
28
28
|
#
|
29
29
|
def send_command(command)
|
30
30
|
command = link.item.format_command(command)
|
31
|
-
super
|
31
|
+
super
|
32
32
|
end
|
33
33
|
|
34
34
|
#
|
@@ -38,7 +38,7 @@ module OpenHAB
|
|
38
38
|
#
|
39
39
|
def send_update(state)
|
40
40
|
state = link.item.format_update(state)
|
41
|
-
super
|
41
|
+
super
|
42
42
|
end
|
43
43
|
|
44
44
|
# @!method send_time_series(time_series)
|
@@ -3,6 +3,9 @@
|
|
3
3
|
require "delegate"
|
4
4
|
require "forwardable"
|
5
5
|
|
6
|
+
require_relative "thing"
|
7
|
+
require_relative "thing_uid"
|
8
|
+
|
6
9
|
module OpenHAB
|
7
10
|
module Core
|
8
11
|
module Things
|
@@ -18,9 +21,14 @@ module OpenHAB
|
|
18
21
|
Events::ThingRemovedEvent::TYPE].freeze
|
19
22
|
# @!visibility private
|
20
23
|
UID_METHOD = :uid
|
24
|
+
# @!visibility private
|
25
|
+
UID_TYPE = ThingUID
|
21
26
|
|
22
27
|
include Core::Proxy
|
23
28
|
|
29
|
+
# @return [ThingUID]
|
30
|
+
attr_reader :uid
|
31
|
+
|
24
32
|
# Returns the list of channels associated with this Thing
|
25
33
|
#
|
26
34
|
# @note This is defined on this class, and not on {Thing}, because
|
@@ -42,57 +50,6 @@ module OpenHAB
|
|
42
50
|
def properties
|
43
51
|
Thing::Properties.new(self)
|
44
52
|
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# Set the proxy item (called by super)
|
48
|
-
#
|
49
|
-
def __setobj__(thing)
|
50
|
-
@uid = thing.uid
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Lookup thing from thing registry
|
55
|
-
#
|
56
|
-
def __getobj__
|
57
|
-
$things.get(@uid)
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
# Need to check if `self` _or_ the delegate is an instance of the
|
62
|
-
# given class
|
63
|
-
#
|
64
|
-
# So that {#==} can work
|
65
|
-
#
|
66
|
-
# @return [true, false]
|
67
|
-
#
|
68
|
-
# @!visibility private
|
69
|
-
def instance_of?(klass)
|
70
|
-
__getobj__.instance_of?(klass) || super
|
71
|
-
end
|
72
|
-
|
73
|
-
#
|
74
|
-
# Check if delegates are equal for comparison
|
75
|
-
#
|
76
|
-
# Otherwise items can't be used in Java maps
|
77
|
-
#
|
78
|
-
# @return [true, false]
|
79
|
-
#
|
80
|
-
# @!visibility private
|
81
|
-
def ==(other)
|
82
|
-
return __getobj__ == other.__getobj__ if other.instance_of?(Proxy)
|
83
|
-
|
84
|
-
super
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
# Non equality comparison
|
89
|
-
#
|
90
|
-
# @return [true, false]
|
91
|
-
#
|
92
|
-
# @!visibility private
|
93
|
-
def !=(other)
|
94
|
-
!(self == other) # rubocop:disable Style/InverseMethods
|
95
|
-
end
|
96
53
|
end
|
97
54
|
end
|
98
55
|
end
|
@@ -49,7 +49,7 @@ module OpenHAB
|
|
49
49
|
# wasn't created by the current provider.
|
50
50
|
#
|
51
51
|
def build(preferred_provider = nil, update: true, &block)
|
52
|
-
DSL::Things::Builder.new(preferred_provider, update:
|
52
|
+
DSL::Things::Builder.new(preferred_provider, update:).instance_eval(&block)
|
53
53
|
end
|
54
54
|
|
55
55
|
#
|
@@ -268,9 +268,7 @@ module OpenHAB
|
|
268
268
|
# @return [true,false] true if all attributes are equal, false otherwise
|
269
269
|
#
|
270
270
|
def config_eql?(other)
|
271
|
-
|
272
|
-
channels.to_a == other.channels.to_a &&
|
273
|
-
%i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
|
271
|
+
%i[uid label bridge_uid location configuration channels].all? { |method| send(method) == other.send(method) }
|
274
272
|
end
|
275
273
|
|
276
274
|
#
|
@@ -279,8 +277,8 @@ module OpenHAB
|
|
279
277
|
# @example
|
280
278
|
# things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
|
281
279
|
#
|
282
|
-
def method_missing(method,
|
283
|
-
return actions.public_send(method,
|
280
|
+
def method_missing(method, ...)
|
281
|
+
return actions.public_send(method, ...) if actions.respond_to?(method)
|
284
282
|
|
285
283
|
super
|
286
284
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Types
|
6
|
+
CommandDescription = org.openhab.core.types.CommandDescription
|
7
|
+
|
8
|
+
# Describes commands you can send to an item
|
9
|
+
module CommandDescription
|
10
|
+
# @!attribute [r] options
|
11
|
+
# @return [Array<org.openhab.core.types.CommandOption>]
|
12
|
+
def options
|
13
|
+
command_options
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [String]
|
17
|
+
def inspect
|
18
|
+
s = "#<OpenHAB::Core::Types::CommandDescription options=["
|
19
|
+
command_options.each_with_index do |o, i|
|
20
|
+
s += ", " if i != 0
|
21
|
+
|
22
|
+
s += o.command.inspect
|
23
|
+
|
24
|
+
s += " (#{o.label.inspect})" if o.command != o.label && !o.label.nil?
|
25
|
+
end
|
26
|
+
s += "]>"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -60,12 +60,7 @@ module OpenHAB
|
|
60
60
|
# @return [ZonedDateTime]
|
61
61
|
|
62
62
|
# @!visibility private
|
63
|
-
|
64
|
-
# @deprecated OH 3.4 getInstant() was added in OH 4.0
|
65
|
-
return get_instant if respond_to?(:get_instant)
|
66
|
-
|
67
|
-
zoned_date_time.to_instant
|
68
|
-
end
|
63
|
+
alias_method :to_instant, :get_instant
|
69
64
|
|
70
65
|
# @!method to_instant
|
71
66
|
# @return [Instant]
|
@@ -239,14 +234,14 @@ module OpenHAB
|
|
239
234
|
# Forward missing methods to the `ZonedDateTime` object or a ruby `Time`
|
240
235
|
# object representing the same instant
|
241
236
|
#
|
242
|
-
def method_missing(method,
|
237
|
+
def method_missing(method, ...)
|
243
238
|
# @deprecated OH 4.2 Remove version check when dropping OH 4.2
|
244
239
|
if OpenHAB::Core.version >= OpenHAB::Core::V4_3 && to_instant.respond_to?(method)
|
245
|
-
return to_instant.send(method,
|
240
|
+
return to_instant.send(method, ...)
|
246
241
|
end
|
247
242
|
|
248
|
-
return zoned_date_time.send(method,
|
249
|
-
return to_time.send(method,
|
243
|
+
return zoned_date_time.send(method, ...) if zoned_date_time.respond_to?(method)
|
244
|
+
return to_time.send(method, ...) if ::Time.instance_methods.include?(method.to_sym)
|
250
245
|
|
251
246
|
super
|
252
247
|
end
|
@@ -139,7 +139,7 @@ module OpenHAB
|
|
139
139
|
remainder: :%,
|
140
140
|
pow: :**
|
141
141
|
}.each do |java_op, ruby_op|
|
142
|
-
class_eval( # rubocop:disable Style/DocumentDynamicEvalDefinition https://github.com/rubocop/rubocop/issues/10179
|
142
|
+
class_eval( # rubocop:disable Style/DocumentDynamicEvalDefinition -- https://github.com/rubocop/rubocop/issues/10179
|
143
143
|
# def +(other)
|
144
144
|
# if other.is_a?(DecimalType)
|
145
145
|
# self.class.new(to_big_decimal.add(other.to_big_decimal))
|