openhab-scripting 5.12.1 → 5.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,8 +36,14 @@ module OpenHAB
36
36
  # Base class for all widgets
37
37
  # @see org.openhab.core.model.sitemap.sitemap.Widget
38
38
  class WidgetBuilder
39
- # This is copied directly out of UIComponentSitemapProvider.java
40
- CONDITION_PATTERN = /(?<item>[A-Za-z]\w*)?\s*(?<condition>==|!=|<=|>=|<|>)?\s*(?<sign>\+|-)?(?<state>.+)/.freeze
39
+ include Core::EntityLookup
40
+
41
+ # This is copied out of UIComponentSitemapProvider.java
42
+ # The original pattern will match plain state e.g. "ON" as item="O" and state="N"
43
+ # this pattern is modified so it matches as item=nil and state="ON" by using atomic grouping `(?>subexpression)`
44
+ # rubocop:disable Layout/LineLength
45
+ CONDITION_PATTERN = /(?>(?<item>[A-Za-z]\w*)?\s*(?<condition>==|!=|<=|>=|<|>))?\s*(?<sign>\+|-)?(?<state>.+)/.freeze
46
+ # rubocop:enable Layout/LineLength
41
47
  private_constant :CONDITION_PATTERN
42
48
 
43
49
  # @return [String, nil]
@@ -45,19 +51,39 @@ module OpenHAB
45
51
  # The item whose state to show
46
52
  # @return [String, Core::Items::Item, nil]
47
53
  attr_accessor :item
48
- # @return [String, nil]
54
+ # The icon to show
55
+ # It can be a string, or a hash of conditions and icons.
56
+ # @example A simple icon
57
+ # sitemaps.build { text icon: "f7:house" }
58
+ #
59
+ # @example A dynamic icon with conditions
60
+ # sitemaps.build do
61
+ # text item: Wifi_Status, icon: {
62
+ # "ON" => "f7:wifi",
63
+ # "OFF" => "f7:wifi_slash",
64
+ # default: "f7:wifi_exclamationmark"
65
+ # }
66
+ # end
67
+ #
68
+ # @return [String, Hash<String, String>, Hash<Array<String>, String>, nil]
49
69
  # @see https://www.openhab.org/docs/ui/sitemaps.html#icons
50
70
  attr_accessor :icon
71
+ # The static icon to show
72
+ # This is mutually exclusive with {#icon}
73
+ # @return [String, nil]
74
+ # @since openHAB 4.1
75
+ # @see https://www.openhab.org/docs/ui/sitemaps.html#element-types
76
+ attr_accessor :static_icon
51
77
  # Label color rules
52
- # @return [Hash<String, String>]
78
+ # @return [Hash<String, String>, Hash<Array<String>, String>]
53
79
  # @see https://www.openhab.org/docs/ui/sitemaps.html#label-value-and-icon-colors
54
80
  attr_reader :label_colors
55
81
  # Value color rules
56
- # @return [Hash<String, String>]
82
+ # @return [Hash<String, String>, Hash<Array<String>, String>]
57
83
  # @see https://www.openhab.org/docs/ui/sitemaps.html#label-value-and-icon-colors
58
84
  attr_reader :value_colors
59
85
  # Icon color rules
60
- # @return [Hash<String, String>]
86
+ # @return [Hash<String, String>, Hash<Array<String>, String>]
61
87
  # @see https://www.openhab.org/docs/ui/sitemaps.html#label-value-and-icon-colors
62
88
  attr_reader :icon_colors
63
89
  # Visibility rules
@@ -67,16 +93,22 @@ module OpenHAB
67
93
 
68
94
  # @param item [String, Core::Items::Item, nil] The item whose state to show (see {#item})
69
95
  # @param label [String, nil] (see {#label})
