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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/console/irb.rb +105 -0
  3. data/lib/openhab/console/jline.rb +104 -0
  4. data/lib/openhab/console/registry.rb +12 -0
  5. data/lib/openhab/console/stdio.rb +178 -0
  6. data/lib/openhab/console.rb +5 -0
  7. data/lib/openhab/core/emulate_hash.rb +11 -11
  8. data/lib/openhab/core/entity_lookup.rb +2 -4
  9. data/lib/openhab/core/events/item_state_updated_event.rb +0 -3
  10. data/lib/openhab/core/events/item_time_series_updated_event.rb +0 -3
  11. data/lib/openhab/core/events/startlevel_event.rb +0 -3
  12. data/lib/openhab/core/events/timer_event.rb +0 -3
  13. data/lib/openhab/core/items/generic_item.rb +14 -154
  14. data/lib/openhab/core/items/group_item.rb +2 -2
  15. data/lib/openhab/core/items/image_item.rb +5 -21
  16. data/lib/openhab/core/items/item.rb +161 -7
  17. data/lib/openhab/core/items/persistence.rb +8 -10
  18. data/lib/openhab/core/items/provider.rb +1 -1
  19. data/lib/openhab/core/items/proxy.rb +33 -94
  20. data/lib/openhab/core/items/registry.rb +1 -1
  21. data/lib/openhab/core/items/semantics/enumerable.rb +1 -1
  22. data/lib/openhab/core/items/semantics/provider.rb +1 -5
  23. data/lib/openhab/core/items/semantics/semantic_tag.rb +0 -3
  24. data/lib/openhab/core/items/semantics.rb +105 -141
  25. data/lib/openhab/core/items/switch_item.rb +1 -1
  26. data/lib/openhab/core/items.rb +22 -22
  27. data/lib/openhab/core/lazy_array.rb +4 -4
  28. data/lib/openhab/core/profile_factory.rb +16 -25
  29. data/lib/openhab/core/provider.rb +3 -4
  30. data/lib/openhab/core/proxy.rb +160 -4
  31. data/lib/openhab/core/rules/registry.rb +2 -2
  32. data/lib/openhab/core/rules/rule.rb +4 -8
  33. data/lib/openhab/core/script_handling.rb +2 -2
  34. data/lib/openhab/core/sitemaps/provider.rb +1 -1
  35. data/lib/openhab/core/things/channel.rb +0 -28
  36. data/lib/openhab/core/things/profile_callback.rb +3 -3
  37. data/lib/openhab/core/things/proxy.rb +8 -51
  38. data/lib/openhab/core/things/registry.rb +1 -1
  39. data/lib/openhab/core/things/thing.rb +3 -5
  40. data/lib/openhab/core/types/command_description.rb +31 -0
  41. data/lib/openhab/core/types/date_time_type.rb +5 -10
  42. data/lib/openhab/core/types/decimal_type.rb +1 -1
  43. data/lib/openhab/core/types/hsb_type.rb +3 -5
  44. data/lib/openhab/core/types/point_type.rb +1 -1
  45. data/lib/openhab/core/types/quantity_type.rb +22 -2
  46. data/lib/openhab/core/types/raw_type.rb +10 -4
  47. data/lib/openhab/core/types/state_description.rb +54 -0
  48. data/lib/openhab/core/types/time_series.rb +0 -3
  49. data/lib/openhab/core/types.rb +2 -2
  50. data/lib/openhab/core/value_cache.rb +3 -3
  51. data/lib/openhab/core.rb +3 -5
  52. data/lib/openhab/core_ext/java/duration.rb +27 -8
  53. data/lib/openhab/core_ext/java/list.rb +1 -1
  54. data/lib/openhab/core_ext/java/local_date.rb +6 -2
  55. data/lib/openhab/core_ext/java/local_time.rb +4 -2
  56. data/lib/openhab/core_ext/java/map.rb +2 -2
  57. data/lib/openhab/core_ext/java/period.rb +9 -6
  58. data/lib/openhab/core_ext/java/temporal_amount.rb +5 -0
  59. data/lib/openhab/core_ext/java/zoned_date_time.rb +12 -6
  60. data/lib/openhab/core_ext/ruby/date.rb +8 -7
  61. data/lib/openhab/core_ext/ruby/date_time.rb +2 -2
  62. data/lib/openhab/core_ext/ruby/time.rb +2 -2
  63. data/lib/openhab/core_ext.rb +1 -1
  64. data/lib/openhab/dsl/config_description/builder.rb +1 -1
  65. data/lib/openhab/dsl/items/builder.rb +5 -13
  66. data/lib/openhab/dsl/items/ensure.rb +3 -5
  67. data/lib/openhab/dsl/items/timed_command.rb +4 -4
  68. data/lib/openhab/dsl/rules/automation_rule.rb +3 -3
  69. data/lib/openhab/dsl/rules/builder.rb +40 -52
  70. data/lib/openhab/dsl/rules/rule_triggers.rb +1 -1
  71. data/lib/openhab/dsl/rules/triggers/changed.rb +16 -15
  72. data/lib/openhab/dsl/rules/triggers/channel.rb +1 -1
  73. data/lib/openhab/dsl/rules/triggers/command.rb +2 -2
  74. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +4 -4
  75. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +4 -14
  76. data/lib/openhab/dsl/rules/triggers/updated.rb +6 -6
  77. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +69 -124
  78. data/lib/openhab/dsl/sitemaps/builder.rb +7 -17
  79. data/lib/openhab/dsl/things/builder.rb +8 -8
  80. data/lib/openhab/dsl/timer_manager.rb +2 -2
  81. data/lib/openhab/dsl/version.rb +1 -1
  82. data/lib/openhab/dsl.rb +14 -15
  83. data/lib/openhab/log.rb +3 -3
  84. data/lib/openhab/osgi.rb +1 -1
  85. data/lib/openhab/rspec/helpers.rb +3 -3
  86. data/lib/openhab/rspec/hooks.rb +2 -8
  87. data/lib/openhab/rspec/jruby.rb +1 -1
  88. data/lib/openhab/rspec/karaf.rb +5 -27
  89. data/lib/openhab/rspec/mocks/persistence_service.rb +5 -5
  90. data/lib/openhab/yard/html_helper.rb +1 -1
  91. data/lib/openhab/yard.rb +1 -1
  92. metadata +18 -13
  93. data/lib/openhab/core/items/semantics/tag_class_methods.rb +0 -73
  94. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +0 -118
