openhab-scripting 5.8.0 → 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00dfdfae614d0fc89c09ddfe86b16c4d0b41e94bc1c2e73889eb359ff09ada3c
4
- data.tar.gz: ecafc5d2f33cf0b0015ac9e8c59449a57488e4f18316bd584e8dfe028d5ec4c7
3
+ metadata.gz: 6f531c0d4e77bbee531e574b759f56e458d4eacde89520b8cf9f810dd46e61d9
4
+ data.tar.gz: 7724b5709c56fb80f095c14930fd3077a2019111731865f1956f4b080a8039ab
5
5
  SHA512:
6
- metadata.gz: eff4e5471afb074c92cd7d3fc01d9070a80db680ed79c4814dc8b88e14eb67c8f9215a77f80c6b1a9a5eb6f4e220b6ce5e38ba01f0287779821db918f81c0fef
7
- data.tar.gz: f187e831d86e87fe4a2e91b311f8bdd3c4e046e9107054ff74c91cdf7644d4fa303d86d8abf3c5f80e8e8cb1762f5c436b89e3e841a86ef05af351c6f0d6abbb
6
+ metadata.gz: 11237012154342229a7b1a4b24a2e5e8f81833d758e81614b067c4a1187a598e5fbc45cfd300312ef0f039130a039e6df7c75f59e08e458d0bdf7761e2a85f8d
7
+ data.tar.gz: 3bd394f5d950d2ab5a0016a4219d7d1ac0cb9f4fbdca541d4f41c9e59406c01a1d0df242334cc95a4cf1668f546e1f0fc7aa03cd835f71384e4a3de4cace8304
@@ -32,9 +32,14 @@ module OpenHAB
32
32
  def inspect
33
33
  r = "#<OpenHAB::Core::Things::Channel #{uid}"
34
34
  r += " #{label.inspect}" if label
35
- r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
35
+ r += " description=#{description.inspect}" if description
36
+ r += " kind=#{kind.inspect}"
37
+ r += " channel_type_uid=#{channel_type_uid.inspect}" if channel_type_uid
36
38
  r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
37
39
  r += " properties=#{properties.to_h}" unless properties.empty?
40
+ r += " default_tags=#{default_tags.to_a}" unless default_tags.empty?
41
+ r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
42
+ r += " accepted_item_type=#{accepted_item_type}" if accepted_item_type
38
43
  "#{r}>"
39
44
  end
40
45
 
@@ -42,6 +47,34 @@ module OpenHAB
42
47
  def to_s
43
48
  uid.to_s
44
49
  end
50
+
51
+ # @deprecated OH3.4 this whole section is not needed in OH4+. Also see Thing#config_eql?
52
+ if Gem::Version.new(Core::VERSION) < Gem::Version.new("4.0.0")
53
+ # @!visibility private
54
+ module ChannelComparable
55
+ # @!visibility private
56
+ # This is only needed in OH3 because it is implemented in OH4 core
57
+ def ==(other)
58
+ return true if equal?(other)
59
+ return false unless other.is_a?(Channel)
60
+
61
+ %i[class
62
+ uid
63
+ label
64
+ description
65
+ kind
66
+ channel_type_uid
67
+ configuration
68
+ properties
69
+ default_tags
70
+ auto_update_policy
71
+ accepted_item_type].all? do |attr|
72
+ send(attr) == other.send(attr)
73
+ end
74
+ end
75
+ end
76
+ org.openhab.core.thing.binding.builder.ChannelBuilder.const_get(:ChannelImpl).prepend(ChannelComparable)
77
+ end
45
78
  end
46
79
  end
47
80
  end
@@ -29,7 +29,7 @@ module OpenHAB
29
29
  #
30
30
  # @return [Array] channels
31
31
  def channels
32
- Thing::ChannelsArray.new(super.to_a)
32
+ Thing::ChannelsArray.new(self, super.to_a)
33
33
  end
34
34
 
35
35
  #
@@ -64,13 +64,17 @@ module OpenHAB
64
64
  # Array wrapper class to allow searching a list of channels
65
65
  # by channel id
66
66
  class ChannelsArray < Array
67
+ def initialize(thing, array)
68
+ super(array)
69
+ @thing = thing
70
+ end
71
+
67
72
  # Allows indexing by both integer as an array or channel id acting like a hash.
68
- # @param [Integer, String] index Numeric index or string channel id to search for.
73
+ # @param [Integer, String, ChannelUID] index
74
+ # Numeric index, string channel id, or a {ChannelUID} to search for.
69
75
  def [](index)
70
- if index.respond_to?(:to_str)
71
- key = index.to_str
72
- return find { |channel| channel.uid.id == key }
73
- end
76
+ return @thing.get_channel(index) if index.is_a?(ChannelUID)
77
+ return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)
74
78
 
75
79
  super
76
80
  end
@@ -204,7 +208,9 @@ module OpenHAB
204
208
  # @return [true,false] true if all attributes are equal, false otherwise
205
209
  #
206
210
  def config_eql?(other)
207
- %i[uid label channels bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
211
+ # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
212
+ channels.to_a == other.channels.to_a &&
213
+ %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
208
214
  end
209
215
 
210
216
  #
@@ -257,7 +257,14 @@ module OpenHAB
257
257
  # The ChannelBuilder DSL allows you to customize a channel
258
258
  class ChannelBuilder
259
259
  attr_accessor :label
260
- attr_reader :uid, :config, :type
260
+ attr_reader :uid,
261
+ :config,
262
+ :type,
263
+ :default_tags,
264
+ :properties,
265
+ :description,
266
+ :auto_update_policy,
267
+ :accepted_item_type
261
268
 
262
269
  #
263
270
  # Constructor for ChannelBuilder
@@ -269,10 +276,27 @@ module OpenHAB
269
276
  # @param [String] label The channel label.
270
277
  # @param [thing] thing The thing associated with this channel.
271
278
  # This parameter is not needed for the {ThingBuilder#channel} method.
279
+ # @param [String] description The channel description.
272
280
  # @param [String] group The group name.
273
281
  # @param [Hash] config Channel configuration. The keys can be strings or symbols.
282
+ # @param [Hash] properties The channel properties.
283
+ # @param [String,Symbol,Semantics::Tag,Array<String,Symbol,Semantics::Tag>] default_tags
284
+ # The default tags for this channel.
285
+ # @param [:default, :recommend, :veto, org.openhab.core.thing.type.AutoUpdatePolicy] auto_update_policy
286
+ # The channel's auto update policy.
287
+ # @param [String] accepted_item_type The accepted item type.
274
288
  #
275
- def initialize(uid, type, label = nil, thing:, group: nil, config: {})
289
+ def initialize(uid,
290
+ type,
291
+ label = nil,
292
+ thing:,
293
+ description: nil,
294
+ group: nil,
295
+ config: nil,
296
+ properties: nil,
297
+ default_tags: nil,
298
+ auto_update_policy: nil,
299
+ accepted_item_type: nil)
276
300
  @thing = thing
277
301
 
278
302
  uid = uid.to_s
@@ -292,7 +316,14 @@ module OpenHAB
292
316
  end
293
317
  @type = type
294
318
  @label = label
295
- @config = config.transform_keys(&:to_s)
319
+ @config = config&.transform_keys(&:to_s)
320
+ @default_tags = Items::ItemBuilder.normalize_tags(*Array.wrap(default_tags))
321
+ @properties = properties&.transform_keys(&:to_s)
322
+ @description = description
323
+ @accepted_item_type = accepted_item_type
324
+ return unless auto_update_policy
325
+
326
+ @auto_update_policy = org.openhab.core.thing.type.AutoUpdatePolicy.value_of(auto_update_policy.to_s.upcase)
296
327
  end
297
328
 
298
329
  # @!visibility private
@@ -300,7 +331,15 @@ module OpenHAB
300
331
  org.openhab.core.thing.binding.builder.ChannelBuilder.create(uid)
301
332
  .with_kind(kind)
302
333
  .with_type(type)
303
- .with_configuration(Core::Configuration.new(config))
334
+ .tap do |builder|
335
+ builder.with_label(label) if label
336
+ builder.with_configuration(Core::Configuration.new(config)) if config && !config.empty?
337
+ builder.with_default_tags(Set.new(default_tags).to_java) unless default_tags.empty?
338
+ builder.with_properties(properties) if properties
339
+ builder.with_description(description) if description
340
+ builder.with_auto_update_policy(auto_update_policy) if auto_update_policy
341
+ builder.with_accepted_item_type(accepted_item_type) if accepted_item_type
342
+ end
304
343
  .build
305
344
  end
306
345
 
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.8.0"
7
+ VERSION = "5.9.0"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.8.0
4
+ version: 5.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-10-07 00:00:00.000000000 Z
13
+ date: 2023-10-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler