openhab-scripting 5.14.0 → 5.15.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: 29d5852ff9f0b047b5e70f69d8ece471770b59a86f4989a3120a7c6027fec1b9
4
- data.tar.gz: 39c590e109e6c5349fd6b4b5eee9bf2e5a3058f4b8cf875b6b69f02bb89996df
3
+ metadata.gz: 11409728d3f0ecb384da9099355fea4728020aa1de1d494d3085dddea518e16c
4
+ data.tar.gz: d4daa321f0b779b0c9f47ccc405cdafd3a71f55666e173cb29315a7f948b2029
5
5
  SHA512:
6
- metadata.gz: 41707220dfe28a3a7395b4d0b7c8538e8150448934d97f63d5b96a533f859f681b47d68bb83688cfa316737b34622f90c7da670915a454427a9c4c705d9cfa9e
7
- data.tar.gz: 9c8ae71904b136e9aa2e11027e0de57101721b7096352994a2d636595f69b32a07e0992bf476a0200e0e6de5330a6a70d6e6f363f2e1f4c687ff1b033f013710
6
+ metadata.gz: b8eee772f02cf086af4db419ecaa5752b21393302533f6fea628a6e9bc50d7e986b1815e03c71de7acba63a13088f46d3e73e96d416a1869a7e2b9fe627764ea
7
+ data.tar.gz: 4ebdb8fb5d81c4429188163e4ced5aabf2ee8a33797b540a32e0e81024a67ac7143728b7679181ca26a4856f8e7e6ed291b5f4bb9427c1df2a744eb6fcb75dd1
@@ -193,4 +193,12 @@ module Enumerable
193
193
  def ensure
194
194
  OpenHAB::DSL::Items::Ensure::ItemDelegate.new(self)
195
195
  end
196
+
197
+ #
198
+ # Send a toggle command to every item in the collection
199
+ # @return [self]
200
+ #
201
+ def toggle
202
+ each(&:toggle)
203
+ end
196
204
  end
@@ -112,8 +112,30 @@ module OpenHAB
112
112
  # end
113
113
  # end
114
114
  #
115
+ # @example
116
+ # def add_tv(builder, tv)
117
+ # builder.frame label: tv.location.label do
118
+ # builder.switch item: tv.points(Semantics::Switch), label: "Power"
119
+ # end
120
+ # end
121
+ #
122
+ # sitemaps.build do |builder|
123
+ # builder.sitemap "tvs", label: "TVs" do
124
+ # items.equipments(Semantics::TV).each do |tv|
125
+ # add_tv(builder, tv)
126
+ # end
127
+ # end
128
+ # end
129
+ #
115
130
  def build(update: true, &block)
116
- DSL::Sitemaps::Builder.new(self, update: update).instance_eval(&block)
131
+ builder_proxy = SimpleDelegator.new(nil) if block.arity == 1
132
+ builder = DSL::Sitemaps::Builder.new(self, builder_proxy, update: update)
133
+ if block.arity == 1
134
+ builder_proxy.__setobj__(builder)
135
+ yield builder_proxy
136
+ else
137
+ builder.instance_eval(&block)
138
+ end
117
139
  end
118
140
 
119
141
  # For use in specs
@@ -12,8 +12,9 @@ module OpenHAB
12
12
  # Base sitemap builder DSL
13
13
  class Builder
14
14
  # @!visibility private
15
- def initialize(provider, update:)
15
+ def initialize(provider, builder_proxy, update:)
16
16
  @provider = provider
17
+ @builder_proxy = builder_proxy
17
18
  @update = update
18
19
  end
19
20
 
@@ -23,8 +24,7 @@ module OpenHAB
23
24
  # @return [SitemapBuilder]
24
25
  # @!visibility public
25
26
  def sitemap(name, label: nil, icon: nil, &block)
26
- sitemap = SitemapBuilder.new(name, label: label, icon: icon)
27
- sitemap.instance_eval_with_dummy_items(&block) if block
27
+ sitemap = SitemapBuilder.new(name, @builder_proxy, label: label, icon: icon, &block)
28
28
  sitemap = sitemap.build
29
29
  if @update && @provider.get(sitemap.uid)
30
30
  @provider.update(sitemap)
@@ -106,6 +106,7 @@ module OpenHAB
106
106
  # One or more visibility rules (see {#visibility})
107
107
  # @!visibility private
108
108
  def initialize(type,
109
+ builder_proxy,
109
110
  item: nil,
110
111
  label: nil,
111
112
  icon: nil,
@@ -113,13 +114,15 @@ module OpenHAB
113
114
  label_color: nil,
114
115
  value_color: nil,
115
116
  icon_color: nil,
116
- visibility: nil)
117
+ visibility: nil,
118
+ &block)
117
119
  unless SitemapBuilder.factory.respond_to?("create_#{type}")
118
120
  raise ArgumentError,
119
121
  "#{type} is not a valid widget type"
120
122
  end
121
123
 
122
124
  @type = type
125
+ @builder_proxy = builder_proxy
123
126
  @item = item
124
127
  @label = label
125
128
  @icon = icon
@@ -133,6 +136,20 @@ module OpenHAB
133
136
  self.value_color(value_color) if value_color
134
137
  self.icon_color(icon_color) if icon_color
135
138
  self.visibility(*visibility) if visibility
139
+
140
+ return unless block
141
+
142
+ @builder_proxy ||= SimpleDelegator.new(nil) if block.arity == 1
143
+
144
+ if @builder_proxy
145
+ old_obj = @builder_proxy.__getobj__
146
+ @builder_proxy.__setobj__(self)
147
+ yield @builder_proxy
148
+ else
149
+ instance_eval_with_dummy_items(&block)
150
+ end
151
+ ensure
152
+ @builder_proxy&.__setobj__(old_obj)
136
153
  end
137
154
 
138
155
  # Adds one or more new rules for setting the label color
@@ -272,8 +289,8 @@ module OpenHAB
272
289
  # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, mappings: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
273
290
  # @param mappings [Hash, Array, nil] Mappings from command to label (see {SwitchBuilder#mappings})
274
291
  # @!visibility private
275
- def initialize(type, mappings: nil, **kwargs)
276
- super(type, **kwargs)
292
+ def initialize(type, builder_proxy, mappings: nil, **kwargs, &block)
293
+ super(type, builder_proxy, **kwargs, &block)
277
294
 
278
295
  @mappings = mappings
279
296
  end
@@ -313,8 +330,8 @@ module OpenHAB
313
330
  # @param range [Range, nil] Allowed range of the value (see {SetpointBuilder#range})
314
331
  # @param step [Numeric,nil] How far the value will change with each button press (see {SetpointBuilder#step})
315
332
  # @!visibility private
316
- def initialize(type, range: nil, step: nil, **kwargs)
317
- super(type, **kwargs)
333
+ def initialize(type, builder_proxy, range: nil, step: nil, **kwargs, &block)
334
+ super(type, builder_proxy, **kwargs, &block)
318
335
 
319
336
  @range = range
320
337
  @step = step
@@ -349,8 +366,8 @@ module OpenHAB
349
366
  # @param frequency [Numeric, nil]
350
367
  # How often to send requests (in seconds) (see {SliderBuilder#frequency})
351
368
  # @!visibility private
352
- def initialize(type, switch: nil, frequency: nil, **kwargs)
353
- super(type, **kwargs)
369
+ def initialize(type, builder_proxy, switch: nil, frequency: nil, **kwargs, &block)
370
+ super(type, builder_proxy, **kwargs, &block)
354
371
 
355
372
  @switch = switch
356
373
  @frequency = frequency
@@ -388,8 +405,8 @@ module OpenHAB
388
405
  # @param [String, nil] url (see {VideoBuilder#url})
389
406
  # @param [:mjpeg, :hls, nil] encoding (see {VideoBuilder#encoding})
390
407
  # @!visibility private
391
- def initialize(type, url: nil, encoding: nil, **kwargs)
392
- super(type, **kwargs)
408
+ def initialize(type, builder_proxy, url: nil, encoding: nil, **kwargs, &block)
409
+ super(type, builder_proxy, **kwargs, &block)
393
410
 
394
411
  @url = url
395
412
  self.encoding = encoding
@@ -457,14 +474,16 @@ module OpenHAB
457
474
  # Formatting string for values on the y axis (see {ChartBuilder#y_axis_pattern})
458
475
  # @!visibility private
459
476
  def initialize(type,
477
+ builder_proxy,
460
478
  service: nil,
461
479
  refresh: nil,
462
480
  period: nil,
463
481
  legend: nil,
464
482
  group: nil,
465
483
  y_axis_pattern: nil,
466
- **kwargs)
467
- super(type, **kwargs)
484
+ **kwargs,
485
+ &block)
486
+ super(type, builder_proxy, **kwargs, &block)
468
487
 
469
488
  @service = service
470
489
  self.refresh = refresh
@@ -514,8 +533,8 @@ module OpenHAB
514
533
  # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, height: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
515
534
  # @param height [Integer] The number of element rows to fill (see {DefaultBuilder#height})
516
535
  # @!visibility private
517
- def initialize(type, height: nil, **kwargs)
518
- super(type, **kwargs)
536
+ def initialize(type, builder_proxy, height: nil, **kwargs, &block)
537
+ super(type, builder_proxy, **kwargs, &block)
519
538
 
520
539
  @height = height
521
540
  end
@@ -539,8 +558,8 @@ module OpenHAB
539
558
  # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, url: nil, height: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
