openhab-scripting 4.1.4 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/core/entity_lookup.rb +1 -57
  3. data/lib/openhab/dsl/actions.rb +2 -3
  4. data/lib/openhab/dsl/dsl.rb +8 -12
  5. data/lib/openhab/dsl/group.rb +1 -5
  6. data/lib/openhab/dsl/items/color_item.rb +60 -0
  7. data/lib/openhab/dsl/items/comparable_item.rb +49 -0
  8. data/lib/openhab/dsl/items/contact_item.rb +41 -0
  9. data/lib/openhab/dsl/items/date_time_item.rb +64 -0
  10. data/lib/openhab/dsl/items/dimmer_item.rb +59 -0
  11. data/lib/openhab/dsl/items/ensure.rb +93 -0
  12. data/lib/openhab/dsl/items/generic_item.rb +174 -0
  13. data/lib/openhab/dsl/items/group_item.rb +121 -89
  14. data/lib/openhab/dsl/items/image_item.rb +5 -41
  15. data/lib/openhab/dsl/items/item_equality.rb +36 -0
  16. data/lib/openhab/dsl/items/item_registry.rb +49 -0
  17. data/lib/openhab/dsl/items/items.rb +81 -35
  18. data/lib/openhab/dsl/items/metadata.rb +325 -0
  19. data/lib/openhab/dsl/items/number_item.rb +6 -312
  20. data/lib/openhab/dsl/items/numeric_item.rb +68 -0
  21. data/lib/openhab/dsl/items/persistence.rb +122 -0
  22. data/lib/openhab/dsl/items/player_item.rb +49 -40
  23. data/lib/openhab/dsl/items/rollershutter_item.rb +25 -77
  24. data/lib/openhab/dsl/items/string_item.rb +16 -58
  25. data/lib/openhab/dsl/items/switch_item.rb +62 -0
  26. data/lib/openhab/dsl/lazy_array.rb +8 -6
  27. data/lib/openhab/dsl/monkey_patch/events/events.rb +2 -2
  28. data/lib/openhab/dsl/monkey_patch/events/item_command.rb +67 -24
  29. data/lib/openhab/dsl/monkey_patch/events/item_event.rb +5 -5
  30. data/lib/openhab/dsl/monkey_patch/events/item_state.rb +10 -11
  31. data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +10 -11
  32. data/lib/openhab/dsl/monkey_patch/ruby/number.rb +25 -2
  33. data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +0 -3
  34. data/lib/openhab/dsl/monkey_patch/ruby/string.rb +24 -24
  35. data/lib/openhab/dsl/rules/terse.rb +24 -0
  36. data/lib/openhab/dsl/states.rb +1 -1
  37. data/lib/openhab/dsl/time_of_day.rb +3 -5
  38. data/lib/openhab/dsl/types/comparable_type.rb +21 -0
  39. data/lib/openhab/dsl/types/date_time_type.rb +334 -0
  40. data/lib/openhab/dsl/types/decimal_type.rb +187 -0
  41. data/lib/openhab/dsl/types/hsb_type.rb +201 -0
  42. data/lib/openhab/dsl/types/increase_decrease_type.rb +23 -0
  43. data/lib/openhab/dsl/types/next_previous_type.rb +23 -0
  44. data/lib/openhab/dsl/types/numeric_type.rb +39 -0
  45. data/lib/openhab/dsl/types/on_off_type.rb +29 -0
  46. data/lib/openhab/dsl/types/open_closed_type.rb +29 -0
  47. data/lib/openhab/dsl/types/percent_type.rb +70 -0
  48. data/lib/openhab/dsl/types/play_pause_type.rb +27 -0
  49. data/lib/openhab/dsl/types/quantity_type.rb +275 -0
  50. data/lib/openhab/dsl/types/refresh_type.rb +18 -0
  51. data/lib/openhab/dsl/types/rewind_fastforward_type.rb +33 -0
  52. data/lib/openhab/dsl/types/stop_move_type.rb +23 -0
  53. data/lib/openhab/dsl/types/string_type.rb +88 -0
  54. data/lib/openhab/dsl/types/type.rb +72 -0
  55. data/lib/openhab/dsl/types/types.rb +78 -0
  56. data/lib/openhab/dsl/types/un_def_type.rb +22 -0
  57. data/lib/openhab/dsl/types/up_down_type.rb +32 -0
  58. data/lib/openhab/dsl/units.rb +11 -6
  59. data/lib/openhab/version.rb +1 -1
  60. data/lib/openhab.rb +0 -1
  61. metadata +36 -28
  62. data/lib/openhab/dsl/items/datetime_item.rb +0 -75
  63. data/lib/openhab/dsl/items/item_command.rb +0 -90
  64. data/lib/openhab/dsl/items/item_delegate.rb +0 -125
  65. data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +0 -51
  66. data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +0 -140
  67. data/lib/openhab/dsl/monkey_patch/items/items.rb +0 -142
  68. data/lib/openhab/dsl/monkey_patch/items/metadata.rb +0 -328
  69. data/lib/openhab/dsl/monkey_patch/items/persistence.rb +0 -123
  70. data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +0 -71
  71. data/lib/openhab/dsl/monkey_patch/ruby/range.rb +0 -47
  72. data/lib/openhab/dsl/monkey_patch/ruby/time.rb +0 -32
  73. data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +0 -97
  74. data/lib/openhab/dsl/monkey_patch/types/increase_decrease_type.rb +0 -23
  75. data/lib/openhab/dsl/monkey_patch/types/next_previous_type.rb +0 -23
  76. data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +0 -79
  77. data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +0 -71
  78. data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +0 -77
  79. data/lib/openhab/dsl/monkey_patch/types/play_pause_type.rb +0 -23
  80. data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +0 -69
  81. data/lib/openhab/dsl/monkey_patch/types/refresh_type.rb +0 -23
  82. data/lib/openhab/dsl/monkey_patch/types/rewind_fastforward_type.rb +0 -23
  83. data/lib/openhab/dsl/monkey_patch/types/stop_move_type.rb +0 -23
  84. data/lib/openhab/dsl/monkey_patch/types/types.rb +0 -15
  85. data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +0 -72
  86. data/lib/openhab/dsl/types/datetime.rb +0 -338
  87. data/lib/openhab/dsl/types/quantity.rb +0 -300
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openhab/dsl/items/metadata'
4
+ require 'openhab/dsl/items/persistence'
5
+
6
+ require_relative 'item_equality'
7
+
8
+ module OpenHAB
9
+ module DSL
10
+ module Items
11
+ java_import org.openhab.core.items.GenericItem
12
+
13
+ # Adds methods to core OpenHAB DimmerItem type to make it more natural in
14
+ # Ruby
15
+ class GenericItem
16
+ include Log
17
+ include ItemEquality
18
+
19
+ prepend Metadata
20
+ prepend Persistence
21
+
22
+ # rubocop:disable Naming/MethodName these mimic Java fields, which are
23
+ # actually methods
24
+ class << self
25
+ # manually define this, since the Java side doesn't
26
+ # @!visibility private
27
+ def ACCEPTED_COMMAND_TYPES
28
+ [org.openhab.core.types.RefreshType.java_class].freeze
29
+ end
30
+
31
+ # manually define this, since the Java side doesn't
32
+ # @!visibility private
33
+ def ACCEPTED_DATA_TYPES
34
+ [org.openhab.core.types.UnDefType.java_class].freeze
35
+ end
36
+ end
37
+ # rubocop:enable Naming/MethodName
38
+
39
+ alias hash hash_code
40
+
41
+ # Get the raw item state.
42
+ #
43
+ # The state of the item, including possibly +NULL+ or +UNDEF+
44
+ #
45
+ # @return [Types::Type]
46
+ #
47
+ alias raw_state state
48
+
49
+ remove_method(:==)
50
+
51
+ #
52
+ # Send a command to this item
53
+ #
54
+ # @param [Types::Type] command to send to object
55
+ #
56
+ #
57
+ def command(command)
58
+ command = format_type_pre(command)
59
+ logger.trace "Sending Command #{command} to #{id}"
60
+ org.openhab.core.model.script.actions.BusEvent.sendCommand(self, command)
61
+ self
62
+ end
63
+ alias << command
64
+
65
+ #
66
+ # Send an update to this item
67
+ #
68
+ # @param [Types::Type] update the item
69
+ #
70
+ #
71
+ def update(update)
72
+ update = format_type_pre(update)
73
+ logger.trace "Sending Update #{update} to #{id}"
74
+ org.openhab.core.model.script.actions.BusEvent.postUpdate(self, update)
75
+ self
76
+ end
77
+
78
+ #
79
+ # Check if the item has a state (not +UNDEF+ or +NULL+)
80
+ #
81
+ # @return [Boolean]
82
+ #
83
+ def state?
84
+ !raw_state.is_a?(Types::UnDefType)
85
+ end
86
+
87
+ #
88
+ # Get the item state
89
+ #
90
+ # @return [Types::Type, nil]
91
+ # OpenHAB item state if state is not +UNDEF+ or +NULL+, nil otherwise
92
+ #
93
+ def state
94
+ raw_state if state?
95
+ end
96
+
97
+ #
98
+ # Get an ID for the item, using the item label if set, otherwise item name
99
+ #
100
+ # @return [String] label if set otherwise name
101
+ #
102
+ def id
103
+ label || name
104
+ end
105
+
106
+ #
107
+ # Get the string representation of the state of the item
108
+ #
109
+ # @return [String] State of the item as a string
110
+ #
111
+ def to_s
112
+ raw_state.to_s # call the super state to include UNDEF/NULL
113
+ end
114
+
115
+ #
116
+ # Inspect the item
117
+ #
118
+ # @return [String] details of the item
119
+ #
120
+ def inspect
121
+ to_string
122
+ end
123
+
124
+ #
125
+ # Return all groups that this item is part of
126
+ #
127
+ # @return [Array<Group>] All groups that this item is part of
128
+ #
129
+ def groups
130
+ group_names.map { |name| Groups.groups[name] }
131
+ end
132
+
133
+ #
134
+ # Check equality without type conversion
135
+ #
136
+ # @return [Boolean] if the same Item is represented, without checking
137
+ # state
138
+ def eql?(other)
139
+ other.instance_of?(self.class) && hash == other.hash
140
+ end
141
+
142
+ # @!method null?
143
+ # Check if the item state == +NULL+
144
+ # @return [Boolean]
145
+
146
+ # @!method undef?
147
+ # Check if the item state == +UNDEF+
148
+ # @return [Boolean]
149
+
150
+ # @!method refresh
151
+ # Send the +REFRESH+ command to the item
152
+ # @return [GenericItem] +self+
153
+
154
+ # formats a {Types::Type} to send to the event bus
155
+ # @!visibility private
156
+ def format_type(command)
157
+ # actual Type types can be sent directly without conversion
158
+ return command if command.is_a?(Types::Type)
159
+
160
+ command.to_s
161
+ end
162
+
163
+ private
164
+
165
+ # convert items to their state before formatting, so that subclasses
166
+ # only have to deal with Types
167
+ def format_type_pre(command)
168
+ command = command.state if command.is_a?(GenericItem)
169
+ format_type(command)
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
@@ -1,81 +1,121 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'delegate'
4
- require 'forwardable'
5
- require 'java'
6
-
7
- require 'openhab/core/entity_lookup'
8
- require 'openhab/dsl/items/item_command'
9
- require 'openhab/dsl/items/item_delegate'
3
+ require_relative 'comparable_item'
10
4
  require 'openhab/dsl/lazy_array'
