openhab-scripting 5.15.0 → 5.16.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: 11409728d3f0ecb384da9099355fea4728020aa1de1d494d3085dddea518e16c
4
- data.tar.gz: d4daa321f0b779b0c9f47ccc405cdafd3a71f55666e173cb29315a7f948b2029
3
+ metadata.gz: 66607fb79de6b8b718ddd8cc5cc10662809001e67915074b44360ba9f6408d31
4
+ data.tar.gz: e21976073a7323b4e8bfe05a09e8959472d950ad28df26534371c857fe64699f
5
5
  SHA512:
6
- metadata.gz: b8eee772f02cf086af4db419ecaa5752b21393302533f6fea628a6e9bc50d7e986b1815e03c71de7acba63a13088f46d3e73e96d416a1869a7e2b9fe627764ea
7
- data.tar.gz: 4ebdb8fb5d81c4429188163e4ced5aabf2ee8a33797b540a32e0e81024a67ac7143728b7679181ca26a4856f8e7e6ed291b5f4bb9427c1df2a744eb6fcb75dd1
6
+ metadata.gz: 815f05142db0071b36cd45b9f9e81c1c033cf759823150066f2c65ec4f5eb61fdf9b1bf4dbc0e8125adf3535eb9e83b71fbbf401c2e6f1a716838fe6f37cdd29
7
+ data.tar.gz: 4fe2bd7469d2d4489bd41ee9c62c6b4e7d53e6350e095c895b936813582d89e088b772bb0a44fde82aaecbfe5ff1c3fac320505001e24d0ac4519646abac5889
@@ -607,22 +607,31 @@ module Enumerable
607
607
  # @!group Filtering Methods
608
608
  #
609
609
 
610
- # Returns a new array of items that are a semantics Location (optionally of the given type)
610
+ #
611
+ # Returns a new array of items that are a semantics Location (optionally of one of the given types)
611
612
  # @return [Array<Item>]
612
- def locations(type = nil)
613
+ #
614
+ # @example Get all rooms
615
+ # items.locations(Semantics::Room)
616
+ #
617
+ # @example Get all bedrooms and bathrooms
618
+ # items.locations(Semantics::Bedroom, Semantics::Bathroom)
619
+ #
620
+ def locations(*types)
613
621
  begin
614
- raise ArgumentError if type && !(type < Semantics::Location)
622
+ raise ArgumentError unless types.all? { |type| type < Semantics::Location }
615
623
  rescue ArgumentError, TypeError
616
624
  raise ArgumentError, "type must be a subclass of Location"
617
625
  end
618
626
 
619
627
  result = select(&:location?)
620
- result.select! { |i| i.location_type <= type } if type
628
+ result.select! { |i| types.any? { |type| i.location_type <= type } } unless types.empty?
621
629
 
622
630
  result
623
631
  end
624
632
 
625
- # Returns a new array of items that are a semantics equipment (optionally of the given type)
633
+ #
634
+ # Returns a new array of items that are a semantics equipment (optionally of one of the given types)
626
635
  #
627
636
  # @note As {Semantics::Equipment equipments} are usually
628
637
  # {GroupItem GroupItems}, this method therefore returns an array of
@@ -633,16 +642,20 @@ module Enumerable
633
642
  # @return [Array<Item>]
634
643
  #
635
644
  # @example Get all TVs in a room
636
- # lGreatRoom.equipments(Semantics::Screen)
637
- def equipments(type = nil)
645
+ # lGreatRoom.equipments(Semantics::Television)
646
+ #
647
+ # @example Get all TVs and Speakers in a room
648
+ # lGreatRoom.equipments(Semantics::Television, Semantics::Speaker)
649
+ #
650
+ def equipments(*types)
638
651
  begin
639
- raise ArgumentError if type && !(type < Semantics::Equipment)
652
+ raise ArgumentError unless types.all? { |type| type < Semantics::Equipment }
640
653
  rescue ArgumentError, TypeError
641
654
  raise ArgumentError, "type must be a subclass of Equipment"
642
655
  end
643
656
 
644
657
  result = select(&:equipment?)
645
- result.select! { |i| i.equipment_type <= type } if type
658
+ result.select! { |i| types.any? { |type| i.equipment_type <= type } } unless types.empty?
646
659
 
647
660
  result
648
661
  end
@@ -663,8 +676,8 @@ module Enumerable
663
676
 
664
677
  begin
665
678
  raise ArgumentError unless point_or_property_types.all? do |tag|
