openhab-scripting 4.1.1 → 4.1.2
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/group.rb +20 -9
- data/lib/openhab/dsl/items/group_item.rb +4 -14
- data/lib/openhab/dsl/items/items.rb +6 -18
- data/lib/openhab/dsl/lazy_array.rb +44 -0
- data/lib/openhab/dsl/things.rb +6 -22
- data/lib/openhab/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d752e22ac324370b7c63e7e38455cd919f3f64abece0fc7ab62fd29c72953b7
|
4
|
+
data.tar.gz: 34c7cd408a075c831e7ea75e55f907bd57203268da81f34e318657d18ad6a90f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc29460c4a427f81fa6a8ce0760d746d0bf1513574e72f89a17c4d5647c22dc860abe12c60d4a0904f5c32927725bed03ff8ff62212bd45217e05d9b9e3fe01a
|
7
|
+
data.tar.gz: b29f6d50649f32134815cb71b9c2d42b466f9d0147a613bbc2225f99469f5c5d4194a7a5c47f81c20757b149c2e5bcc7133fc6b099025f43132ecef25bb2cfc2
|
data/lib/openhab/dsl/group.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'java'
|
4
|
+
require 'singleton'
|
5
|
+
|
5
6
|
require 'openhab/core/entity_lookup'
|
6
7
|
require 'openhab/dsl/items/group_item'
|
8
|
+
require 'openhab/dsl/lazy_array'
|
7
9
|
|
8
10
|
module OpenHAB
|
9
11
|
module DSL
|
@@ -14,16 +16,27 @@ module OpenHAB
|
|
14
16
|
#
|
15
17
|
# Provide access to groups as a set
|
16
18
|
#
|
17
|
-
class Groups
|
19
|
+
class Groups
|
20
|
+
include LazyArray
|
21
|
+
include Singleton
|
22
|
+
|
18
23
|
#
|
19
24
|
# Get a OpenHAB Group by name
|
20
25
|
# @param [String] name of the group to retrieve
|
21
26
|
#
|
22
27
|
# @return [Set] of OpenHAB Groups
|
23
28
|
#
|
24
|
-
def[](name)
|
25
|
-
group =
|
26
|
-
group.is_a?(
|
29
|
+
def [](name)
|
30
|
+
group = Core::EntityLookup.lookup_item(name)
|
31
|
+
group.is_a?(Items::GroupItem) ? group : nil
|
32
|
+
end
|
33
|
+
alias include? []
|
34
|
+
alias key? include?
|
35
|
+
|
36
|
+
# explicit conversion to array
|
37
|
+
def to_a
|
38
|
+
items = $ir.items.grep(org.openhab.core.items.GroupItem) # rubocop:disable Style/GlobalVars
|
39
|
+
Core::EntityLookup.decorate_items(items)
|
27
40
|
end
|
28
41
|
end
|
29
42
|
|
@@ -33,9 +46,7 @@ module OpenHAB
|
|
33
46
|
# @return [Set] of OpenHAB Groups
|
34
47
|
#
|
35
48
|
def groups
|
36
|
-
|
37
|
-
Groups.new(OpenHAB::Core::EntityLookup.decorate_items($ir.items.grep(Java::OrgOpenhabCoreItems::GroupItem)))
|
38
|
-
# rubocop: enable Style/GlobalVars
|
49
|
+
Groups.instance
|
39
50
|
end
|
40
51
|
end
|
41
52
|
end
|
@@ -3,9 +3,11 @@
|
|
3
3
|
require 'delegate'
|
4
4
|
require 'forwardable'
|
5
5
|
require 'java'
|
6
|
+
|
7
|
+
require 'openhab/core/entity_lookup'
|
6
8
|
require 'openhab/dsl/items/item_command'
|
7
9
|
require 'openhab/dsl/items/item_delegate'
|
8
|
-
require 'openhab/
|
10
|
+
require 'openhab/dsl/lazy_array'
|
9
11
|
|
10
12
|
module OpenHAB
|
11
13
|
module DSL
|
@@ -14,7 +16,7 @@ module OpenHAB
|
|
14
16
|
# Class for indicating to triggers that a group trigger should be used
|
15
17
|
#
|
16
18
|
class GroupMembers
|
17
|
-
include
|
19
|
+
include LazyArray
|
18
20
|
|
19
21
|
attr_reader :group
|
20
22
|
|
@@ -27,22 +29,10 @@ module OpenHAB
|
|
27
29
|
@group = group_item
|
28
30
|
end
|
29
31
|
|
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
32
|
# explicit conversion to array
|
40
|
-
# more efficient than letting Enumerable do it
|
41
33
|
def to_a
|
42
34
|
OpenHAB::Core::EntityLookup.decorate_items(group.members.to_a)
|
43
35
|
end
|
44
|
-
# implicitly convertible to array
|
45
|
-
alias to_ary to_a
|
46
36
|
end
|
47
37
|
|
48
38
|
#
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'java'
|
4
|
-
require 'openhab/core/entity_lookup'
|
5
4
|
require 'singleton'
|
6
5
|
|
6
|
+
require 'openhab/core/entity_lookup'
|
7
|
+
require 'openhab/dsl/lazy_array'
|
8
|
+
|
7
9
|
module OpenHAB
|
8
10
|
module DSL
|
9
11
|
#
|
@@ -14,7 +16,7 @@ module OpenHAB
|
|
14
16
|
# Delegates to underlying set of all OpenHAB Items, provides convenience methods
|
15
17
|
#
|
16
18
|
class Items
|
17
|
-
include
|
19
|
+
include LazyArray
|
18
20
|
include Singleton
|
19
21
|
|
20
22
|
# Fetches the named item from the the ItemRegistry
|
@@ -32,27 +34,13 @@ module OpenHAB
|
|
32
34
|
def include?(name)
|
33
35
|
!$ir.getItems(name).empty? # rubocop: disable Style/GlobalVars
|
34
36
|
end
|
35
|
-
alias key?
|
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
|
37
|
+
alias key? []
|
47
38
|
|
48
39
|
# explicit conversion to array
|
49
|
-
# more efficient than letting Enumerable do it
|
50
40
|
def to_a
|
51
|
-
items = $ir.items.grep_v(
|
41
|
+
items = $ir.items.grep_v(org.openhab.core.items.GroupItem) # rubocop:disable Style/GlobalVars
|
52
42
|
OpenHAB::Core::EntityLookup.decorate_items(items)
|
53
43
|
end
|
54
|
-
# implicitly convertible to array
|
55
|
-
alias to_ary to_a
|
56
44
|
end
|
57
45
|
|
58
46
|
# Fetches all non-group items from the item registry
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module DSL
|
5
|
+
# common base class for array-like collections that have lookup
|
6
|
+
# methods to avoid instantiating the elements if you only use
|
7
|
+
# the lookup method
|
8
|
+
#
|
9
|
+
# your class should implement to_a
|
10
|
+
#
|
11
|
+
module LazyArray
|
12
|
+
include Enumerable
|
13
|
+
|
14
|
+
# Calls the given block once for each Thing, passing that Thing as a
|
15
|
+
# parameter. Returns self.
|
16
|
+
#
|
17
|
+
# If no block is given, an Enumerator is returned.
|
18
|
+
def each(&block)
|
19
|
+
to_a.each(&block)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
# implicitly convertible to array
|
24
|
+
def to_ary
|
25
|
+
to_a
|
26
|
+
end
|
27
|
+
|
28
|
+
# delegate any other methods to the actual array
|
29
|
+
# exclude mutating methods though
|
30
|
+
def method_missing(method, *args, &block)
|
31
|
+
return to_a.send(method, *args, &block) if method[-1] != '!' && Array.instance_methods.include?(method)
|
32
|
+
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
# advertise that methods exist that would be delegated to Array
|
37
|
+
def respond_to_missing?(method, include_private = false)
|
38
|
+
return true if method[-1] != '!' && Array.instance_methods.include?(method.to_sym)
|
39
|
+
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/openhab/dsl/things.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'delegate'
|
3
4
|
require 'java'
|
5
|
+
require 'singleton'
|
6
|
+
|
4
7
|
require 'openhab/log/logger'
|
5
8
|
require 'openhab/dsl/actions'
|
6
|
-
require '
|
7
|
-
require 'singleton'
|
9
|
+
require 'openhab/dsl/lazy_array'
|
8
10
|
|
9
11
|
module OpenHAB
|
10
12
|
module DSL
|
@@ -78,44 +80,26 @@ module OpenHAB
|
|
78
80
|
# Wraps all Things in a delegator to underlying set and provides lookup method
|
79
81
|
#
|
80
82
|
class Things
|
81
|
-
|
82
|
-
|
83
|
-
include Enumerable
|
83
|
+
include LazyArray
|
84
84
|
include Singleton
|
85
85
|
|
86
86
|
# Gets a specific thing by name in the format binding_id:type_id:thing_id
|
87
87
|
# @return Thing specified by name or nil if name does not exist in thing registry
|
88
88
|
def [](uid)
|
89
|
-
thing_uid = ThingUID.new(*uid.split(':'))
|
89
|
+
thing_uid = org.openhab.core.thing.ThingUID.new(*uid.split(':'))
|
90
90
|
thing = $things.get(thing_uid) # rubocop: disable Style/GlobalVars
|
91
91
|
return unless thing
|
92
92
|
|
93
93
|
logger.trace("Retrieved Thing(#{thing}) from registry for uid: #{uid}")
|
94
94
|
Thing.new(thing)
|
95
95
|
end
|
96
|
-
|
97
96
|
alias include? []
|
98
97
|
alias key? []
|
99
98
|
|
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
99
|
# explicit conversion to array
|
113
|
-
# more efficient than letting Enumerable do it
|
114
100
|
def to_a
|
115
101
|
$things.getAll.map { |thing| Thing.new(thing) } # rubocop: disable Style/GlobalVars
|
116
102
|
end
|
117
|
-
# implicitly convertible to array
|
118
|
-
alias to_ary to_a
|
119
103
|
end
|
120
104
|
|
121
105
|
#
|
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.1.
|
4
|
+
version: 4.1.2
|
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: 2021-10-
|
11
|
+
date: 2021-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/openhab/dsl/items/player_item.rb
|
65
65
|
- lib/openhab/dsl/items/rollershutter_item.rb
|
66
66
|
- lib/openhab/dsl/items/string_item.rb
|
67
|
+
- lib/openhab/dsl/lazy_array.rb
|
67
68
|
- lib/openhab/dsl/monkey_patch/actions/actions.rb
|
68
69
|
- lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb
|
69
70
|
- lib/openhab/dsl/monkey_patch/events/events.rb
|