openhab-scripting 4.0.0 → 4.0.1
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/items/group_item.rb +21 -3
- data/lib/openhab/dsl/items/items.rb +28 -8
- data/lib/openhab/dsl/rules/triggers/command.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/trigger.rb +6 -2
- data/lib/openhab/dsl/rules/triggers/updated.rb +1 -1
- data/lib/openhab/dsl/things.rb +32 -9
- 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: 4028b9fda2ff3ffa7005f730d7b876e136cf4c3dacc66f0f8950077c4a8f5ab9
|
4
|
+
data.tar.gz: dc819dea7d3f573299934da843ddadc597f98f59165426e6c88e321a1fd93200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2839736ff1c0d15c6622e679e7ada29d6f34afe5bae7d9fa375ebe34e809b14eb0f54b447d95ff7548b3f97786f0c7f6f979cd8ce796fa84bdbb1b60312a7e73
|
7
|
+
data.tar.gz: 45b0ca416f63b8971fdd4f7ee7d86c449ac44b0d0acdf6a1ce6955d604c04bf12788900a180fde7ec49d9fafe8aa5a5b6a8d4271cc5a72ab4440ddbe9e7a2b8a
|
@@ -13,7 +13,9 @@ module OpenHAB
|
|
13
13
|
#
|
14
14
|
# Class for indicating to triggers that a group trigger should be used
|
15
15
|
#
|
16
|
-
class GroupMembers
|
16
|
+
class GroupMembers
|
17
|
+
include Enumerable
|
18
|
+
|
17
19
|
attr_reader :group
|
18
20
|
|
19
21
|
#
|
@@ -23,8 +25,24 @@ module OpenHAB
|
|
23
25
|
#
|
24
26
|
def initialize(group_item)
|
25
27
|
@group = group_item
|
26
|
-
super(OpenHAB::Core::EntityLookup.decorate_items(@group.members.to_a))
|
27
28
|
end
|
29
|
+
|
30
|
+
# Calls the given block once for each group member, passing that
|
31
|
+
# item as a parameter. Returns self.
|
32
|
+
#
|
33
|
+
# If no block is given, an Enumerator is returned.
|
34
|
+
def each(&block)
|
35
|
+
to_a.each(&block)
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
# explicit conversion to array
|
40
|
+
# more efficient than letting Enumerable do it
|
41
|
+
def to_a
|
42
|
+
OpenHAB::Core::EntityLookup.decorate_items(group.members.to_a)
|
43
|
+
end
|
44
|
+
# implicitly convertible to array
|
45
|
+
alias to_ary to_a
|
28
46
|
end
|
29
47
|
|
30
48
|
#
|
@@ -74,7 +92,7 @@ module OpenHAB
|
|
74
92
|
# Iterates through the direct members of the Group
|
75
93
|
#
|
76
94
|
def each(&block)
|
77
|
-
|
95
|
+
members.each(&block)
|
78
96
|
end
|
79
97
|
|
80
98
|
#
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'java'
|
4
4
|
require 'openhab/core/entity_lookup'
|
5
|
+
require 'singleton'
|
5
6
|
|
6
7
|
module OpenHAB
|
7
8
|
module DSL
|
@@ -12,11 +13,14 @@ module OpenHAB
|
|
12
13
|
#
|
13
14
|
# Delegates to underlying set of all OpenHAB Items, provides convenience methods
|
14
15
|
#
|
15
|
-
class Items
|
16
|
+
class Items
|
17
|
+
include Enumerable
|
18
|
+
include Singleton
|
19
|
+
|
16
20
|
# Fetches the named item from the the ItemRegistry
|
17
21
|
# @param [String] name
|
18
22
|
# @return Item from registry, nil if item missing or requested item is a Group Type
|
19
|
-
def[](name)
|
23
|
+
def [](name)
|
20
24
|
OpenHAB::Core::EntityLookup.lookup_item(name)
|
21
25
|
rescue Java::OrgOpenhabCoreItems::ItemNotFoundException
|
22
26
|
nil
|
@@ -26,19 +30,35 @@ module OpenHAB
|
|
26
30
|
# @param name [String] Item name to check
|
27
31
|
# @return [Boolean] true if the item exists, false otherwise
|
28
32
|
def include?(name)
|
29
|
-
# rubocop: disable Style/GlobalVars
|
30
|
-
!$ir.getItems(name).empty?
|
31
|
-
# rubocop: enable Style/GlobalVars
|
33
|
+
!$ir.getItems(name).empty? # rubocop: disable Style/GlobalVars
|
32
34
|
end
|
33
35
|
alias key? include?
|
36
|
+
|
37
|
+
# Calls the given block once for each Item, passing that Item as a
|
38
|
+
# parameter. Returns self.
|
39
|
+
#
|
40
|
+
# If no block is given, an Enumerator is returned.
|
41
|
+
def each(&block)
|
42
|
+
# ideally we would do this lazily, but until ruby 2.7
|
43
|
+
# there's no #eager method to convert back to a non-lazy
|
44
|
+
# enumerator
|
45
|
+
to_a.each(&block)
|
46
|
+
end
|
47
|
+
|
48
|
+
# explicit conversion to array
|
49
|
+
# more efficient than letting Enumerable do it
|
50
|
+
def to_a
|
51
|
+
items = $ir.items.grep_v(Java::OrgOpenhabCoreItems::GroupItem) # rubocop:disable Style/GlobalVars
|
52
|
+
OpenHAB::Core::EntityLookup.decorate_items(items)
|
53
|
+
end
|
54
|
+
# implicitly convertible to array
|
55
|
+
alias to_ary to_a
|
34
56
|
end
|
35
57
|
|
36
58
|
# Fetches all non-group items from the item registry
|
37
59
|
# @return [OpenHAB::DSL::Items::Items]
|
38
60
|
def items
|
39
|
-
|
40
|
-
Items.new(OpenHAB::Core::EntityLookup.decorate_items($ir.items.grep_v(Java::OrgOpenhabCoreItems::GroupItem)))
|
41
|
-
# rubocop: enable Style/GlobalVars
|
61
|
+
Items.instance
|
42
62
|
end
|
43
63
|
end
|
44
64
|
end
|
@@ -22,7 +22,7 @@ module OpenHAB
|
|
22
22
|
#
|
23
23
|
#
|
24
24
|
def received_command(*items, command: nil, commands: nil)
|
25
|
-
separate_groups(items).
|
25
|
+
separate_groups(items).each do |item|
|
26
26
|
logger.trace("Creating received command trigger for item(#{item})"\
|
27
27
|
"command(#{command}) commands(#{commands})")
|
28
28
|
|
@@ -61,9 +61,13 @@ module OpenHAB
|
|
61
61
|
# @return [Array] A new flat array with any GroupMembers object left intact
|
62
62
|
#
|
63
63
|
def separate_groups(item_array)
|
64
|
-
|
64
|
+
# we want to support anything that can be flattened... i.e. responds to to_ary
|
65
|
+
# we want to be more lenient than only things that are currently Array,
|
66
|
+
# but Enumerable is too lenient because Array#flatten won't traverse interior
|
67
|
+
# Enumerables
|
68
|
+
return item_array unless item_array.find { |item| item.respond_to?(:to_ary) }
|
65
69
|
|
66
|
-
groups, items = item_array.partition { |item| item.is_a?
|
70
|
+
groups, items = item_array.partition { |item| item.is_a?(OpenHAB::DSL::Items::GroupItem::GroupMembers) }
|
67
71
|
groups + separate_groups(items.flatten(1))
|
68
72
|
end
|
69
73
|
|
@@ -20,7 +20,7 @@ module OpenHAB
|
|
20
20
|
# @return [Trigger] Trigger for updated entity
|
21
21
|
#
|
22
22
|
def updated(*items, to: nil)
|
23
|
-
separate_groups(items).
|
23
|
+
separate_groups(items).each do |item|
|
24
24
|
logger.trace("Creating updated trigger for item(#{item}) to(#{to})")
|
25
25
|
[to].flatten.each do |to_state|
|
26
26
|
trigger, config = create_update_trigger(item, to_state)
|
data/lib/openhab/dsl/things.rb
CHANGED
@@ -4,6 +4,7 @@ require 'java'
|
|
4
4
|
require 'openhab/log/logger'
|
5
5
|
require 'openhab/dsl/actions'
|
6
6
|
require 'delegate'
|
7
|
+
require 'singleton'
|
7
8
|
|
8
9
|
module OpenHAB
|
9
10
|
module DSL
|
@@ -76,32 +77,54 @@ module OpenHAB
|
|
76
77
|
#
|
77
78
|
# Wraps all Things in a delegator to underlying set and provides lookup method
|
78
79
|
#
|
79
|
-
class Things
|
80
|
+
class Things
|
80
81
|
java_import org.openhab.core.thing.ThingUID
|
81
82
|
|
83
|
+
include Enumerable
|
84
|
+
include Singleton
|
85
|
+
|
82
86
|
# Gets a specific thing by name in the format binding_id:type_id:thing_id
|
83
87
|
# @return Thing specified by name or nil if name does not exist in thing registry
|
84
|
-
def[](uid)
|
88
|
+
def [](uid)
|
85
89
|
thing_uid = ThingUID.new(*uid.split(':'))
|
86
|
-
# rubocop: disable Style/GlobalVars
|
87
|
-
thing = $things.get(thing_uid)
|
88
|
-
# rubocop: enable Style/GlobalVars
|
90
|
+
thing = $things.get(thing_uid) # rubocop: disable Style/GlobalVars
|
89
91
|
return unless thing
|
90
92
|
|
91
93
|
logger.trace("Retrieved Thing(#{thing}) from registry for uid: #{uid}")
|
92
94
|
Thing.new(thing)
|
93
95
|
end
|
96
|
+
|
97
|
+
alias include? []
|
98
|
+
alias key? []
|
99
|
+
|
100
|
+
# Calls the given block once for each Thing, passing that Thing as a
|
101
|
+
# parameter. Returns self.
|
102
|
+
#
|
103
|
+
# If no block is given, an Enumerator is returned.
|
104
|
+
def each(&block)
|
105
|
+
# ideally we would do this lazily, but until ruby 2.7
|
106
|
+
# there's no #eager method to convert back to a non-lazy
|
107
|
+
# enumerator
|
108
|
+
to_a.each(&block)
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
# explicit conversion to array
|
113
|
+
# more efficient than letting Enumerable do it
|
114
|
+
def to_a
|
115
|
+
$things.getAll.map { |thing| Thing.new(thing) } # rubocop: disable Style/GlobalVars
|
116
|
+
end
|
117
|
+
# implicitly convertible to array
|
118
|
+
alias to_ary to_a
|
94
119
|
end
|
95
120
|
|
96
121
|
#
|
97
122
|
# Get all things known to OpenHAB
|
98
123
|
#
|
99
|
-
# @return [
|
124
|
+
# @return [Things] all Thing objects known to OpenHAB
|
100
125
|
#
|
101
126
|
def things
|
102
|
-
|
103
|
-
Things.new($things.getAll.map { |thing| Thing.new(thing) }.to_set)
|
104
|
-
# rubocop: enable Style/GlobalVars
|
127
|
+
Things.instance
|
105
128
|
end
|
106
129
|
end
|
107
130
|
end
|
data/lib/openhab/version.rb
CHANGED