openhab-scripting 2.16.1 → 2.16.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7471d207d040d9fb085fa45e4f6be88f7ad9d99b0987b6a6845f2bb85c8bf5ab
|
4
|
+
data.tar.gz: b000d8e9397d5556c4387f09e1ec247ccd8303cfa83b27722737e38324ac91b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13d1994d629262afc44f8c8e62c965e65e383e91224b8fbd12d83f9ec61fa707a0655060c805e3342b373adc5d3034f1744defca1803f84d52190aab055cd8de
|
7
|
+
data.tar.gz: 368969daaa876bdebbd0b60b8818f9da333c2c6d9df96fa7f00abf99df4891f32cd2151d576a6819c2213630fd1ccf3e1a81a1ddc5aa48d2bfe20be776a3c91a
|
@@ -27,6 +27,7 @@ end
|
|
27
27
|
#
|
28
28
|
module EntityLookup
|
29
29
|
include Logging
|
30
|
+
|
30
31
|
#
|
31
32
|
# Decorate items with Ruby wrappers
|
32
33
|
#
|
@@ -34,26 +35,32 @@ module EntityLookup
|
|
34
35
|
#
|
35
36
|
# @return [Array] Array of decorated items
|
36
37
|
#
|
37
|
-
# rubocop: disable Metrics/MethodLength
|
38
|
-
# Disabled line length - case dispatch pattern
|
39
38
|
def self.decorate_items(*items)
|
40
|
-
items.flatten.map
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
39
|
+
items.flatten.map { |item| decorate_item(item) }
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Decorate item with Ruby wrappers
|
44
|
+
#
|
45
|
+
# @param [Object] item the item object to decorate
|
46
|
+
#
|
47
|
+
# @return [Object] the ruby wrapper for the item
|
48
|
+
#
|
49
|
+
def self.decorate_item(item)
|
50
|
+
case item
|
51
|
+
when GroupItem
|
52
|
+
decorate_group(item)
|
53
|
+
when Java::Org.openhab.core.library.items::NumberItem
|
54
|
+
OpenHAB::Core::DSL::Items::NumberItem.new(item)
|
55
|
+
when Java::Org.openhab.core.library.items::StringItem
|
56
|
+
OpenHAB::Core::DSL::Items::StringItem.new(item)
|
57
|
+
else
|
58
|
+
item
|
51
59
|
end
|
52
60
|
end
|
53
|
-
# rubocop: enable Metrics/MethodLength
|
54
61
|
|
55
62
|
#
|
56
|
-
#
|
63
|
+
# Looks up a Thing in the OpenHAB registry replacing '_' with ':'
|
57
64
|
#
|
58
65
|
# @param [String] name of Thing to lookup in Thing registry
|
59
66
|
#
|
@@ -86,7 +93,7 @@ module EntityLookup
|
|
86
93
|
# rubocop: disable Style/GlobalVars
|
87
94
|
item = $ir.get(name)
|
88
95
|
# rubocop: enable Style/GlobalVars
|
89
|
-
EntityLookup.
|
96
|
+
EntityLookup.decorate_item(item)
|
90
97
|
end
|
91
98
|
|
92
99
|
#
|
@@ -86,6 +86,15 @@ module OpenHAB
|
|
86
86
|
def to_s
|
87
87
|
"[#{map(&:to_s).join(',')}]"
|
88
88
|
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Get an ID for the group, using the label if set, otherwise group name
|
92
|
+
#
|
93
|
+
# @return [String] label if set otherwise name
|
94
|
+
#
|
95
|
+
def id
|
96
|
+
label || name
|
97
|
+
end
|
89
98
|
end
|
90
99
|
end
|
91
100
|
end
|
@@ -21,7 +21,7 @@ module OpenHAB
|
|
21
21
|
# rubocop: disable Style/GlobalVars
|
22
22
|
item = $ir.getItem(name)
|
23
23
|
# rubocop: enable Style/GlobalVars
|
24
|
-
item.is_a?(GroupItem) ? nil : item
|
24
|
+
item.is_a?(GroupItem) ? nil : EntityLookup.decorate_item(item)
|
25
25
|
rescue Java::OrgOpenhabCoreItems::ItemNotFoundException
|
26
26
|
nil
|
27
27
|
end
|
@@ -221,20 +221,18 @@ module OpenHAB
|
|
221
221
|
end
|
222
222
|
|
223
223
|
#
|
224
|
-
# Patch event to
|
225
|
-
# This is to patch a bug see https://github.com/boc-tothefuture/openhab-jruby/issues/75
|
226
|
-
# It may be fixed in the openhab core in the future, in which case, this patch will no longer be necessary
|
224
|
+
# Patch event to decorate event.item with our item wrapper
|
227
225
|
#
|
228
|
-
# @param [OpenHAB Event] event
|
229
|
-
# @param [OpenHAB Event Inputs] inputs inputs to running rule
|
226
|
+
# @param [OpenHAB Event] event patch
|
230
227
|
#
|
231
|
-
def
|
232
|
-
return if event.nil?
|
228
|
+
def decorate_event_item(event)
|
229
|
+
return if event.nil?
|
233
230
|
|
234
231
|
class << event
|
235
|
-
|
232
|
+
def item
|
233
|
+
EntityLookup.lookup_item(item_name)
|
234
|
+
end
|
236
235
|
end
|
237
|
-
event.item = inputs&.dig('triggeringItem')
|
238
236
|
end
|
239
237
|
|
240
238
|
#
|
@@ -266,6 +264,7 @@ module OpenHAB
|
|
266
264
|
#
|
267
265
|
#
|
268
266
|
def process_otherwise_task(event, task)
|
267
|
+
decorate_event_item(event)
|
269
268
|
logger.trace { "Executing rule '#{name}' otherwise block with event(#{event})" }
|
270
269
|
task.block.call(event)
|
271
270
|
end
|
@@ -292,9 +291,7 @@ module OpenHAB
|
|
292
291
|
#
|
293
292
|
#
|
294
293
|
def process_trigger_task(event, task)
|
295
|
-
|
296
|
-
triggering_item = $ir.get(event&.itemName)
|
297
|
-
# rubocop: enable Style/GlobalVars
|
294
|
+
triggering_item = EntityLookup.lookup_item(event&.itemName)
|
298
295
|
logger.trace { "Executing rule '#{name}' trigger block with item (#{triggering_item})" }
|
299
296
|
task.block.call(triggering_item) if triggering_item
|
300
297
|
end
|
@@ -307,8 +304,8 @@ module OpenHAB
|
|
307
304
|
# @param [Run] task to execute
|
308
305
|
#
|
309
306
|
#
|
310
|
-
def process_run_task(event,
|
311
|
-
|
307
|
+
def process_run_task(event, _inputs, task)
|
308
|
+
decorate_event_item(event)
|
312
309
|
logger.trace { "Executing rule '#{name}' run block with event(#{event})" }
|
313
310
|
task.block.call(event)
|
314
311
|
end
|
data/lib/openhab/version.rb
CHANGED