11
5
 
12
6
  module OpenHAB
13
7
  module DSL
14
8
  module Items
15
- #
16
- # Class for indicating to triggers that a group trigger should be used
17
- #
18
- class GroupMembers
19
- include LazyArray
20
-
21
- attr_reader :group
9
+ java_import org.openhab.core.items.GroupItem
22
10
 
11
+ # Adds methods to core OpenHAB GroupItem type to make it more natural in
12
+ # Ruby
13
+ class GroupItem < GenericItem
23
14
  #
24
- # Create a new GroupMembers instance from a GroupItem
15
+ # Class for indicating to triggers that a group trigger should be used
25
16
  #
26
- # @param [GroupItem] group_item GroupItem to use as trigger
27
- #
28
- def initialize(group_item)
29
- @group = group_item
30
- end
17
+ class GroupMembers
18
+ include LazyArray
31
19
 
32
- # explicit conversion to array
33
- def to_a
34
- OpenHAB::Core::EntityLookup.decorate_items(group.members.to_a)
35
- end
36
- end
20
+ # @return [GroupItem]
21
+ attr_reader :group
37
22
 
38
- #
39
- # Delegator to OpenHAB Group Item
40
- #
41
- class GroupItem
42
- extend OpenHAB::DSL::Items::ItemCommand
43
- extend OpenHAB::DSL::Items::ItemDelegate
44
- include Enumerable
45
- include Comparable
23
+ # @!visibility private
24
+ def initialize(group_item)
25
+ @group = group_item
26
+ end
46
27
 
47
- def_item_delegator :@group_item
28
+ # Explicit conversion to Array
29
+ #
30
+ # @return [Array]
31
+ def to_a
32
+ group.get_members.to_a
33
+ end
48
34
 
49
- #
50
- # @return [Hash] A hash of lambdas with default filters for `all_members`
51
- #
52
- DEFAULT_FILTERS = {
53
- groups: ->(item) { item.is_a?(Java::OrgOpenhabCoreItems::GroupItem) },
54
- all: -> { true }
55
- }.freeze
35
+ # Send a command to each member of the group
36
+ #
37
+ # @return [GroupMembers] +self+
38
+ def command(command)
39
+ each { |item| item << command }
40
+ end
41
+ alias << command
56
42
 
57
- private_constant :DEFAULT_FILTERS
43
+ # @!method refresh
44
+ # Send the +REFRESH+ command to each member of the group
45
+ # @return [GroupMembers] +self+
58
46
 
59
- #
60
- # Create a new GroupItem
61
- #
62
- # @param [Java::Org::openhab::core::items::GroupItem] group_item OpenHAB GroupItem to delegate to
63
- #
64
- def initialize(group_item)
65
- @group_item = group_item
47
+ # @!method on
48
+ # Send the +ON+ command to each member of the group
49
+ # @return [GroupMembers] +self+
50
+
51
+ # @!method off
52
+ # Send the +OFF+ command to each member of the group
53
+ # @return [GroupMembers] +self+
54
+
55
+ # @!method up
56
+ # Send the +UP+ command to each member of the group
57
+ # @return [GroupMembers] +self+
58
+
59
+ # @!method down
60
+ # Send the +DOWN+ command to each member of the group
61
+ # @return [GroupMembers] +self+
62
+
63
+ # @!method stop
64
+ # Send the +STOP+ command to each member of the group
65
+ # @return [GroupMembers] +self+
66
+
67
+ # @!method move
68
+ # Send the +MOVE+ command to each member of the group
69
+ # @return [GroupMembers] +self+
70
+
71
+ # @!method increase
72
+ # Send the +INCREASE+ command to each member of the group
73
+ # @return [GroupMembers] +self+
74
+
75
+ # @!method desrease
76
+ # Send the +DECREASE+ command to each member of the group
77
+ # @return [GroupMembers] +self+
78
+
79
+ # @!method play
80
+ # Send the +PLAY+ command to each member of the group
81
+ # @return [GroupMembers] +self+
82
+
83
+ # @!method pause
84
+ # Send the +PAUSE+ command to each member of the group
85
+ # @return [GroupMembers] +self+
86
+
87
+ # @!method rewind
88
+ # Send the +REWIND+ command to each member of the group
89
+ # @return [GroupMembers] +self+
66
90
 
