openhab-scripting 5.12.0 → 5.12.1

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: 35d0d28ba4dd272f12cd989761c2d615836d25dbafbc2af2b60692f8a535d5c1
4
- data.tar.gz: 4d51dd07a43f5ff7a7ad43bc66cbb1d63b320486a82036d1a8cbfb22412a061b
3
+ metadata.gz: 0d3cc7138b6a4b42066a80ec926d31c2b6f1dc9538ae4498d1b6014be8d8aa1d
4
+ data.tar.gz: eae0f6ddcde8c3a2b8b6b747554e73dc3b86b63f599f9afe2e50676e4cc8c4f8
5
5
  SHA512:
6
- metadata.gz: 76c075f22df43c0ecfe37775e297f496d2f55fe60e6da95bbece311d92fe3e37e50d867a23f6f52c3ebeb690771e7eb5512c357ca3b0745d83d03a8df892cad7
7
- data.tar.gz: 93eb532732729b91437a669fbbe9b0b024397332faa435c82ebe17d50c4ea4a29576108c819010c0a497a5912d74eaa95e87fc0d98b01f9fa0987fbb52b5fa7b
6
+ metadata.gz: 5fb2a8142e739424fabd68595923588066edc753f62467c6cd1e4b3ab38b9d2b1717d7d24dbfcd96533000fa1adcef1e8470790167d7b5f031dc24ce34c25f82
7
+ data.tar.gz: 5ea1f6bd0c4926ae9126f388af80c2d69bd643f14495226cad3388150b971080705bea645e52b76308a7c96a48026c5be02ae6ba6408973eba73d22b6bee3626
@@ -46,6 +46,7 @@ module OpenHAB
46
46
  @block = block
47
47
  @subdirs = subdirs
48
48
  @path = Pathname.new(path)
49
+ @custom_watcher = nil
49
50
  return if path.to_s.start_with?(OpenHAB::Core.config_folder.to_s)
50
51
 
51
52
  @custom_watcher = "jrubyscripting-#{SecureRandom.uuid}"
@@ -32,6 +32,36 @@ module OpenHAB
32
32
  # end
33
33
  # end
34
34
  #
35
+ # @example Create a Thing within a Bridge
36
+ # things.build do
37
+ # bridge "mqtt:broker:mosquitto", config: { host: "127.0.0.1", enableDiscovery: false } do
38
+ # thing "mqtt:topic:window1", "My Window Sensor" do
39
+ # channel "contact1", "contact", config: {
40
+ # stateTopic: "zigbee2mqtt/window1/contact",
41
+ # on: "false",
42
+ # off: "true"
43
+ # }
44
+ # end
45
+ # end
46
+ # end
47
+ #
48
+ # items.build do
49
+ # contact_item Window1_Contact, channel: "mqtt:topic:window1:contact1"
50
+ # end
51
+ #
52
+ # @example Create a Thing separately from the Bridge
53
+ # things.build do
54
+ # bridge = bridge "mqtt:broker:mosquitto", config: { host: "127.0.0.1", enableDiscovery: false }
55
+ #
56
+ # thing "mqtt:topic:window1", "My Window Sensor", bridge: bridge do
57
+ # channel "contact1", "contact", config: {
58
+ # stateTopic: "zigbee2mqtt/window1/contact",
59
+ # on: "false",
60
+ # off: "true"
61
+ # }
62
+ # end
63
+ # end
64
+ #
35
65
  # @see ThingBuilder#initialize ThingBuilder#initialize for #thing's parameters
36
66
  # @see ChannelBuilder#initialize ChannelBuilder#initialize for #channel's parameters
37
67
  # @see Items::Builder
@@ -61,6 +91,7 @@ module OpenHAB
61
91
 
62
92
  def build(klass, *args, **kwargs, &block)
63
93
  builder = klass.new(*args, **kwargs)
94
+ builder.parent_builder = self if builder.respond_to?(:parent_builder=)
64
95
  builder.instance_eval(&block) if block
65
96
  thing = builder.build
66
97
 
@@ -190,6 +221,7 @@ module OpenHAB
190
221
  @location = location.label if location.is_a?(Item)
191
222
  @config = config.transform_keys(&:to_s)
192
223
  @enabled = enabled
224
+ @builder = org.openhab.core.thing.binding.builder.ThingBuilder unless instance_variable_defined?(:@builder)
193
225
  end
194
226
 
195
227
  # Add an explicitly configured channel to this item
@@ -222,13 +254,12 @@ module OpenHAB
222
254
  @channels = merged_channels.values
223
255
  end
224
256
 
225
- builder = org.openhab.core.thing.binding.builder.ThingBuilder
226
- .create(thing_type_uid, uid)
227
- .with_label(label)
228
- .with_location(location)
229
- .with_configuration(configuration)
230
- .with_bridge(bridge_uid)
231
- .with_channels(channels)
257
+ builder = @builder.create(thing_type_uid, uid)
258
+ .with_label(label)
259
+ .with_location(location)
260
+ .with_configuration(configuration)
261
+ .with_bridge(bridge_uid)
262
+ .with_channels(channels)
232
263
 
233
264
  builder.with_properties(thing_type.properties) if thing_type
234
265
 
@@ -244,16 +275,26 @@ module OpenHAB
244
275
 
245
276
  # The BridgeBuilder DSL allows you to customize a thing
246
277
  class BridgeBuilder < ThingBuilder
278
+ # @!visibility private
279
+ attr_accessor :parent_builder
280
+
281
+ # Constructor for BridgeBuilder
282
+ # @see ThingBuilder#initialize
283
+ def initialize(uid, label = nil, binding: nil, type: nil, bridge: nil, location: nil, config: {}, enabled: nil)
284
+ @builder = org.openhab.core.thing.binding.builder.BridgeBuilder
285
+ super
286
+ end
287
+
247
288
  # Create a new Bridge with this Bridge as its Bridge
248
289
  # @see BridgeBuilder#initialize
249
290
  def bridge(*args, **kwargs, &block)
250
- super(*args, bridge: self, **kwargs, &block)
291
+ parent_builder.bridge(*args, bridge: self, **kwargs, &block)
251
292
  end
252
293
 
253
294
  # Create a new Thing with this Bridge as its Bridge
254
295
  # @see ThingBuilder#initialize
255
296
  def thing(*args, **kwargs, &block)
256
- super(*args, bridge: self, **kwargs, &block)
297
+ parent_builder.thing(*args, bridge: self, **kwargs, &block)
257
298
  end
258
299
  end
259
300
 
@@ -283,7 +324,7 @@ module OpenHAB
283
324
  # @param [String] uid The channel's ID.
284
325
  # @param [String, ChannelTypeUID, :trigger] type The concrete type of the channel.
285
326
  # @param [String] label The channel label.
286
- # @param [thing] thing The thing associated with this channel.
327
+ # @param [Thing] thing The thing associated with this channel.
287
328
  # This parameter is not needed for the {ThingBuilder#channel} method.
288
329
  # @param [String] description The channel description.
289
330
  # @param [String] group The group name.
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.12.0"
7
+ VERSION = "5.12.1"
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.12.0
4
+ version: 5.12.1
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-12-19 00:00:00.000000000 Z
13
+ date: 2023-12-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler