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.
- checksums.yaml +4 -4
- data/lib/openhab/console/irb.rb +105 -0
- data/lib/openhab/console/jline.rb +104 -0
- data/lib/openhab/console/registry.rb +12 -0
- data/lib/openhab/console/stdio.rb +178 -0
- data/lib/openhab/console.rb +5 -0
- data/lib/openhab/core/emulate_hash.rb +11 -11
- data/lib/openhab/core/entity_lookup.rb +2 -4
- data/lib/openhab/core/events/item_state_updated_event.rb +0 -3
- data/lib/openhab/core/events/item_time_series_updated_event.rb +0 -3
- data/lib/openhab/core/events/startlevel_event.rb +0 -3
- data/lib/openhab/core/events/timer_event.rb +0 -3
- data/lib/openhab/core/items/generic_item.rb +14 -154
- data/lib/openhab/core/items/group_item.rb +2 -2
- data/lib/openhab/core/items/image_item.rb +5 -21
- data/lib/openhab/core/items/item.rb +161 -7
- data/lib/openhab/core/items/persistence.rb +8 -10
- data/lib/openhab/core/items/provider.rb +1 -1
- data/lib/openhab/core/items/proxy.rb +33 -94
- data/lib/openhab/core/items/registry.rb +1 -1
- data/lib/openhab/core/items/semantics/enumerable.rb +1 -1
- data/lib/openhab/core/items/semantics/provider.rb +1 -5
- data/lib/openhab/core/items/semantics/semantic_tag.rb +0 -3
- data/lib/openhab/core/items/semantics.rb +105 -141
- data/lib/openhab/core/items/switch_item.rb +1 -1
- data/lib/openhab/core/items.rb +22 -22
- data/lib/openhab/core/lazy_array.rb +4 -4
- data/lib/openhab/core/profile_factory.rb +16 -25
- data/lib/openhab/core/provider.rb +3 -4
- data/lib/openhab/core/proxy.rb +160 -4
- data/lib/openhab/core/rules/registry.rb +2 -2
- data/lib/openhab/core/rules/rule.rb +4 -8
- data/lib/openhab/core/script_handling.rb +2 -2
- data/lib/openhab/core/sitemaps/provider.rb +1 -1
- data/lib/openhab/core/things/channel.rb +0 -28
- data/lib/openhab/core/things/profile_callback.rb +3 -3
- data/lib/openhab/core/things/proxy.rb +8 -51
- data/lib/openhab/core/things/registry.rb +1 -1
- data/lib/openhab/core/things/thing.rb +3 -5
- data/lib/openhab/core/types/command_description.rb +31 -0
- data/lib/openhab/core/types/date_time_type.rb +5 -10
- data/lib/openhab/core/types/decimal_type.rb +1 -1
- data/lib/openhab/core/types/hsb_type.rb +3 -5
- data/lib/openhab/core/types/point_type.rb +1 -1
- data/lib/openhab/core/types/quantity_type.rb +22 -2
- data/lib/openhab/core/types/raw_type.rb +10 -4
- data/lib/openhab/core/types/state_description.rb +54 -0
- data/lib/openhab/core/types/time_series.rb +0 -3
- data/lib/openhab/core/types.rb +2 -2
- data/lib/openhab/core/value_cache.rb +3 -3
- data/lib/openhab/core.rb +3 -5
- data/lib/openhab/core_ext/java/duration.rb +27 -8
- data/lib/openhab/core_ext/java/list.rb +1 -1
- data/lib/openhab/core_ext/java/local_date.rb +6 -2
- data/lib/openhab/core_ext/java/local_time.rb +4 -2
- data/lib/openhab/core_ext/java/map.rb +2 -2
- data/lib/openhab/core_ext/java/period.rb +9 -6
- data/lib/openhab/core_ext/java/temporal_amount.rb +5 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +12 -6
- data/lib/openhab/core_ext/ruby/date.rb +8 -7
- data/lib/openhab/core_ext/ruby/date_time.rb +2 -2
- data/lib/openhab/core_ext/ruby/time.rb +2 -2
- data/lib/openhab/core_ext.rb +1 -1
- data/lib/openhab/dsl/config_description/builder.rb +1 -1
- data/lib/openhab/dsl/items/builder.rb +5 -13
- data/lib/openhab/dsl/items/ensure.rb +3 -5
- data/lib/openhab/dsl/items/timed_command.rb +4 -4
- data/lib/openhab/dsl/rules/automation_rule.rb +3 -3
- data/lib/openhab/dsl/rules/builder.rb +40 -52
- data/lib/openhab/dsl/rules/rule_triggers.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/changed.rb +16 -15
- data/lib/openhab/dsl/rules/triggers/channel.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/command.rb +2 -2
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +4 -4
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +4 -14
- data/lib/openhab/dsl/rules/triggers/updated.rb +6 -6
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +69 -124
- data/lib/openhab/dsl/sitemaps/builder.rb +7 -17
- data/lib/openhab/dsl/things/builder.rb +8 -8
- data/lib/openhab/dsl/timer_manager.rb +2 -2
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +14 -15
- data/lib/openhab/log.rb +3 -3
- data/lib/openhab/osgi.rb +1 -1
- data/lib/openhab/rspec/helpers.rb +3 -3
- data/lib/openhab/rspec/hooks.rb +2 -8
- data/lib/openhab/rspec/jruby.rb +1 -1
- data/lib/openhab/rspec/karaf.rb +5 -27
- data/lib/openhab/rspec/mocks/persistence_service.rb +5 -5
- data/lib/openhab/yard/html_helper.rb +1 -1
- data/lib/openhab/yard.rb +1 -1
- metadata +18 -13
- data/lib/openhab/core/items/semantics/tag_class_methods.rb +0 -73
- 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,
|
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
|
-
|
31
|
+
target = __getobj__
|
32
|
+
return Item if target.nil?
|
43
33
|
|
44
|
-
|
34
|
+
target.class
|
45
35
|
end
|
46
36
|
|
47
37
|
# @return [true, false]
|
48
38
|
def is_a?(klass)
|
49
|
-
|
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 ||
|
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
|
46
|
+
# @raise [NoMethodError] if item is neither a GroupItem, nor a dummy.
|
94
47
|
def members
|
95
|
-
|
48
|
+
target = __getobj__
|
49
|
+
return GroupItem::Members.new(self) if target.nil?
|
96
50
|
|
97
|
-
|
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
|
-
#
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
163
|
-
|
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
|
-
|
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:
|
57
|
+
DSL::Items::BaseBuilderDSL.new(preferred_provider, update:)
|
58
58
|
.instance_eval_with_dummy_items(&block)
|
59
59
|
end
|
60
60
|
|
@@ -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
|
-
|
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
|
#
|
@@ -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
|
-
#
|
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
|
-
|
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
|
-
|
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,
|
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
|
-
#
|
228
|
-
#
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
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
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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
|
-
|
275
|
+
synonyms = Array.wrap(synonyms).map { |s| s.to_s.strip }
|
311
276
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
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
|
-
|
319
|
-
|
320
|
-
|
283
|
+
unless parent.is_a?(SemanticTag)
|
284
|
+
parent_tag = lookup(parent)
|
285
|
+
raise ArgumentError, "Unknown parent: #{parent}" unless parent_tag
|
321
286
|
|
322
|
-
|
323
|
-
|
287
|
+
parent = parent_tag
|
288
|
+
end
|
324
289
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
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
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
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
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
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
|
-
|
364
|
-
end
|
328
|
+
children += remove(existing_tag, recursive:)
|
365
329
|
end
|
330
|
+
end
|
366
331
|
|
367
|
-
|
368
|
-
|
369
|
-
|
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
|
|
data/lib/openhab/core/items.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "types"
|
4
4
|
|
5
|
-
Dir[File.expand_path("items/*.rb", __dir__)].
|
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
|
-
|
68
|
-
command(#{value},
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
command!(#{value},
|
73
|
-
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
|
-
|
78
|
-
each do |member|
|
79
|
-
member.#{command}(
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
each do |member|
|
85
|
-
member.#{command}!(
|
86
|
-
end
|
87
|
-
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
|
-
|
94
|
-
command!(#{value},
|
95
|
-
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(&
|
25
|
-
to_a.each(&
|
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,
|
39
|
-
return to_a.send(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
|