67
- item_missing_delegate { @group_item }
68
- item_missing_delegate { OpenHAB::Core::EntityLookup.decorate_item(base_item) }
91
+ # @!method fast_forward
92
+ # Send the +FASTFORWARD+ command to each member of the group
93
+ # @return [GroupMembers] +self+
94
+
95
+ # @!method next
96
+ # Send the +NEXT+ command to each member of the group
97
+ # @return [GroupMembers] +self+
98
+
99
+ # @!method previous
100
+ # Send the +PREVIOUS+ command to each member of the group
101
+ # @return [GroupMembers] +self+
69
102
  end
70
103
 
104
+ include Enumerable
105
+ include ComparableItem
106
+
107
+ remove_method :==
108
+
71
109
  #
72
- # Create a GroupMembers object for use in triggers
110
+ # Get an Array-like object representing the members of the group
73
111
  #
74
- # @return [GroupMembers] A GroupMembers object
112
+ # @return [GroupMembers]
75
113
  #
76
114
  def members
77
- GroupMembers.new(@group_item)
115
+ GroupMembers.new(self)
78
116
  end
117
+
118
+ # @deprecated
79
119
  alias items members
80
120
 
81
121
  #
@@ -89,51 +129,43 @@ module OpenHAB
89
129
  # Get all members of the group recursively. Optionally filter the items to only return
90
130
  # Groups or regular Items
91
131
  #
92
- # @param [Symbol] filter Either :groups or :items
132
+ # @param [Symbol] filter Either +:groups+ or +:items+
93
133
  #
94
134
  # @return [Array] An Array containing all descendants of the Group, optionally filtered
95
135
  #
96
136
  def all_members(filter = nil, &block)
97
- predicate = DEFAULT_FILTERS[filter] || block
137
+ filter = nil if filter == :items
138
+ raise ArgumentError, 'filter must be :groups or :items' unless [:groups, nil].include?(filter)
98
139
 
99
- return OpenHAB::Core::EntityLookup.decorate_items(@group_item.all_members.to_a) unless predicate
140
+ block = ->(i) { i.is_a?(GroupItem) } if filter
100
141
 
101
- OpenHAB::Core::EntityLookup.decorate_items(@group_item.get_members(&predicate).to_a)
102
- end
103
-
104
- #
105
- # Test for equality
106
- #
107
- # @param [Object] other Other object to compare against
108
- #
109
- # @return [Boolean] true if self and other can be considered equal, false otherwise
110
- #
111
- def ==(other)
112
- if other.respond_to?(:java_class) && accepted_data_types.include?(other.java_class)
113
- get_state_as(other.class) == other
114
- elsif other.respond_to?(:state)
115
- base_item ? OpenHAB::Core::EntityLookup.decorate_item(base_item) == other.state : self == other.state
142
+ if block
143
+ get_members(&block).to_a
116
144
  else
117
- super
145
+ get_all_members.to_a
118
146
  end
119
147
  end
120
148
 
121
- #
122
- # Compare GroupItem to supplied object
123
- #
124
- # @param [Object] other object to compare to
125
- #
126
- # @return [Integer] -1,0,1 or nil depending on value supplied,
127
- # nil comparison to supplied object is not possible.
128
- #
129
- def <=>(other)
130
- if base_item
131
- OpenHAB::Core::EntityLookup.decorate_item(base_item) <=> other
132
- elsif state?
133
- -(other <=> state)
134
- else
135
- super
136
- end
149
+ # Delegate missing methods to +base_item+ if possible
150
+ def method_missing(method, *args, &block)
151
+ return base_item.__send__(method, *args, &block) if base_item.respond_to?(method)
152
+
153
+ super
154
+ end
155
+
156
+ # @!visibility private
157
+ def respond_to_missing?(method, include_private = false)
158
+ return true if base_item.respond_to?(method)
159
+
160
+ super
161
+ end
162
+
163
+ # give the base item type a chance to format commands
164
+ # @!visibility private
165
+ def format_type(command)
166
+ return super unless base_item
167
+
168
+ base_item.format_type(command)
137
169
  end
138
170
  end
139
171
  end
@@ -3,52 +3,16 @@
3
3
  require 'base64'
4
4
  require 'pathname'
5
5
  require 'net/http'
6
- require 'java'
7
6
  require 'marcel'
8
- require 'openhab/dsl/items/item_command'
9
- require 'openhab/dsl/items/item_delegate'
10
7
 
11
8
  module OpenHAB
12
9
  module DSL
13
10
  module Items
14
- #
15
- # Delegator to OpenHAB Player Item
16
- #
17
- class ImageItem
18
- extend OpenHAB::DSL::Items::ItemCommand
19
- extend OpenHAB::DSL::Items::ItemDelegate
20
-
21
- def_item_delegator :@image_item
22
-
23
- item_type Java::OrgOpenhabCoreLibraryItems::ImageItem
24
-
25
- #
26
- # Creates a new ImageItem
27
- #
28
- # @param [Java::OrgOpenhabCoreLibraryItems::ImageItem] image_item
29
- # The OpenHAB ImageItem to delegate to
30
- #
31
- def initialize(image_item)
32
- logger.trace("Wrapping #{image_item}")
33
- @image_item = image_item
34
-
35
- item_missing_delegate { @image_item }
36
-
37
- super()
38
- end
39
-
40
- #
41
- #
42
- # Update image with base64 encoded OpenHAB compatable image
43
- #
44
- # @param [String] base_64 base_64 encoding of an image
45
- #
46
- #
47
- def update(base_64_encoded_image)
48
- logger.trace { "Updating #{self} with Base64 image #{base_64_encoded_image}" }
49
- @image_item.update base_64_encoded_image
50
- end
11
+ java_import org.openhab.core.library.items.ImageItem
51
12
 
13
+ # Adds methods to core OpenHAB ImageItem type to make it more natural in
14
+ # Ruby
15
+ class ImageItem < GenericItem
52
16
  #
53
17
  # Update image from file
54
18
  #
@@ -87,7 +51,7 @@ module OpenHAB
87
51
  def update_from_bytes(bytes, mime_type: nil)
88
52
  mime_type ||= detect_mime_from_bytes(bytes: bytes)
89
53
  base_64_image = encode_image(mime_type: mime_type, bytes: bytes)
90
- update base_64_image
54
+ update(base_64_image)
91
55
  end
92
56
 
93
57
  #
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ module Items
6
+ # Shared method for checking item equality by delegating to state
7
+ module ItemEquality
8
+ # Check equality, with type conversions
9
+ #
10
+ # @param [GenericItem, Types::Type, Object] other object to
11
+ # compare to
12
+ #
13
+ # If this item is +NULL+ or +UNDEF+, and +other+ is nil, they are
14
+ # considered equal
15
+ #
16
+ # If this item is +NULL+ or +UNDEF+, and other is a {GenericItem}, they
17
+ # are only considered equal if the other item is in the exact same
18
+ # state (i.e. +NULL+ != +UNDEF+)
19
+ #
20
+ # Otherwise, the state of this item is compared with +other+
21
+ #
22
+ # @return [Boolean]
23
+ #
24
+ def ==(other)
25
+ logger.trace("(#{self.class}) #{self} == #{other} (#{other.class})")
26
+ return true if equal?(other) || eql?(other)
27
+ return true if !state? && other.nil?
28
+
29
+ return raw_state == other.raw_state if other.is_a?(GenericItem)
30
+
31
+ state == other
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ require 'openhab/core/entity_lookup'
6
+ require 'openhab/dsl/lazy_array'
7
+
8
+ module OpenHAB
9
+ module DSL
10
+ module Items
11
+ #
12
+ # Provides access to all OpenHAB items, and acts like an array.
13
+ #
14
+ class ItemRegistry
15
+ include LazyArray
16
+ include Singleton
17
+
18
+ # Fetches the named item from the the ItemRegistry
19
+ # @param [String] name
20
+ # @return [GenericItem] Item from registry, nil if item missing or requested item is a Group Type
21
+ def [](name)
22
+ OpenHAB::Core::EntityLookup.lookup_item(name)
23
+ rescue org.openhab.core.items.ItemNotFoundException
24
+ nil
25
+ end
26
+
27
+ # Returns true if the given item name exists
28
+ # @param name [String] Item name to check
29
+ # @return [Boolean] true if the item exists, false otherwise
30
+ def include?(name)
31
+ !$ir.getItems(name).empty? # rubocop: disable Style/GlobalVars
32
+ end
33
+ alias key? include?
34
+
35
+ # Explicit conversion to array
36
+ # @return [Array]
37
+ def to_a
38
+ $ir.items.grep_v(org.openhab.core.items.GroupItem) # rubocop:disable Style/GlobalVars
39
+ end
40
+ end
41
+
42
+ # Fetches all non-group items from the item registry
43
+ # @return [ItemRegistry]
44
+ def items
45
+ ItemRegistry.instance
46
+ end
47
+ end
48
+ end
49
+ end