666
- (tag < Semantics::Point ||
667
- tag < Semantics::Property)
679
+ tag < Semantics::Point ||
680
+ tag < Semantics::Property
668
681
  end
669
682
  rescue ArgumentError, TypeError
670
683
  raise ArgumentError, "point_or_property_types must all be a subclass of Point or Property"
@@ -137,7 +137,7 @@ module OpenHAB
137
137
  #
138
138
 
139
139
  ThingStatus.constants.each do |thingstatus|
140
- define_method("#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
140
+ define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
141
141
  end
142
142
 
143
143
  #
@@ -311,7 +311,7 @@ module Java::JavaUtil::List # rubocop:disable Style/ClassAndModuleChildren
311
311
  end
312
312
 
313
313
  def rotate!(count = 1)
314
- count = count % length
314
+ count %= length
315
315
  push(*shift(count))
316
316
  self
317
317
  end
@@ -125,7 +125,7 @@ module OpenHAB
125
125
  parameter = org.openhab.core.config.core.ConfigDescriptionParameterBuilder.create(name.to_s, type)
126
126
 
127
127
  p.each do |key, value|
128
- parameter.send("with_#{key}", value) unless value.nil?
128
+ parameter.send(:"with_#{key}", value) unless value.nil?
129
129
  end
130
130
  parameter.build
131
131
  end
@@ -20,15 +20,15 @@ module OpenHAB
20
20
  # in this module than instance variable belong to the module not the calling class
21
21
  define_method(name) do |*args, &block|
22
22
  if args.empty? && block.nil? == true
23
- instance_variable_get("@#{name}")
23
+ instance_variable_get(:"@#{name}")
24
24
  else
25
25
  logger.trace("Property '#{name}' called with args(#{args}) and block(#{block})")
26
26
  if args.length == 1
27
- instance_variable_set("@#{name}", args.first)
27
+ instance_variable_set(:"@#{name}", args.first)
28
28
  elsif args.length > 1
29
- instance_variable_set("@#{name}", args)
29
+ instance_variable_set(:"@#{name}", args)
30
30
  elsif block
31
- instance_variable_set("@#{name}", block)
31
+ instance_variable_set(:"@#{name}", block)
32
32
  end
33
33
  end
34
34
  end
@@ -47,7 +47,7 @@ module OpenHAB
47
47
  define_method(name) do |*args, &block|
48
48
  array_name ||= name
49
49
  if args.empty? && block.nil? == true
50
- instance_variable_get("@#{array_name}")
50
+ instance_variable_get(:"@#{array_name}")
51
51
  else
52
52
  logger.trace("Property '#{name}' called with args(#{args}) and block(#{block})")
53
53
  if args.length == 1
@@ -59,14 +59,14 @@ module OpenHAB
59
59
  end
60
60
  yield insert if block_given?
61
61
  insert = wrapper.new(insert) if wrapper
62
- instance_variable_set("@#{array_name}", (instance_variable_get("@#{array_name}") || []) << insert)
62
+ instance_variable_set(:"@#{array_name}", (instance_variable_get(:"@#{array_name}") || []) << insert)
63
63
  end
64
64
  end
65
65
 
66
66
  return unless array_name
67
67
 
68
68
  define_method(array_name) do
69
- instance_variable_get("@#{array_name}")
69
+ instance_variable_get(:"@#{array_name}")
70
70
  end
71
71
  end
72
72
  end
@@ -174,10 +174,10 @@ module OpenHAB
174
174
  def self.duration_to_map(duration)
175
175
  if duration.to_millis_part.zero? && duration.to_nanos_part.zero? && duration.to_days.zero?
176
176
  %i[second minute hour].each do |unit|
177
- to_unit_part = duration.public_send("to_#{unit}s_part")
177
+ to_unit_part = duration.public_send(:"to_#{unit}s_part")
178
178
  next unless to_unit_part.positive?
179
179
 
180
- to_unit = duration.public_send("to_#{unit}s")
180
+ to_unit = duration.public_send(:"to_#{unit}s")
181
181
  break unless to_unit_part == to_unit
182
182
 
183
183
  return EXPRESSION_MAP[unit].merge(unit => "*/#{to_unit}")
@@ -116,7 +116,7 @@ module OpenHAB
116
116
  icon_color: nil,
117
117
  visibility: nil,
118
118
  &block)
119
- unless SitemapBuilder.factory.respond_to?("create_#{type}")
119
+ unless SitemapBuilder.factory.respond_to?(:"create_#{type}")
120
120
  raise ArgumentError,
121
121
  "#{type} is not a valid widget type"
122
122
  end
@@ -144,12 +144,14 @@ module OpenHAB
144
144
  if @builder_proxy
145
145
  old_obj = @builder_proxy.__getobj__
146
146
  @builder_proxy.__setobj__(self)
147
- yield @builder_proxy
147
+ begin
148
+ yield @builder_proxy
149
+ ensure
150
+ @builder_proxy.__setobj__(old_obj)
151
+ end
148
152
  else
149
153
  instance_eval_with_dummy_items(&block)
150
154
  end
151
- ensure
152
- @builder_proxy&.__setobj__(old_obj)
153
155
  end
154
156
 
155
157
  # Adds one or more new rules for setting the label color
@@ -181,7 +183,7 @@ module OpenHAB
181
183
 
182
184
  # @!visibility private
183
185
  def build
184
- widget = SitemapBuilder.factory.send("create_#{@type}")
186
+ widget = SitemapBuilder.factory.send(:"create_#{@type}")
185
187
  item = @item
186
188
  item = item.name if item.respond_to?(:name)
187
189
  widget.item = item if item
@@ -279,9 +281,41 @@ module OpenHAB
279
281
  class SwitchBuilder < WidgetBuilder
280
282
  # Mappings from command to label
281
283
  #
282
- # Keys can be any {Core::Types::Command command}, values are strings.
283
- # If an array is given, the same value is used for both command and label.
284
+ # If a hash is given, the keys are the commands and the values are the labels.
285
+ # The keys can be any {Core::Types::Command command}, string or symbol.
286
+ # They will be converted to strings.
287
+ #
288
+ # If an array is given:
289
+ # - Scalar elements define the command, and the label is the same as the command.
290
+ # - Array elements contain the command, label, and optional third element for the icon.
291
+ # - Hash elements contain the command, label, and optional icon defined by the corresponding keys.
292
+ #
293
+ # @since openHAB 4.1 added support for icons
294
+ #
295
+ # @example A Hash to specify different command and label
296
+ # switch mappings: { off: "Off", cool: "Cool", heat: "Heat" }
297
+ #
298
+ # @example A simple array with the same command and label
299
+ # switch mappings: %w[off cool heat]
300
+ #
301
+ # @example An array of arrays containing the command, label, and icon
302
+ # switch mappings: [
303
+ # %w[off Off f7:power],
304
+ # %w[cool Cool f7:snow],
305
+ # %w[heat Heat f7:flame],
306
+ # %w[auto Auto] # no icon
307
+ # ]
308
+ #
309
+ # @example An array of hashes for the command, label, and icon
310
+ # switch mappings: [
311
+ # {command: "off", label: "Off", icon: "f7:power"},
312
+ # {command: "cool", label: "Cool", icon: "f7:snow"},
313
+ # {command: "heat", label: "Heat", icon: "f7:flame"},
314
+ # {command: "auto", label: "Auto"} # no icon
315
+ # ]
316
+ #
284
317
  # @return [Hash, Array, nil]
318
+ # @see LinkableWidgetBuilder#switch
285
319
  # @see https://www.openhab.org/docs/ui/sitemaps.html#mappings
286
320
  attr_accessor :mappings
287
321
 
@@ -298,10 +332,13 @@ module OpenHAB
298
332
  # @!visibility private
299
333
  def build
300
334
  widget = super
301
- mappings&.each do |cmd, label|
335
+ mappings&.each do |cmd, label, icon|
302
336
  mapping = SitemapBuilder.factory.create_mapping
337
+ cmd, label, icon = cmd.values_at(:command, :label, :icon) if cmd.is_a?(Hash)
303
338
  mapping.cmd = cmd.to_s
304
339
  mapping.label = label&.to_s || cmd.to_s
340
+ # @deprecated OH 4.1 the if check is not needed in OH4.1+
341
+ mapping.icon = icon if icon
305
342
  widget.mappings.add(mapping)
306
343
  end
307
344
  widget
@@ -663,16 +700,18 @@ module OpenHAB
663
700
  # @example
664
701
  # # This creates a buttongrid to emulate a TV remote control
665
702
  # sitemaps.build do
666
- # buttongrid item: LivingRoom_TV_RCButton, buttons: [
667
- # [1, 1, "BACK", "Back", "f7:return"],
668
- # [1, 2, "HOME", "Menu", "material:apps"],
669
- # [1, 3, "YELLOW", "Search", "f7:search"],
670
- # [2, 2, "UP", "Up", "f7:arrowtriangle_up"],
671
- # [4, 2, "DOWN", "Down", "f7:arrowtriangle_down"],
672
- # [3, 1, "LEFT", "Left", "f7:arrowtriangle_left"],
673
- # [3, 3, "RIGHT", "Right", "f7:arrowtriangle_right"],
674
- # [3, 2, "ENTER", "Enter", "material:adjust"]
675
- # ]
703
+ # sitemap "remote", label: "TV Remote Control" do
704
+ # buttongrid item: LivingRoom_TV_RCButton, buttons: [
705
+ # [1, 1, "BACK", "Back", "f7:return"],
706
+ # [1, 2, "HOME", "Menu", "material:apps"],
707
+ # [1, 3, "YELLOW", "Search", "f7:search"],
708
+ # [2, 2, "UP", "Up", "f7:arrowtriangle_up"],
709
+ # [4, 2, "DOWN", "Down", "f7:arrowtriangle_down"],
710
+ # [3, 1, "LEFT", "Left", "f7:arrowtriangle_left"],
711
+ # [3, 3, "RIGHT", "Right", "f7:arrowtriangle_right"],
712
+ # [3, 2, "ENTER", "Enter", "material:adjust"]
713
+ # ]
714
+ # end
676
715
  # end
677
716
  #
678
717
  # @see https://www.openhab.org/docs/ui/sitemaps.html#element-type-buttongrid
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.15.0"
7
+ VERSION = "5.16.0"
8
8
  end
9
9
  end
data/lib/openhab/log.rb CHANGED
@@ -210,7 +210,7 @@ module OpenHAB
210
210
  # @return [true,false]
211
211
  #
212
212
  def def_level_predicate(level)
213
- define_method("#{level}?") { @slf4j_logger.send("is_#{level}_enabled") }
213
+ define_method(:"#{level}?") { @slf4j_logger.send(:"is_#{level}_enabled") }
214
214
  end
215
215
  end
216
216
 
@@ -318,7 +318,7 @@ module OpenHAB
318
318
  raise ArgumentError, "Unknown Severity #{severity}" unless LEVELS.include? severity
319
319
 
320
320
  # Dynamically check enablement of underlying logger
321
- return unless send("#{severity}?")
321
+ return unless send(:"#{severity}?")
322
322
 
323
323
  # Process block if no message provided
324
324
  msg = yield if msg.nil? && block_given?
@@ -449,10 +449,13 @@ module OpenHAB
449
449
 
450
450
  def parse_emacs_modeline(line)
451
451
  line[EMACS_MODELINE_REGEXP, 1]
452
- &.split(";")
453
- &.map(&:strip)
454
- &.map { |l| l.split(":", 2).map(&:strip).tap { |a| a[1] ||= nil } }
455
- &.to_h
452
+ &.split(";")
453
+ &.to_h do |l|
454
+ l.strip
455
+ .split(":", 2)
456
+ .map(&:strip)
457
+ .tap { |a| a[1] ||= nil }
458
+ end
456
459
  end
457
460
 
458
461
  def ruby_file?(script)
@@ -7,7 +7,7 @@ module OpenHAB
7
7
  module CodeRay
8
8
  module HtmlHelper
9
9
  ::CodeRay::Scanners.list.each do |scanner|
10
- define_method("html_syntax_highlight_#{scanner}") do |source|
10
+ define_method(:"html_syntax_highlight_#{scanner}") do |source|
11
11
  ::CodeRay.scan(source, scanner).html
12
12
  end
13
13
  end
data/lib/openhab/yard.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "byebug"
4
-
5
3
  Dir[File.expand_path("yard/**/*.rb", __dir__)].sort.each do |f|
6
4
  require f
7
5
  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.15.0
4
+ version: 5.16.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-06 00:00:00.000000000 Z
13
+ date: 2024-01-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -96,20 +96,6 @@ dependencies:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
98
  version: '1.2'
99
- - !ruby/object:Gem::Dependency
100
- name: faraday-retry
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - "~>"
104
- - !ruby/object:Gem::Version
105
- version: '2.1'
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - "~>"
111
- - !ruby/object:Gem::Version
112
- version: '2.1'
113
99
  - !ruby/object:Gem::Dependency
114
100
  name: gem-release
115
101
  requirement: !ruby/object:Gem::Requirement
@@ -124,48 +110,6 @@ dependencies:
124
110
  - - "~>"
125
111
  - !ruby/object:Gem::Version
126
112
  version: '2.2'
127
- - !ruby/object:Gem::Dependency
128
- name: guard-rubocop
129
- requirement: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - "~>"
132
- - !ruby/object:Gem::Version
133
- version: '1.5'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- requirements:
138
- - - "~>"
139
- - !ruby/object:Gem::Version
140
- version: '1.5'
141
- - !ruby/object:Gem::Dependency
142
- name: guard-shell
143
- requirement: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - "~>"
146
- - !ruby/object:Gem::Version
147
- version: '0.7'
148
- type: :development
149
- prerelease: false
150
- version_requirements: !ruby/object:Gem::Requirement
151
- requirements:
152
- - - "~>"
153
- - !ruby/object:Gem::Version
154
- version: '0.7'
155
- - !ruby/object:Gem::Dependency
156
- name: guard-yard
157
- requirement: !ruby/object:Gem::Requirement
158
- requirements:
159
- - - "~>"
160
- - !ruby/object:Gem::Version
161
- version: '2.2'
162
- type: :development
163
- prerelease: false
164
- version_requirements: !ruby/object:Gem::Requirement
165
- requirements:
166
- - - "~>"
167
- - !ruby/object:Gem::Version
168
- version: '2.2'
169
113
  - !ruby/object:Gem::Dependency
170
114
  name: httparty
171
115
  requirement: !ruby/object:Gem::Requirement
@@ -180,34 +124,6 @@ dependencies:
180
124
  - - "~>"
181
125
  - !ruby/object:Gem::Version
182
126
  version: '0.20'
183
- - !ruby/object:Gem::Dependency
184
- name: irb
185
- requirement: !ruby/object:Gem::Requirement
186
- requirements:
187
- - - "~>"
188
- - !ruby/object:Gem::Version
189
- version: '1.4'
190
- type: :development
191
- prerelease: false
192
- version_requirements: !ruby/object:Gem::Requirement
193
- requirements:
194
- - - "~>"
195
- - !ruby/object:Gem::Version
196
- version: '1.4'
197
- - !ruby/object:Gem::Dependency
198
- name: nokogiri
199
- requirement: !ruby/object:Gem::Requirement
200
- requirements:
201
- - - "~>"
202
- - !ruby/object:Gem::Version
203
- version: '1.13'
204
- type: :development
205
- prerelease: false
206
- version_requirements: !ruby/object:Gem::Requirement
207
- requirements:
208
- - - "~>"
209
- - !ruby/object:Gem::Version
210
- version: '1.13'
211
127
  - !ruby/object:Gem::Dependency
212
128
  name: persistent_httparty
213
129
  requirement: !ruby/object:Gem::Requirement
@@ -264,48 +180,6 @@ dependencies:
264
180
  - - "~>"
265
181
  - !ruby/object:Gem::Version
266
182
  version: '3.11'
267
- - !ruby/object:Gem::Dependency
268
- name: rubocop-inst
269
- requirement: !ruby/object:Gem::Requirement
270
- requirements:
271
- - - ">="
272
- - !ruby/object:Gem::Version
273
- version: '0'
274
- type: :development
275
- prerelease: false
276
- version_requirements: !ruby/object:Gem::Requirement
277
- requirements:
278
- - - ">="
279
- - !ruby/object:Gem::Version
280
- version: '0'
281
- - !ruby/object:Gem::Dependency
282
- name: rubocop-rake
283
- requirement: !ruby/object:Gem::Requirement
284
- requirements:
285
- - - "~>"
286
- - !ruby/object:Gem::Version
287
- version: '0.6'
288
- type: :development
289
- prerelease: false
290
- version_requirements: !ruby/object:Gem::Requirement
291
- requirements:
292
- - - "~>"
293
- - !ruby/object:Gem::Version
294
- version: '0.6'
295
- - !ruby/object:Gem::Dependency
296
- name: rubocop-rspec
297
- requirement: !ruby/object:Gem::Requirement
298
- requirements:
299
- - - "~>"
300
- - !ruby/object:Gem::Version
301
- version: '2.11'
302
- type: :development
303
- prerelease: false
304
- version_requirements: !ruby/object:Gem::Requirement
305
- requirements:
306
- - - "~>"
307
- - !ruby/object:Gem::Version
308
- version: '2.11'
309
183
  - !ruby/object:Gem::Dependency
310
184
  name: timecop
311
185
  requirement: !ruby/object:Gem::Requirement