70
- # @param icon [String, nil] (see {#icon})
71
- # @param label_color [String, Array<String>, nil] One or more label color rules (see {#label_color})
72
- # @param value_color [String, Array<String>, nil] One or more value color rules (see {#value_color})
73
- # @param icon_color [String, Array<String>, nil] One or more icon color rules (see {#icon_color})
74
- # @param visibility [String, Array<String>, nil] One or more visibility rules (see {#visibility})
96
+ # @param icon [String, Hash<String, String>, Hash<Array<String>, String>, nil] (see {#icon})
97
+ # @param static_icon [String, nil] (see {#static_icon})
98
+ # @param label_color [String, Hash<String, String>, Hash<Array<String>, String>, nil]
99
+ # One or more label color rules (see {#label_color})
100
+ # @param value_color [String, Hash<String, String>, Hash<Array<String>, String>, nil]
101
+ # One or more value color rules (see {#value_color})
102
+ # @param icon_color [String, Hash<String, String>, Hash<Array<String>, String>, nil]
103
+ # One or more icon color rules (see {#icon_color})
104
+ # @param visibility [String, Array<String>, Array<Array<String>>, nil]
105
+ # One or more visibility rules (see {#visibility})
75
106
  # @!visibility private
76
107
  def initialize(type,
77
108
  item: nil,
78
109
  label: nil,
79
110
  icon: nil,
111
+ static_icon: nil,
80
112
  label_color: nil,
81
113
  value_color: nil,
82
114
  icon_color: nil,
@@ -90,6 +122,7 @@ module OpenHAB
90
122
  @item = item
91
123
  @label = label
92
124
  @icon = icon
125
+ @static_icon = static_icon
93
126
  @visibilities = []
94
127
  @label_colors = {}
95
128
  @value_colors = {}
@@ -104,18 +137,21 @@ module OpenHAB
104
137
  # Adds one or more new rules for setting the label color
105
138
  # @return [Hash<String, String>] the current rules
106
139
  def label_color(rules)
140
+ rules = { default: rules } if rules.is_a?(String)
107
141
  @label_colors.merge!(rules)
108
142
  end
109
143
 
110
144
  # Adds one or more new rules for setting the value color
111
145
  # @return [Hash<String, String>] the current rules
112
146
  def value_color(rules)
147
+ rules = { default: rules } if rules.is_a?(String)
113
148
  @value_colors.merge!(rules)
114
149
  end
115
150
 
116
151
  # Adds one or more new rules for setting the icon color
117
152
  # @return [Hash<String, String>] the current rules
118
153
  def icon_color(rules)
154
+ rules = { default: rules } if rules.is_a?(String)
119
155
  @icon_colors.merge!(rules)
120
156
  end
121
157
 
@@ -132,31 +168,24 @@ module OpenHAB
132
168
  item = item.name if item.respond_to?(:name)
133
169
  widget.item = item if item
134
170
  widget.label = @label
135
- widget.icon = @icon
171
+
172
+ raise ArgumentError, "icon and static_icon are mutually exclusive" if icon && static_icon
173
+
174
+ if static_icon
175
+ widget.static_icon = static_icon
176
+ elsif icon.is_a?(String)
177
+ widget.icon = @icon
178
+ elsif icon.is_a?(Hash)
179
+ add_icons(widget)
180
+ elsif !icon.nil?
181
+ raise ArgumentError, "icon must be a String or a Hash"
182
+ end
136
183
 
137
184
  add_colors(widget, :label_color, label_colors)
138
185
  add_colors(widget, :value_color, value_colors)
139
186
  add_colors(widget, :icon_color, icon_colors)
140
187
 
141
- # @deprecated OH 4.1
142
- if SitemapBuilder.factory.respond_to?(:create_condition)
143
- add_conditions(widget, :visibility, visibilities, :create_visibility_rule)
144
- else
145
- visibilities.each do |v|
146
- raise ArgumentError, "AND conditions not supported prior to openHAB 4.1" if v.is_a?(Array)
147
-
148
- unless (match = CONDITION_PATTERN.match(v))
149
- raise ArgumentError, "Syntax error in visibility rule #{v.inspect}"
150
- end
151
-
152
- rule = SitemapBuilder.factory.create_visibility_rule
153
- rule.item = match["item"]
154
- rule.condition = match["condition"]
155
- rule.sign = match["sign"]
156
- rule.state = match["state"]
157
- widget.visibility.add(rule)
158
- end
159
- end
188
+ add_conditions(widget, :visibility, visibilities, :create_visibility_rule)
160
189
 
161
190
  widget
162
191
  end
@@ -173,12 +202,19 @@ module OpenHAB
173
202
 
174
203
  private
175
204
 
176
- def add_colors(widget, method, conditions)
177
- conditions.each do |condition, color|
178
- condition = [condition] unless condition.is_a?(Array)
179
- add_conditions(widget, method, condition, :create_color_array) do |color_array|
180
- color_array.arg = color
181
- end
205
+ def add_colors(widget, method, colors)
206
+ # ensure that the default color is at the end, and make the conditions nil (no conditions)
207
+ colors.delete(:default)&.tap { |default_color| colors.merge!(nil => default_color) }
208
+
209
+ add_conditions(widget, method, colors.keys, :create_color_array) do |color_array, key|
210
+ color_array.arg = colors[key]
211
+ end
212
+ end
213
+
214
+ def add_icons(widget)
215
+ icon.delete(:default)&.tap { |default_icon| icon.merge!(nil => default_icon) }
216
+ add_conditions(widget, :icon_rules, icon.keys, :create_icon_rule) do |icon_array, key|
217
+ icon_array.arg = icon[key]
182
218
  end
183
219
  end
184
220
 
@@ -186,25 +222,22 @@ module OpenHAB
186
222
  return if conditions.empty?
187
223
 
188
224
  object = widget.send(method)
189
- has_and_conditions = conditions.any?(Array)
190
- # @deprecated OH 4.1
191
- if !SitemapBuilder.factory.respond_to?(:create_condition) && has_and_conditions
225
+ # @deprecated OH 4.0
226
+ if conditions.any?(Array) && !SitemapBuilder.factory.respond_to?(:create_condition)
192
227
  raise ArgumentError, "AND conditions not supported prior to openHAB 4.1"
193
228
  end
194
229
 
195
- conditions = [conditions] unless has_and_conditions
196
-
197
230
  conditions.each do |sub_conditions|
198
231
  container = SitemapBuilder.factory.send(container_method)
199
232
 
200
233
  add_conditions_to_container(container, sub_conditions)
201
- yield container if block_given?
234
+ yield container, sub_conditions if block_given?
202
235
  object.add(container)
203
236
  end
204
237
  end
205
238
 
206
239
  def add_conditions_to_container(container, conditions)
207
- # @deprecated OH 4.1
240
+ # @deprecated OH 4.0
208
241
  supports_and_conditions = SitemapBuilder.factory.respond_to?(:create_condition)
209
242
 
210
243
  Array.wrap(conditions).each do |c|
@@ -235,7 +268,7 @@ module OpenHAB
235
268
  attr_accessor :mappings
236
269
 
237
270
  # (see WidgetBuilder#initialize)
238
- # @!method initialize(item: nil, label: nil, icon: nil, mappings: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
271
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, mappings: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
239
272
  # @param mappings [Hash, Array, nil] Mappings from command to label (see {SwitchBuilder#mappings})
240
273
  # @!visibility private
241
274
  def initialize(type, mappings: nil, **kwargs)
@@ -275,7 +308,7 @@ module OpenHAB
275
308
  attr_accessor :step
276
309
 
277
310
  # (see WidgetBuilder#initialize)
278
- # @!method initialize(item: nil, label: nil, icon: nil, range: nil, step: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
311
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, range: nil, step: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
279
312
  # @param range [Range, nil] Allowed range of the value (see {SetpointBuilder#range})
280
313
  # @param step [Numeric,nil] How far the value will change with each button press (see {SetpointBuilder#step})
281
314
  # @!visibility private
@@ -309,7 +342,7 @@ module OpenHAB
309
342
  attr_writer :switch
310
343
 
311
344
  # (see SetpointBuilder#initialize)
312
- # @!method initialize(item: nil, label: nil, icon: nil, range: nil, step: nil, switch: nil, frequency: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
345
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, range: nil, step: nil, switch: nil, frequency: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
313
346
  # @param switch [true, false, nil]
314
347
  # A short press on the item toggles the item on or off (see {SliderBuilder#switch=})
315
348
  # @param frequency [Numeric, nil]
@@ -350,7 +383,7 @@ module OpenHAB
350
383
  attr_reader :encoding
351
384
 
352
385
  # (see WidgetBuilder#initialize)
353
- # @!method initialize(item: nil, label: nil, icon: nil, url: nil, encoding: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
386
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, url: nil, encoding: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
354
387
  # @param [String, nil] url (see {VideoBuilder#url})
355
388
  # @param [:mjpeg, :hls, nil] encoding (see {VideoBuilder#encoding})
356
389
  # @!visibility private
@@ -408,7 +441,7 @@ module OpenHAB
408
441
  attr_accessor :y_axis_pattern
409
442
 
410
443
  # (see WidgetBuilder#initialize)
411
- # @!method initialize(item: nil, label: nil, icon: nil, service: nil, refresh: nil, period: nil, legend: nil, group: nil, y_axis_pattern: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
444
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, service: nil, refresh: nil, period: nil, legend: nil, group: nil, y_axis_pattern: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
412
445
  # @param service [String, nil]
413
446
  # The persistence service to use (see {ChartBuilder#service})
414
447
  # @param refresh [Numeric, nil)]
@@ -477,7 +510,7 @@ module OpenHAB
477
510
  attr_accessor :height
478
511
 
479
512
  # (see WidgetBuilder#initialize)
480
- # @!method initialize(item: nil, label: nil, icon: nil, height: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
513
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, height: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
481
514
  # @param height [Integer] The number of element rows to fill (see {DefaultBuilder#height})
482
515
  # @!visibility private
483
516
  def initialize(type, height: nil, **kwargs)
@@ -502,7 +535,7 @@ module OpenHAB
502
535
  attr_accessor :url
503
536
 
504
537
  # (see DefaultBuilder#initialize)
505
- # @!method initialize(item: nil, label: nil, icon: nil, url: nil, height: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
538
+ # @!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)
506
539
  # @param url [String, nil] (see {WebviewBuilder#url})
507
540
  # @!visibility private
508
541
  def initialize(type, url: nil, **kwargs)
@@ -528,7 +561,7 @@ module OpenHAB
528
561
  attr_accessor :frequency
529
562
 
530
563
  # (see WidgetBuilder#initialize)
531
- # @!method initialize(item: nil, label: nil, icon: nil, frequency: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
564
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, frequency: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
532
565
  # @param frequency [Numeric, nil] How often to send requests (see {ColorpickerBuilder#frequency})
533
566
  # @!visibility private
534
567
  def initialize(type, frequency: nil, **kwargs)
@@ -563,7 +596,7 @@ module OpenHAB
563
596
  attr_reader :hint
564
597
 
565
598
  # (see WidgetBuilder#initialize)
566
- # @!method initialize(item: nil, label: nil, icon: nil, hint: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
599
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, hint: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
567
600
  # @param [:text, :number, :date, :time, :datetime, nil] hint
568
601
  # Gives a hint to the user interface to use a widget adapted to a specific use (see {InputBuilder#hint})
569
602
  # @!visibility private
@@ -588,11 +621,87 @@ module OpenHAB
588
621
  end
589
622
  end
590
623
 
624
+ # Builds a `Buttongrid` element
625
+ # @since openHAB 4.1
626
+ # @see https://www.openhab.org/docs/ui/sitemaps.html#element-type-buttongrid
627
+ # @see org.openhab.core.model.sitemap.sitemap.Buttongrid
628
+ class ButtongridBuilder < WidgetBuilder
629
+ # @return [Array<Array<int, int, Command, String, String>>]
630
+ # An array of buttons to display
631
+ attr_reader :buttons
632
+
633
+ # (see WidgetBuilder#initialize)
634
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, buttons: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
635
+ # @param [Array<Array<int, int, Command, String, String>>] buttons An array of buttons to display.
636
+ # Each element is an array with the following elements:
637
+ # - row: 1-12
638
+ # - column: 1-12
639
+ # - command: The command to send when the button is pressed
640
+ # - label: The label to display on the button
641
+ # - icon: The icon to display on the button (optional)
642
+ #
643
+ # @example
644
+ # # This creates a buttongrid to emulate a TV remote control
645
+ # sitemaps.build do
646
+ # buttongrid item: LivingRoom_TV_RCButton, buttons: [
647
+ # [1, 1, "BACK", "Back", "f7:return"],
648
+ # [1, 2, "HOME", "Menu", "material:apps"],
649
+ # [1, 3, "YELLOW", "Search", "f7:search"],
650
+ # [2, 2, "UP", "Up", "f7:arrowtriangle_up"],
651
+ # [4, 2, "DOWN", "Down", "f7:arrowtriangle_down"],
652
+ # [3, 1, "LEFT", "Left", "f7:arrowtriangle_left"],
653
+ # [3, 3, "RIGHT", "Right", "f7:arrowtriangle_right"],
654
+ # [3, 2, "ENTER", "Enter", "material:adjust"]
655
+ # ]
656
+ # end
657
+ #
658
+ # @see https://www.openhab.org/docs/ui/sitemaps.html#element-type-buttongrid
659
+ # @!visibility private
660
+ def initialize(type, buttons: [], **kwargs)
661
+ super(type, **kwargs)
662
+ buttons.each { |button| validate_button(button) }
663
+ @buttons = buttons
664
+ end
665
+
666
+ #
667
+ # Adds a button to the buttongrid
668
+ #
669
+ # @param [Array<int, int, Command, String, String>] button the button to add
670
+ # @return [Array<Array<int, int, Command, String, String>>] the current buttons
671
+ #
672
+ def button(button)
673
+ validate_button(button)
674
+ @buttons << button
675
+ end
676
+
677
+ # @!visibility private
678
+ def build
679
+ widget = super
680
+ buttons.each do |button|
681
+ button_object = SitemapBuilder.factory.create_button
682
+ button_object.row = button[0]
683
+ button_object.column = button[1]
684
+ button_object.cmd = button[2]
685
+ button_object.label = button[3]
686
+ button_object.icon = button[4] if button[4]
687
+ widget.buttons.add(button_object)
688
+ end
689
+
690
+ widget
691
+ end
692
+
693
+ private
694
+
695
+ def validate_button(button)
696
+ return if (4..5).cover?(button.size)
697
+
698
+ raise ArgumentError, "Invalid button: '#{button.inspect}'. It must be an array with (4..5) elements"
699
+ end
700
+ end
701
+
591
702
  # Parent class for builders of widgets that can contain other widgets.
592
703
  # @see org.openhab.core.model.sitemap.sitemap.LinkableWidget
593
704
  class LinkableWidgetBuilder < WidgetBuilder
594
- include Core::EntityLookup
595
-
596
705
  # allow referring to items that don't exist yet
597
706
  self.create_dummy_items = true
598
707
 
@@ -609,6 +718,7 @@ module OpenHAB
609
718
  # def frame(item: nil,
610
719
  # label: nil,
611
720
  # icon: nil,
721
+ # static_icon: nil,
612
722
  # label_color: nil,
613
723
  # value_color: nil,
614
724
  # icon_color: nil,
@@ -623,6 +733,7 @@ module OpenHAB
623
733
  # def text(item: nil,
624
734
  # label: nil,
625
735
  # icon: nil,
736
+ # static_icon: nil,
626
737
  # label_color: nil,
627
738
  # value_color: nil,
628
739
  # icon_color: nil,
@@ -637,6 +748,7 @@ module OpenHAB
637
748
  # def group(item: nil,
638
749
  # label: nil,
639
750
  # icon: nil,
751
+ # static_icon: nil,
640
752
  # label_color: nil,
641
753
  # value_color: nil,
642
754
  # icon_color: nil,
@@ -651,6 +763,7 @@ module OpenHAB
651
763
  # def image(item: nil,
652
764
  # label: nil,
653
765
  # icon: nil,
766
+ # static_icon: nil,
654
767
  # url: nil,
655
768
  # refresh: nil,
656
769
  # label_color: nil,
@@ -667,6 +780,7 @@ module OpenHAB
667
780
  # def video(item: nil,
668
781
  # label: nil,
669
782
  # icon: nil,
783
+ # static_icon: nil,
670
784
  # url: nil,
671
785
  # encoding: nil,
672
786
  # label_color: nil,
@@ -683,6 +797,7 @@ module OpenHAB
683
797
  # def chart(item: nil,
684
798
  # label: nil,
685
799
  # icon: nil,
800
+ # static_icon: nil,
686
801
  # service: nil,
687
802
  # refresh: nil,
688
803
  # period: nil,
@@ -703,6 +818,7 @@ module OpenHAB
703
818
  # def webview(item: nil,
704
819
  # label: nil,
705
820
  # icon: nil,
821
+ # static_icon: nil,
706
822
  # url: nil,
707
823
  # height: nil,
708
824
  # label_color: nil,
@@ -719,6 +835,7 @@ module OpenHAB
719
835
  # def switch(item: nil,
720
836
  # label: nil,
721
837
  # icon: nil,
838
+ # static_icon: nil,
722
839
  # mappings: nil,
723
840
  # label_color: nil,
724
841
  # value_color: nil,
@@ -734,6 +851,7 @@ module OpenHAB
734
851
  # def mapview(item: nil,
735
852
  # label: nil,
736
853
  # icon: nil,
854
+ # static_icon: nil,
737
855
  # height: nil,
738
856
  # label_color: nil,
739
857
  # value_color: nil,
@@ -749,6 +867,7 @@ module OpenHAB
749
867
  # def slider(item: nil,
750
868
  # label: nil,
751
869
  # icon: nil,
870
+ # static_icon: nil,
752
871
  # range: nil,
753
872
  # step: nil,
754
873
  # switch: nil,
@@ -767,6 +886,7 @@ module OpenHAB
767
886
  # def selection(item: nil,
768
887
  # label: nil,
769
888
  # icon: nil,
889
+ # static_icon: nil,
770
890
  # mappings: nil,
771
891
  # label_color: nil,
772
892
  # value_color: nil,
@@ -783,6 +903,7 @@ module OpenHAB
783
903
  # def input(item: nil,
784
904
  # label: nil,
785
905
  # icon: nil,
906
+ # static_icon: nil,
786
907
  # hint: nil,
787
908
  # label_color: nil,
788
909
  # value_color: nil,
@@ -790,6 +911,23 @@ module OpenHAB
790
911
  # visibility: nil)
791
912
  # end
792
913
  #
914
+ # # (see ButtongridBuilder#initialize)
915
+ # # Create a new `Buttongrid` element.
916
+ # # @yield Block executed in the context of an {ButtongridBuilder}
917
+ # # @return [ButtongridBuilder]
918
+ # # @since openHAB 4.1
919
+ # # @!visibility public
920
+ # def buttongrid(item: nil,
921
+ # label: nil,
922
+ # icon: nil,
923
+ # static_icon: nil,
924
+ # buttons: nil,
925
+ # label_color: nil,
926
+ # value_color: nil,
927
+ # icon_color: nil,
928
+ # visibility: nil)
929
+ # end
930
+ #
793
931
  # # (see SetpointBuilder#initialize)
794
932
  # # Create a new `Setpoint` element.
795
933
  # # @yield Block executed in the context of a {SetpointBuilder}
@@ -798,6 +936,7 @@ module OpenHAB
798
936
  # def setpoint(item: nil,
799
937
  # label: nil,
800
938
  # icon: nil,
939
+ # static_icon: nil,
801
940
  # range: nil,
802
941
  # step: nil,
803
942
  # label_color: nil,
@@ -814,6 +953,7 @@ module OpenHAB
814
953
  # def colorpicker(item: nil,
815
954
  # label: nil,
816
955
  # icon: nil,
956
+ # static_icon: nil,
817
957
  # frequency: nil,
818
958
  # label_color: nil,
819
959
  # value_color: nil,
@@ -829,6 +969,7 @@ module OpenHAB
829
969
  # def default(item: nil,
830
970
  # label: nil,
831
971
  # icon: nil,
972
+ # static_icon: nil,
832
973
  # height: nil,
833
974
  # label_color: nil,
834
975
  # value_color: nil,
@@ -849,6 +990,7 @@ module OpenHAB
849
990
  slider
850
991
  selection
851
992
  input
993
+ buttongrid
852
994
  setpoint
853
995
  colorpicker
854
996
  default].each do |method|