540
559
  # @param url [String, nil] (see {WebviewBuilder#url})
541
560
  # @!visibility private
542
- def initialize(type, url: nil, **kwargs)
543
- super(type, **kwargs)
561
+ def initialize(type, builder_proxy, url: nil, **kwargs, &block)
562
+ super(type, builder_proxy, **kwargs, &block)
544
563
 
545
564
  @url = url
546
565
  end
@@ -565,8 +584,8 @@ module OpenHAB
565
584
  # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, frequency: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
566
585
  # @param frequency [Numeric, nil] How often to send requests (see {ColorpickerBuilder#frequency})
567
586
  # @!visibility private
568
- def initialize(type, frequency: nil, **kwargs)
569
- super(type, **kwargs)
587
+ def initialize(type, builder_proxy, frequency: nil, **kwargs, &block)
588
+ super(type, builder_proxy, **kwargs, &block)
570
589
 
571
590
  @frequency = frequency
572
591
  end
@@ -601,8 +620,8 @@ module OpenHAB
601
620
  # @param [:text, :number, :date, :time, :datetime, nil] hint
602
621
  # Gives a hint to the user interface to use a widget adapted to a specific use (see {InputBuilder#hint})
603
622
  # @!visibility private
604
- def initialize(type, hint: nil, **kwargs)
605
- super(type, **kwargs)
623
+ def initialize(type, builder_proxy, hint: nil, **kwargs, &block)
624
+ super(type, builder_proxy, **kwargs, &block)
606
625
 
607
626
  self.hint = hint
608
627
  end
@@ -658,10 +677,10 @@ module OpenHAB
658
677
  #
659
678
  # @see https://www.openhab.org/docs/ui/sitemaps.html#element-type-buttongrid
660
679
  # @!visibility private
661
- def initialize(type, buttons: [], **kwargs)
662
- super(type, **kwargs)
663
- buttons.each { |button| validate_button(button) }
680
+ def initialize(type, builder_proxy, buttons: [], **kwargs, &block)
664
681
  @buttons = buttons
682
+ super(type, builder_proxy, **kwargs, &block)
683
+ buttons.each { |button| validate_button(button) }
665
684
  end
666
685
 
667
686
  #
@@ -998,9 +1017,10 @@ module OpenHAB
998
1017
  class_eval <<~RUBY, __FILE__, __LINE__ + 1
999
1018
  def #{method}(*args, **kwargs, &block) # def frame(*args, **kwargs, &block)
1000
1019
  widget = #{method.capitalize}Builder.new(#{method.inspect}, # widget = FrameBuilder.new(:frame,
1020
+ @builder_proxy, # @builder_proxy,
1001
1021
  *args, # *args,
1002
- **kwargs) # **kwargs)
1003
- widget.instance_eval_with_dummy_items(&block) if block # widget.instance_eval_with_dummy_items(&block) if block
1022
+ **kwargs, # **kwargs,
1023
+ &block) # &block)
1004
1024
  children << widget # children << widget
1005
1025
  widget # widget
1006
1026
  end # end
@@ -1011,9 +1031,9 @@ module OpenHAB
1011
1031
  # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
1012
1032
  # @!visibility private
1013
1033
  def initialize(*, **)
1014
- super
1015
-
1016
1034
  @children = []
1035
+
1036
+ super
1017
1037
  end
1018
1038
 
1019
1039
  # @!visibility private
@@ -1062,8 +1082,8 @@ module OpenHAB
1062
1082
  # @param url [String, nil] The URL for the image (see {ImageBuilder#url})
1063
1083
  # @param refresh [Numeric, nil] How often to refresh the image (see {ImageBuilder#refresh})
1064
1084
  # @!visibility private
1065
- def initialize(type, url: nil, refresh: nil, **kwargs)
1066
- super(type, **kwargs)
1085
+ def initialize(type, builder_proxy, url: nil, refresh: nil, **kwargs, &block)
1086
+ super(type, builder_proxy, **kwargs, &block)
1067
1087
 
1068
1088
  @url = url
1069
1089
  @refresh = refresh
@@ -1111,8 +1131,8 @@ module OpenHAB
1111
1131
  # @param label [String, nil]
1112
1132
  # @param icon [String, nil]
1113
1133
  # @!visibility private
1114
- def initialize(name, label: nil, icon: nil)
1115
- super(:sitemap, label: label, icon: icon)
1134
+ def initialize(name, builder_proxy, label: nil, icon: nil)
1135
+ super(:sitemap, builder_proxy, label: label, icon: icon)
1116
1136
 
1117
1137
  @name = name
1118
1138
  end
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.14.0"
7
+ VERSION = "5.15.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.14.0
4
+ version: 5.15.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: 2024-01-05 00:00:00.000000000 Z
13
+ date: 2024-01-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler