openhab-scripting 5.14.0 → 5.15.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2150062e6b4a58f888b09bb106f39cb57c7e67749b85dfc13978a8437702e33
|
4
|
+
data.tar.gz: 22cfc6729962a702bae8ecc83d26280e4967834a8235bd7ee9ac8f3596796f50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfab71ec2435493bafdf61bf447a34a644e366494a9ccdf174a98d9035b1cc8fd9828ca174c5288d2c41a5798cb6ea2bad8bd78f492cb5564f0f3cbf6fcf7023
|
7
|
+
data.tar.gz: 36ff08d089054720805effeb0fa16557b767a87b8238c45d7c3c2e5d5fc12ac0dffae5b0f2f7226435e68c5ddfb03a252a8ad12e680f422695040869865716cb
|
@@ -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
|
-
|
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,22 @@ 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
|
+
begin
|
148
|
+
yield @builder_proxy
|
149
|
+
ensure
|
150
|
+
@builder_proxy.__setobj__(old_obj)
|
151
|
+
end
|
152
|
+
else
|
153
|
+
instance_eval_with_dummy_items(&block)
|
154
|
+
end
|
136
155
|
end
|
137
156
|
|
138
157
|
# Adds one or more new rules for setting the label color
|
@@ -272,8 +291,8 @@ module OpenHAB
|
|
272
291
|
# @!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
292
|
# @param mappings [Hash, Array, nil] Mappings from command to label (see {SwitchBuilder#mappings})
|
274
293
|
# @!visibility private
|
275
|
-
def initialize(type, mappings: nil, **kwargs)
|
276
|
-
super(type, **kwargs)
|
294
|
+
def initialize(type, builder_proxy, mappings: nil, **kwargs, &block)
|
295
|
+
super(type, builder_proxy, **kwargs, &block)
|
277
296
|
|
278
297
|
@mappings = mappings
|
279
298
|
end
|
@@ -313,8 +332,8 @@ module OpenHAB
|
|
313
332
|
# @param range [Range, nil] Allowed range of the value (see {SetpointBuilder#range})
|
314
333
|
# @param step [Numeric,nil] How far the value will change with each button press (see {SetpointBuilder#step})
|
315
334
|
# @!visibility private
|
316
|
-
def initialize(type, range: nil, step: nil, **kwargs)
|
317
|
-
super(type, **kwargs)
|
335
|
+
def initialize(type, builder_proxy, range: nil, step: nil, **kwargs, &block)
|
336
|
+
super(type, builder_proxy, **kwargs, &block)
|
318
337
|
|
319
338
|
@range = range
|
320
339
|
@step = step
|
@@ -349,8 +368,8 @@ module OpenHAB
|
|
349
368
|
# @param frequency [Numeric, nil]
|
350
369
|
# How often to send requests (in seconds) (see {SliderBuilder#frequency})
|
351
370
|
# @!visibility private
|
352
|
-
def initialize(type, switch: nil, frequency: nil, **kwargs)
|
353
|
-
super(type, **kwargs)
|
371
|
+
def initialize(type, builder_proxy, switch: nil, frequency: nil, **kwargs, &block)
|
372
|
+
super(type, builder_proxy, **kwargs, &block)
|
354
373
|
|
355
374
|
@switch = switch
|
356
375
|
@frequency = frequency
|
@@ -388,8 +407,8 @@ module OpenHAB
|
|
388
407
|
# @param [String, nil] url (see {VideoBuilder#url})
|
389
408
|
# @param [:mjpeg, :hls, nil] encoding (see {VideoBuilder#encoding})
|
390
409
|
# @!visibility private
|
391
|
-
def initialize(type, url: nil, encoding: nil, **kwargs)
|
392
|
-
super(type, **kwargs)
|
410
|
+
def initialize(type, builder_proxy, url: nil, encoding: nil, **kwargs, &block)
|
411
|
+
super(type, builder_proxy, **kwargs, &block)
|
393
412
|
|
394
413
|
@url = url
|
395
414
|
self.encoding = encoding
|
@@ -457,14 +476,16 @@ module OpenHAB
|
|
457
476
|
# Formatting string for values on the y axis (see {ChartBuilder#y_axis_pattern})
|
458
477
|
# @!visibility private
|
459
478
|
def initialize(type,
|
479
|
+
builder_proxy,
|
460
480
|
service: nil,
|
461
481
|
refresh: nil,
|
462
482
|
period: nil,
|
463
483
|
legend: nil,
|
464
484
|
group: nil,
|
465
485
|
y_axis_pattern: nil,
|
466
|
-
**kwargs
|
467
|
-
|
486
|
+
**kwargs,
|
487
|
+
&block)
|
488
|
+
super(type, builder_proxy, **kwargs, &block)
|
468
489
|
|
469
490
|
@service = service
|
470
491
|
self.refresh = refresh
|
@@ -514,8 +535,8 @@ module OpenHAB
|
|
514
535
|
# @!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
536
|
# @param height [Integer] The number of element rows to fill (see {DefaultBuilder#height})
|
516
537
|
# @!visibility private
|
517
|
-
def initialize(type, height: nil, **kwargs)
|
518
|
-
super(type, **kwargs)
|
538
|
+
def initialize(type, builder_proxy, height: nil, **kwargs, &block)
|
539
|
+
super(type, builder_proxy, **kwargs, &block)
|
519
540
|
|
520
541
|
@height = height
|
521
542
|
end
|
@@ -539,8 +560,8 @@ module OpenHAB
|
|
539
560
|
# @!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
561
|
# @param url [String, nil] (see {WebviewBuilder#url})
|
541
562
|
# @!visibility private
|
542
|
-
def initialize(type, url: nil, **kwargs)
|
543
|
-
super(type, **kwargs)
|
563
|
+
def initialize(type, builder_proxy, url: nil, **kwargs, &block)
|
564
|
+
super(type, builder_proxy, **kwargs, &block)
|
544
565
|
|
545
566
|
@url = url
|
546
567
|
end
|
@@ -565,8 +586,8 @@ module OpenHAB
|
|
565
586
|
# @!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
587
|
# @param frequency [Numeric, nil] How often to send requests (see {ColorpickerBuilder#frequency})
|
567
588
|
# @!visibility private
|
568
|
-
def initialize(type, frequency: nil, **kwargs)
|
569
|
-
super(type, **kwargs)
|
589
|
+
def initialize(type, builder_proxy, frequency: nil, **kwargs, &block)
|
590
|
+
super(type, builder_proxy, **kwargs, &block)
|
570
591
|
|
571
592
|
@frequency = frequency
|
572
593
|
end
|
@@ -601,8 +622,8 @@ module OpenHAB
|
|
601
622
|
# @param [:text, :number, :date, :time, :datetime, nil] hint
|
602
623
|
# Gives a hint to the user interface to use a widget adapted to a specific use (see {InputBuilder#hint})
|
603
624
|
# @!visibility private
|
604
|
-
def initialize(type, hint: nil, **kwargs)
|
605
|
-
super(type, **kwargs)
|
625
|
+
def initialize(type, builder_proxy, hint: nil, **kwargs, &block)
|
626
|
+
super(type, builder_proxy, **kwargs, &block)
|
606
627
|
|
607
628
|
self.hint = hint
|
608
629
|
end
|
@@ -644,24 +665,26 @@ module OpenHAB
|
|
644
665
|
# @example
|
645
666
|
# # This creates a buttongrid to emulate a TV remote control
|
646
667
|
# sitemaps.build do
|
647
|
-
#
|
648
|
-
#
|
649
|
-
#
|
650
|
-
#
|
651
|
-
#
|
652
|
-
#
|
653
|
-
#
|
654
|
-
#
|
655
|
-
#
|
656
|
-
#
|
668
|
+
# sitemap "remote", label: "TV Remote Control" do
|
669
|
+
# buttongrid item: LivingRoom_TV_RCButton, buttons: [
|
670
|
+
# [1, 1, "BACK", "Back", "f7:return"],
|
671
|
+
# [1, 2, "HOME", "Menu", "material:apps"],
|
672
|
+
# [1, 3, "YELLOW", "Search", "f7:search"],
|
673
|
+
# [2, 2, "UP", "Up", "f7:arrowtriangle_up"],
|
674
|
+
# [4, 2, "DOWN", "Down", "f7:arrowtriangle_down"],
|
675
|
+
# [3, 1, "LEFT", "Left", "f7:arrowtriangle_left"],
|
676
|
+
# [3, 3, "RIGHT", "Right", "f7:arrowtriangle_right"],
|
677
|
+
# [3, 2, "ENTER", "Enter", "material:adjust"]
|
678
|
+
# ]
|
679
|
+
# end
|
657
680
|
# end
|
658
681
|
#
|
659
682
|
# @see https://www.openhab.org/docs/ui/sitemaps.html#element-type-buttongrid
|
660
683
|
# @!visibility private
|
661
|
-
def initialize(type, buttons: [], **kwargs)
|
662
|
-
super(type, **kwargs)
|
663
|
-
buttons.each { |button| validate_button(button) }
|
684
|
+
def initialize(type, builder_proxy, buttons: [], **kwargs, &block)
|
664
685
|
@buttons = buttons
|
686
|
+
super(type, builder_proxy, **kwargs, &block)
|
687
|
+
buttons.each { |button| validate_button(button) }
|
665
688
|
end
|
666
689
|
|
667
690
|
#
|
@@ -998,9 +1021,10 @@ module OpenHAB
|
|
998
1021
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
999
1022
|
def #{method}(*args, **kwargs, &block) # def frame(*args, **kwargs, &block)
|
1000
1023
|
widget = #{method.capitalize}Builder.new(#{method.inspect}, # widget = FrameBuilder.new(:frame,
|
1024
|
+
@builder_proxy, # @builder_proxy,
|
1001
1025
|
*args, # *args,
|
1002
|
-
**kwargs
|
1003
|
-
|
1026
|
+
**kwargs, # **kwargs,
|
1027
|
+
&block) # &block)
|
1004
1028
|
children << widget # children << widget
|
1005
1029
|
widget # widget
|
1006
1030
|
end # end
|
@@ -1011,9 +1035,9 @@ module OpenHAB
|
|
1011
1035
|
# @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
|
1012
1036
|
# @!visibility private
|
1013
1037
|
def initialize(*, **)
|
1014
|
-
super
|
1015
|
-
|
1016
1038
|
@children = []
|
1039
|
+
|
1040
|
+
super
|
1017
1041
|
end
|
1018
1042
|
|
1019
1043
|
# @!visibility private
|
@@ -1062,8 +1086,8 @@ module OpenHAB
|
|
1062
1086
|
# @param url [String, nil] The URL for the image (see {ImageBuilder#url})
|
1063
1087
|
# @param refresh [Numeric, nil] How often to refresh the image (see {ImageBuilder#refresh})
|
1064
1088
|
# @!visibility private
|
1065
|
-
def initialize(type, url: nil, refresh: nil, **kwargs)
|
1066
|
-
super(type, **kwargs)
|
1089
|
+
def initialize(type, builder_proxy, url: nil, refresh: nil, **kwargs, &block)
|
1090
|
+
super(type, builder_proxy, **kwargs, &block)
|
1067
1091
|
|
1068
1092
|
@url = url
|
1069
1093
|
@refresh = refresh
|
@@ -1111,8 +1135,8 @@ module OpenHAB
|
|
1111
1135
|
# @param label [String, nil]
|
1112
1136
|
# @param icon [String, nil]
|
1113
1137
|
# @!visibility private
|
1114
|
-
def initialize(name, label: nil, icon: nil)
|
1115
|
-
super(:sitemap, label: label, icon: icon)
|
1138
|
+
def initialize(name, builder_proxy, label: nil, icon: nil)
|
1139
|
+
super(:sitemap, builder_proxy, label: label, icon: icon)
|
1116
1140
|
|
1117
1141
|
@name = name
|
1118
1142
|
end
|
data/lib/openhab/dsl/version.rb
CHANGED
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.
|
4
|
+
version: 5.15.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: 2024-01-
|
13
|
+
date: 2024-01-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|