@@ -865,7 +1007,7 @@ module OpenHAB
865
1007
  end
866
1008
 
867
1009
  # (see WidgetBuilder#initialize)
868
- # @!method initialize(item: nil, label: nil, icon: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
1010
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
869
1011
  # @!visibility private
870
1012
  def initialize(*, **)
871
1013
  super
@@ -915,7 +1057,7 @@ module OpenHAB
915
1057
  attr_accessor :refresh
916
1058
 
917
1059
  # (see LinkableWidgetBuilder#initialize)
918
- # @!method initialize(item: nil, label: nil, icon: nil, url: nil, refresh: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
1060
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, url: nil, refresh: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
919
1061
  # @param url [String, nil] The URL for the image (see {ImageBuilder#url})
920
1062
  # @param refresh [Numeric, nil] How often to refresh the image (see {ImageBuilder#refresh})
921
1063
  # @!visibility private
@@ -309,13 +309,6 @@ module OpenHAB
309
309
  :description,
310
310
  :auto_update_policy
311
311
 
312
- class << self
313
- # @!visibility private
314
- def channel_type_registry
315
- @channel_type_registry ||= OSGi.service("org.openhab.core.thing.type.ChannelTypeRegistry")
316
- end
317
- end
318
-
319
312
  #
320
313
  # Constructor for ChannelBuilder
321
314
  #
@@ -396,7 +389,7 @@ module OpenHAB
396
389
  # @!attribute [r] accepted_item_type
397
390
  # @return [String] The accepted item type.
398
391
  def accepted_item_type
399
- @accepted_item_type ||= self.class.channel_type_registry.get_channel_type(type)&.item_type
392
+ @accepted_item_type ||= type.channel_type&.item_type
400
393
  end
401
394
 
402
395
  private
@@ -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.1"
7
+ VERSION = "5.13.0"
8
8
  end
9
9
  end
data/lib/openhab/dsl.rb CHANGED
@@ -61,13 +61,13 @@ module OpenHAB
61
61
  end
62
62
 
63
63
  # (see Rules::Builder#scene)
64
- def scene(name = nil, id: nil, **kwargs, &block)
65
- rules.build { scene(name, id: id, **kwargs, &block) }
64
+ def scene(name = nil, description: nil, id: nil, tag: nil, tags: nil, **kwargs, &block)
65
+ rules.build { scene(name, description: description, id: id, tag: tag, tags: tags, **kwargs, &block) }
66
66
  end
67
67
 
68
68
  # (see Rules::Builder#script)
69
- def script(name = nil, id: nil, **kwargs, &block)
70
- rules.build { script(name, id: id, **kwargs, &block) }
69
+ def script(name = nil, description: nil, id: nil, tag: nil, tags: nil, **kwargs, &block)
70
+ rules.build { script(name, description: description, id: id, tag: tag, tags: tags, **kwargs, &block) }
71
71
  end