@@ -13,88 +13,42 @@ module OpenHAB
13
13
  # @!parse include Item
14
14
 
15
15
  # @!visibility private
16
- EVENTS = [Events::ItemAddedEvent::TYPE, Events::ItemUpdatedEvent::TYPE, Events::ItemRemovedEvent::TYPE].freeze
16
+ EVENTS = [Events::ItemAddedEvent::TYPE,
17
+ Events::ItemUpdatedEvent::TYPE,
18
+ Events::ItemRemovedEvent::TYPE].freeze
17
19
  # @!visibility private
18
20
  UID_METHOD = :name
21
+ # @!visibility private
22
+ UID_TYPE = String
19
23
 
20
24
  include Core::Proxy
21
25
 
22
26
  # @return [String]
23
27
  attr_reader :name
24
28
 
25
- #
26
- # Set the proxy item (called by super)
27
- #
28
- def __setobj__(item)
29
- @item = item.is_a?(Item) ? item : nil
30
- @name ||= item.name if item
31
- end
32
-
33
- #
34
- # @return [Item, nil]
35
- #
36
- def __getobj__
37
- @item
38
- end
39
-
40
29
  # @return [Module]
41
30
  def class
42
- return Item if __getobj__.nil?
31
+ target = __getobj__
32
+ return Item if target.nil?
43
33
 
44
- __getobj__.class
34
+ target.class
45
35
  end
46
36
 
47
37
  # @return [true, false]
48
38
  def is_a?(klass)
49
- obj = __getobj__
39
+ target = __getobj__
50
40
  # only claim to be a Delegator if we're backed by an actual item at the moment
51
- klass == Item || obj.is_a?(klass) || klass == Proxy || (!obj.nil? && super)
41
+ klass == Item || target.is_a?(klass) || klass == Proxy || (target.nil? && super)
52
42
  end
53
43
  alias_method :kind_of?, :is_a?
54
44
 
55
- #
56
- # Need to check if `self` _or_ the delegate is an instance of the
57
- # given class
58
- #
59
- # So that {#==} can work
60
- #
61
- # @return [true, false]
62
- #
63
- # @!visibility private
64
- def instance_of?(klass)
65
- __getobj__.instance_of?(klass) || super
66
- end
67
-
68
- #
69
- # Check if delegates are equal for comparison
70
- #
71
- # Otherwise items can't be used in Java maps
72
- #
73
- # @return [true, false]
74
- #
75
- # @!visibility private
76
- def ==(other)
77
- return __getobj__ == other.__getobj__ if other.instance_of?(Proxy)
78
-
79
- super
80
- end
81
-
82
- #
83
- # Non equality comparison
84
- #
85
- # @return [true, false]
86
- #
87
- # @!visibility private
88
- def !=(other)
89
- !(self == other) # rubocop:disable Style/InverseMethods
90
- end
91
-
92
45
  # @return [GroupItem::Members]
93
- # @raise [NoMethodError] if item is not a GroupItem, or a dummy.
46
+ # @raise [NoMethodError] if item is neither a GroupItem, nor a dummy.
94
47
  def members
95
- return GroupItem::Members.new(self) if __getobj__.nil?
48
+ target = __getobj__
49
+ return GroupItem::Members.new(self) if target.nil?
96
50
 
97
- __getobj__.members
51
+ target.members
98
52
  end
99
53
 
100
54
  # Several methods can just return nil when it's a dummy item
@@ -126,45 +80,30 @@ module OpenHAB
126
80
  RUBY
127
81
  end
128
82
 
129
- # @return [String]
130
- def to_s
131
- return name if __getobj__.nil?
132
-
133
- __getobj__.to_s
134
- end
135
-
136
- # @return [String]
137
- def inspect
138
- return super unless __getobj__.nil?
139
-
140
- "#<OpenHAB::Core::Items::Proxy #{name}>"
83
+ # needs to return `true` for dummies for #members, false
84
+ # for non-dummies that aren't actually groups
85
+ def respond_to?(method, include_private = false) # rubocop:disable Style/OptionalBooleanParameter
86
+ target = __getobj__
87
+ if target.nil?
88
+ return true if Item.method_defined?(method)
89
+ elsif method.to_sym == :members
90
+ return target.respond_to?(method)
91
+ end
92
+
93
+ target.respond_to?(method, include_private) || super
141
94
  end
142
95
 
143
- #
144
- # Supports inspect from IRB when we're a dummy item.
145
- #
146
- # @return [void]
147
- # @!visibility private
148
- def pretty_print(printer)
149
- return super unless __getobj__.nil?
96
+ private
150
97
 
151
- printer.text(inspect)
152
- end
153
-
154
- # needs to return `false` if we know we're not a {GroupItem}
155
- def respond_to?(method, *args)
156
- obj = __getobj__
157
- return obj.respond_to?(method, *args) if method.to_sym == :members && !obj.nil?
158
-
159
- super
160
- end
98
+ # ditto
99
+ def target_respond_to?(target, method, include_private)
100
+ if method.to_sym == :members
101
+ return true if target.nil?
161
102
 
162
- # needs to return `false` if we know we're not a {GroupItem}
163
- def respond_to_missing?(method, *args)
164
- obj = __getobj__
165
- return obj.respond_to_missing?(method, *args) if method.to_sym == :members && !obj.nil?
103
+ return target.respond_to?(method, include_private)
104
+ end
166
105
 
167
- super
106
+ target.respond_to?(method, include_private)
168
107
  end
169
108
  end
170
109
  end
@@ -54,7 +54,7 @@ module OpenHAB
54
54
  # @see DSL::Items::Builder DSL::Items::Builder for more details and examples
55
55
  #
56
56
  def build(preferred_provider = nil, update: true, &block)
57
- DSL::Items::BaseBuilderDSL.new(preferred_provider, update: update)
57
+ DSL::Items::BaseBuilderDSL.new(preferred_provider, update:)
58
58
  .instance_eval_with_dummy_items(&block)
59
59
  end
60
60
 
@@ -199,6 +199,6 @@ module Enumerable
199
199
  # @return [self]
200
200
  #
201
201
  def toggle(source: nil)
202
- each { |i| i.toggle(source: source) }
202
+ each { |i| i.toggle(source:) }
203
203
  end
204
204
  end
@@ -8,11 +8,7 @@ module OpenHAB
8
8
  # Provides {SemanticTag SemanticTags} created in Ruby to openHAB
9
9
  #
10
10
  class Provider < Core::Provider
11
- begin
12
- include org.openhab.core.semantics.SemanticTagProvider
13
- rescue NameError
14
- # @deprecated OH3.4
15
- end
11
+ include org.openhab.core.semantics.SemanticTagProvider
16
12
 
17
13
  class << self
18
14
  #
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # @deprecated OH3.4
4
- return unless OpenHAB::Core::Items::Semantics::Provider.registry
5
-
6
3
  module OpenHAB
7
4
  module Core
8
5
  module Items
@@ -61,11 +61,8 @@ module OpenHAB
61
61
  # and {#property_type}. They can even be used with
62
62
  # {DSL::Items::ItemBuilder#tag}.
63
63
  #
64
- # In openHAB 4.0, all of the tag objects implement {SemanticTag}.
64
+ # All of the tag objects implement {SemanticTag}.
65
65
  #
66
- # In openHAB 3.4, the constants in the {Semantics} module are enhanced with {TagClassMethods}
67
- # to provide easy access to the tags' additional attributes: {TagClassMethods#label label},
68
- # {TagClassMethods#synonyms synonyms}, and {TagClassMethods#description description}.
69
66
  # For example, to get the synonyms for `Semantics::Lightbulb` in German:
70
67
  # `Semantics::Lightbulb.synonyms(java.util.Locale::GERMAN)`
71
68
  #
@@ -173,7 +170,7 @@ module OpenHAB
173
170
  # For more information, see {add}
174
171
  #
175
172
  module Semantics
176
- GenericItem.include(self)
173
+ Item.include(self)
177
174
  GroupItem.extend(Forwardable)
178
175
  GroupItem.def_delegators :members, :equipments, :locations
179
176
 
@@ -198,17 +195,7 @@ module OpenHAB
198
195
  # @return [Array<SemanticTag>] an array containing all the Semantic tags
199
196
  #
200
197
  def tags
201
- # @deprecated OH3.4 missing registry
202
- if Provider.registry
203
- Provider.registry.all.to_a
204
- else
205
- java.util.stream.Stream.of(
206
- org.openhab.core.semantics.model.point.Points.stream,
207
- org.openhab.core.semantics.model.property.Properties.stream,
208
- org.openhab.core.semantics.model.equipment.Equipments.stream,
209
- org.openhab.core.semantics.model.location.Locations.stream
210
- ).flat_map(&:itself).map(&:ruby_class).iterator.to_a
211
- end
198
+ Provider.registry.all.to_a
212
199
  end
213
200
 
214
201
  #
@@ -217,35 +204,19 @@ module OpenHAB
217
204
  # @param [String,Symbol] id The tag name, label, or synonym to look up
218
205
  # @param [java.util.Locale] locale The locale of the given label or synonym
219
206
  #
220
- # @return [SemanticTag, Module, nil] The semantic tag class if found, or nil if not found.
221
- # In openHAB 4.0, a SemanticTag instance will be returned. In openHAB 3.4, it will be
222
- # a Module.
207
+ # @return [SemanticTag, nil] The semantic tag class if found, or nil if not found.
223
208
  #
224
209
  def lookup(id, locale = java.util.Locale.default)
225
210
  id = id.to_s
226
211
 
227
- # @deprecated OH3.4 - the Property tag had an ID of "MeasurementProperty" in OH3.4.
228
- # This was corrected in OH4.
229
- id = "MeasurementProperty" if id == "Property" && Core.version < Core::V4_0
230
-
231
- # @deprecated OH3.4 missing registry
232
- if Provider.registry
233
- tag = service.get_by_label_or_synonym(id, locale)
234
- tag = nil if tag&.empty?
235
- tag_class = tag&.first ||
236
- Provider.registry.get_tag_class_by_id(id)
237
- return unless tag_class
238
-
239
- Provider.registry.get(Provider.registry.class.build_id(tag_class))
240
- else
241
- tag = org.openhab.core.semantics.SemanticTags.get_by_label_or_synonym(id, locale).first ||
242
- org.openhab.core.semantics.SemanticTags.get_by_id(id)
243
- return unless tag
244
-
245
- tag = tag.ruby_class
246
- tag.singleton_class.include(TagClassMethods)
247
- tag
248
- end
212
+ # Java21 added #first method, which overrides Ruby's #first.
213
+ # It throws an error if the list is Empty instead of returning nil.
214
+ # So we use #ruby_first to ensure we get Ruby's behaviour
215
+ tag_class = service.get_by_label_or_synonym(id, locale).ruby_first ||
216
+ Provider.registry.get_tag_class_by_id(id)
217
+ return unless tag_class
218
+
219
+ Provider.registry.get(Provider.registry.class.build_id(tag_class))
249
220
  end
250
221
 
251
222
  #
@@ -256,118 +227,111 @@ module OpenHAB
256
227
  logger.trace { "const missing, performing Semantics Lookup for: #{sym}" }
257
228
  lookup(sym)&.tap { |tag| const_set(sym, tag) } || super
258
229
  end
259
- end
260
230
 
261
- # @deprecated OH3.4 cannot add a tag
262
- # this not in the class << self block above because YARD doesn't figure out
263
- # it's a class method with the conditional
264
- if Provider.registry
265
- class << self
266
- #
267
- # Adds custom semantic tags.
268
- #
269
- # @since openHAB 4.0
270
- # @return [Array<SemanticTag>] An array of tags successfully added.
271
- #
272
- # @overload add(**tags)
273
- # Quickly add one or more semantic tags using the default label, empty synonyms and descriptions.
274
- #
275
- # @param [kwargs] **tags Pairs of `tag` => `parent` where tag is either a `Symbol` or a `String`
276
- # for the tag to be added, and parent is either a {SemanticTag}, a `Symbol` or a `String` of an
277
- # existing tag.
278
- # @return [Array<SemanticTag>] An array of tags successfully added.
279
- #
280
- # @example Add one semantic tag `Balcony` whose parent is `Semantics::Outdoor` (Location)
281
- # Semantics.add(Balcony: Semantics::Outdoor)
282
- #
283
- # @example Add multiple semantic tags
284
- # Semantics.add(Balcony: Semantics::Outdoor,
285
- # SecretRoom: Semantics::Room,
286
- # Motion: Semantics::Property)
287
- #
288
- # @overload add(label: nil, synonyms: "", description: "", **tags)
289
- # Add a custom semantic tag with extra details.
290
- #
291
- # @example
292
- # Semantics.add(SecretRoom: Semantics::Room, label: "My Secret Room",
293
- # synonyms: "HidingPlace", description: "A room that requires a special trick to enter")
294
- #
295
- # @param [String,nil] label Optional label. When `nil`, infer the label from the tag name,
296
- # converting `CamelCase` to `Camel Case`
297
- # @param [String,Symbol,Array<String,Symbol>] synonyms Additional synonyms to refer to this tag.
298
- # @param [String] description A longer description of the tag.
299
- # @param [kwargs] **tags Exactly one pair of `tag` => `parent` where tag is either a `Symbol` or a
300
- # `String` for the tag to be added, and parent is either a {SemanticTag}, a `Symbol` or a
301
- # `String` of an existing tag.
302
- # @return [Array<SemanticTag>] An array of tags successfully added.
303
- #
304
- def add(label: nil, synonyms: "", description: "", **tags)
305
- raise ArgumentError, "Tags must be specified" if tags.empty?
306
- if (tags.length > 1) && !(label.nil? && synonyms.empty? && description.empty?)
307
- raise ArgumentError, "Additional options can only be specified when creating one tag"
308
- end
231
+ #
232
+ # Adds custom semantic tags.
233
+ #
234
+ # @since openHAB 4.0
235
+ # @return [Array<SemanticTag>] An array of tags successfully added.
236
+ #
237
+ # @overload add(**tags)
238
+ # Quickly add one or more semantic tags using the default label, empty synonyms and descriptions.
239
+ #
240
+ # @param [kwargs] **tags Pairs of `tag` => `parent` where tag is either a `Symbol` or a `String`
241
+ # for the tag to be added, and parent is either a {SemanticTag}, a `Symbol` or a `String` of an
242
+ # existing tag.
243
+ # @return [Array<SemanticTag>] An array of tags successfully added.
244
+ #
245
+ # @example Add one semantic tag `Balcony` whose parent is `Semantics::Outdoor` (Location)
246
+ # Semantics.add(Balcony: Semantics::Outdoor)
247
+ #
248
+ # @example Add multiple semantic tags
249
+ # Semantics.add(Balcony: Semantics::Outdoor,
250
+ # SecretRoom: Semantics::Room,
251
+ # Motion: Semantics::Property)
252
+ #
253
+ # @overload add(label: nil, synonyms: "", description: "", **tags)
254
+ # Add a custom semantic tag with extra details.
255
+ #
256
+ # @example
257
+ # Semantics.add(SecretRoom: Semantics::Room, label: "My Secret Room",
258
+ # synonyms: "HidingPlace", description: "A room that requires a special trick to enter")
259
+ #
260
+ # @param [String,nil] label Optional label. When `nil`, infer the label from the tag name,
261
+ # converting `CamelCase` to `Camel Case`
262
+ # @param [String,Symbol,Array<String,Symbol>] synonyms Additional synonyms to refer to this tag.
263
+ # @param [String] description A longer description of the tag.
264
+ # @param [kwargs] **tags Exactly one pair of `tag` => `parent` where tag is either a `Symbol` or a
265
+ # `String` for the tag to be added, and parent is either a {SemanticTag}, a `Symbol` or a
266
+ # `String` of an existing tag.
267
+ # @return [Array<SemanticTag>] An array of tags successfully added.
268
+ #
269
+ def add(label: nil, synonyms: "", description: "", **tags)
270
+ raise ArgumentError, "Tags must be specified" if tags.empty?
271
+ if (tags.length > 1) && !(label.nil? && synonyms.empty? && description.empty?)
272
+ raise ArgumentError, "Additional options can only be specified when creating one tag"
273
+ end
309
274
 
310
- synonyms = Array.wrap(synonyms).map { |s| s.to_s.strip }
275
+ synonyms = Array.wrap(synonyms).map { |s| s.to_s.strip }
311
276
 
312
- tags.map do |name, parent|
313
- if (existing_tag = lookup(name))
314
- logger.warn("Tag already exists: #{existing_tag.inspect}")
315
- next
316
- end
277
+ tags.filter_map do |name, parent|
278
+ if (existing_tag = lookup(name))
279
+ logger.warn("Tag already exists: #{existing_tag.inspect}")
280
+ next
281
+ end
317
282
 
318
- unless parent.is_a?(SemanticTag)
319
- parent_tag = lookup(parent)
320
- raise ArgumentError, "Unknown parent: #{parent}" unless parent_tag
283
+ unless parent.is_a?(SemanticTag)
284
+ parent_tag = lookup(parent)
285
+ raise ArgumentError, "Unknown parent: #{parent}" unless parent_tag
321
286
 