72
72
 
73
73
  # @!group Rule Support
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.1
4
+ version: 5.13.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-12-29 00:00:00.000000000 Z
13
+ date: 2024-01-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -358,6 +358,7 @@ extensions: []
358
358
  extra_rdoc_files: []
359
359
  files:
360
360
  - lib/openhab/core.rb
361
+ - lib/openhab/core/abstract_uid.rb
361
362
  - lib/openhab/core/actions.rb
362
363
  - lib/openhab/core/actions/audio.rb
363
364
  - lib/openhab/core/actions/ephemeris.rb
@@ -432,7 +433,15 @@ files:
432
433
  - lib/openhab/core/script_handling.rb
433
434
  - lib/openhab/core/sitemaps/provider.rb
434
435
  - lib/openhab/core/things.rb
436
+ - lib/openhab/core/things/abstract_description_type.rb
435
437
  - lib/openhab/core/things/channel.rb
438
+ - lib/openhab/core/things/channel_definition.rb
439
+ - lib/openhab/core/things/channel_group_definition.rb
440
+ - lib/openhab/core/things/channel_group_type.rb
441
+ - lib/openhab/core/things/channel_group_type_uid.rb
442
+ - lib/openhab/core/things/channel_group_uid.rb
443
+ - lib/openhab/core/things/channel_type.rb
444
+ - lib/openhab/core/things/channel_type_uid.rb
436
445
  - lib/openhab/core/things/channel_uid.rb
437
446
  - lib/openhab/core/things/item_channel_link.rb
438
447
  - lib/openhab/core/things/links/provider.rb
@@ -441,6 +450,10 @@ files:
441
450
  - lib/openhab/core/things/proxy.rb
442
451
  - lib/openhab/core/things/registry.rb
443
452
  - lib/openhab/core/things/thing.rb
453
+ - lib/openhab/core/things/thing_type.rb
454
+ - lib/openhab/core/things/thing_type_uid.rb
455
+ - lib/openhab/core/things/thing_uid.rb
456
+ - lib/openhab/core/things/uid.rb
444
457
  - lib/openhab/core/timer.rb
445
458
  - lib/openhab/core/types.rb
446
459
  - lib/openhab/core/types/comparable_type.rb
@@ -464,7 +477,6 @@ files:
464
477
  - lib/openhab/core/types/type.rb
465
478
  - lib/openhab/core/types/un_def_type.rb
466
479
  - lib/openhab/core/types/up_down_type.rb
467
- - lib/openhab/core/uid.rb
468
480
  - lib/openhab/core/value_cache.rb
469
481
  - lib/openhab/core_ext.rb
470
482
  - lib/openhab/core_ext/between.rb