322
- parent = parent_tag
323
- end
287
+ parent = parent_tag
288
+ end
324
289
 
325
- new_tag = org.openhab.core.semantics.SemanticTagImpl.new("#{parent.uid}_#{name}",
326
- label,
327
- description,
328
- synonyms)
329
- Provider.instance.add(new_tag)
330
- lookup(name)
331
- end.compact
290
+ new_tag = org.openhab.core.semantics.SemanticTagImpl.new("#{parent.uid}_#{name}",
291
+ label,
292
+ description,
293
+ synonyms)
294
+ Provider.instance.add(new_tag)
295
+ lookup(name)
332
296
  end
297
+ end
333
298
 
334
- #
335
- # Removes custom semantic tags.
336
- #
337
- # @param [SemanticTag, String, Symbol] tags Custom Semantic Tags to remove.
338
- # The built in Semantic Tags cannot be removed.
339
- # @param [true, false] recursive Remove all children of the given tags.
340
- #
341
- # @return [Array<SemanticTag>] An array of tags successfully removed.
342
- # @raise [ArgumentError] if any of the tags have children
343
- # @raise [FrozenError] if any of the tags are not custom tags
344
- #
345
- # @since openHAB 4.0
346
- #
347
- def remove(*tags, recursive: false)
348
- tags.flat_map do |tag|
349
- tag = lookup(tag) unless tag.is_a?(SemanticTag)
350
- next unless tag
351
-
352
- provider = Provider.registry.provider_for(tag)
353
- unless provider.is_a?(ManagedProvider)
354
- raise FrozenError, "Cannot remove item #{tag} from non-managed provider #{provider.inspect}"
355
- end
299
+ #
300
+ # Removes custom semantic tags.
301
+ #
302
+ # @param [SemanticTag, String, Symbol] tags Custom Semantic Tags to remove.
303
+ # The built in Semantic Tags cannot be removed.
304
+ # @param [true, false] recursive Remove all children of the given tags.
305
+ #
306
+ # @return [Array<SemanticTag>] An array of tags successfully removed.
307
+ # @raise [ArgumentError] if any of the tags have children
308
+ # @raise [FrozenError] if any of the tags are not custom tags
309
+ #
310
+ # @since openHAB 4.0
311
+ #
312
+ def remove(*tags, recursive: false)
313
+ tags.flat_map do |tag|
314
+ tag = lookup(tag) unless tag.is_a?(SemanticTag)
315
+ next unless tag
316
+
317
+ provider = Provider.registry.provider_for(tag)
318
+ unless provider.is_a?(ManagedProvider)
319
+ raise FrozenError, "Cannot remove item #{tag} from non-managed provider #{provider.inspect}"
320
+ end
356
321
 
357
- children = []
358
- Provider.registry.providers.grep(ManagedProvider).each do |managed_provider|
359
- managed_provider.all.each do |existing_tag|
360
- next unless existing_tag.parent_uid == tag.uid
361
- raise ArgumentError, "Cannot remove #{tag} because it has children" unless recursive
322
+ children = []
323
+ Provider.registry.providers.grep(ManagedProvider).each do |managed_provider|
324
+ managed_provider.all.each do |existing_tag|
325
+ next unless existing_tag.parent_uid == tag.uid
326
+ raise ArgumentError, "Cannot remove #{tag} because it has children" unless recursive
362
327
 
363
- children += remove(existing_tag, recursive: recursive)
364
- end
328
+ children += remove(existing_tag, recursive:)
365
329
  end
330
+ end
366
331
 
367
- remove_const(tag.name) if provider.remove(tag.uid) && const_defined?(tag.name)
368
- [tag] + children
369
- end.compact
370
- end
332
+ remove_const(tag.name) if provider.remove(tag.uid) && const_defined?(tag.name)
333
+ [tag] + children
334
+ end.compact
371
335
  end
372
336
  end
373
337
 
@@ -50,7 +50,7 @@ module OpenHAB
50
50
  # @return [self]
51
51
  #
52
52
  def toggle(source: nil)
53
- command!(!on?, source: source)
53
+ command!(!on?, source:)
54
54
  end
55
55
 
56
56
  # @!method on?
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "types"
4
4
 
5
- Dir[File.expand_path("items/*.rb", __dir__)].sort.each do |f|
5
+ Dir[File.expand_path("items/*.rb", __dir__)].each do |f|
6
6
  require f
7
7
  end
8
8
 
@@ -64,35 +64,35 @@ module OpenHAB
64
64
  logger.trace { "Defining #{klass}/Enumerable##{command}/#{command}! for #{value}" }
65
65
 
66
66
  klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
67
- ruby2_keywords def #{command}(*args, &block) # ruby2_keywords def on(*args, &block)
68
- command(#{value}, *args, &block) # command(ON, *args, &block)
69
- end # end
70
- #
71
- ruby2_keywords def #{command}!(*args, &block) # ruby2_keywords def on!(*args, &block)
72
- command!(#{value}, *args, &block) # command!(ON, *args, &block)
73
- end # end
67
+ def #{command}(...) # def on(...)
68
+ command(#{value}, ...) # command(ON, ...)
69
+ end # end
70
+ #
71
+ def #{command}!(...) # def on!(...)
72
+ command!(#{value}, ...) # command!(ON, ...)
73
+ end # end
74
74
  RUBY
75
75
 
76
76
  Enumerable.class_eval <<~RUBY, __FILE__, __LINE__ + 1
77
- ruby2_keywords def #{command}(*args, &block) # ruby2_keywords def on(*args, &block)
78
- each do |member| # each do |member|
79
- member.#{command}(*args, &block) # member.on(*args, &block)
80
- end # end
81
- end # end
82
- #
83
- ruby2_keywords def #{command}!(*args, &block) # ruby2_keywords def on!(*args, &block)
84
- each do |member| # each do |member|
85
- member.#{command}!(*args, &block) # member.on!(*args, &block)
86
- end # end
87
- end # end
77
+ def #{command}(...) # def on(...)
78
+ each do |member| # each do |member|
79
+ member.#{command}(...) # member.on(...)
80
+ end # end
81
+ end # end
82
+ #
83
+ def #{command}!(...) # def on!(...)
84
+ each do |member| # each do |member|
85
+ member.#{command}!(...) # member.on!(...)
86
+ end # end
87
+ end # end
88
88
  RUBY
89
89
  else
90
90
  logger.trace { "Defining #{klass}/Enumerable##{command} for #{value}" }
91
91
 
92
92
  klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
93
- ruby2_keywords def #{command}(*args, &block) # ruby2_keywords def refresh(*args, &block)
94
- command!(#{value}, *args, &block) # command!(REFRESH, *args, &block)
95
- end # end
93
+ def #{command}(...) # def refresh(...)
94
+ command!(#{value}, ...) # command!(REFRESH, ...)
95
+ end # end
96
96
  RUBY
97
97
 
98
98
  Enumerable.class_eval <<~RUBY, __FILE__, __LINE__ + 1
@@ -21,8 +21,8 @@ module OpenHAB
21
21
  # parameter. Returns self.
22
22
  #
23
23
  # If no block is given, an Enumerator is returned.
24
- def each(&block)
25
- to_a.each(&block)
24
+ def each(&)
25
+ to_a.each(&)
26
26
  self
27
27
  end
28
28
 
@@ -35,8 +35,8 @@ module OpenHAB
35
35
  end
36
36
 
37
37
  # Delegate any other methods to the actual array, exclude mutating methods
38
- def method_missing(method, *args, &block)
39
- return to_a.send(method, *args, &block) if method[-1] != "!" && Array.instance_methods.include?(method)
38
+ def method_missing(method, ...)
39
+ return to_a.send(method, ...) if method[-1] != "!" && Array.instance_methods.include?(method)
40
40
 
41
41
  super
42
42
  end