openhab-scripting 5.35.1 → 5.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/console/irb.rb +105 -0
  3. data/lib/openhab/console/jline.rb +104 -0
  4. data/lib/openhab/console/registry.rb +12 -0
  5. data/lib/openhab/console/stdio.rb +178 -0
  6. data/lib/openhab/console.rb +5 -0
  7. data/lib/openhab/core/emulate_hash.rb +11 -11
  8. data/lib/openhab/core/entity_lookup.rb +2 -4
  9. data/lib/openhab/core/events/item_state_updated_event.rb +0 -3
  10. data/lib/openhab/core/events/item_time_series_updated_event.rb +0 -3
  11. data/lib/openhab/core/events/startlevel_event.rb +0 -3
  12. data/lib/openhab/core/events/timer_event.rb +0 -3
  13. data/lib/openhab/core/items/generic_item.rb +14 -154
  14. data/lib/openhab/core/items/group_item.rb +2 -2
  15. data/lib/openhab/core/items/image_item.rb +5 -21
  16. data/lib/openhab/core/items/item.rb +161 -7
  17. data/lib/openhab/core/items/persistence.rb +8 -10
  18. data/lib/openhab/core/items/provider.rb +1 -1
  19. data/lib/openhab/core/items/proxy.rb +33 -94
  20. data/lib/openhab/core/items/registry.rb +1 -1
  21. data/lib/openhab/core/items/semantics/enumerable.rb +1 -1
  22. data/lib/openhab/core/items/semantics/provider.rb +1 -5
  23. data/lib/openhab/core/items/semantics/semantic_tag.rb +0 -3
  24. data/lib/openhab/core/items/semantics.rb +105 -141
  25. data/lib/openhab/core/items/switch_item.rb +1 -1
  26. data/lib/openhab/core/items.rb +22 -22
  27. data/lib/openhab/core/lazy_array.rb +4 -4
  28. data/lib/openhab/core/profile_factory.rb +16 -25
  29. data/lib/openhab/core/provider.rb +3 -4
  30. data/lib/openhab/core/proxy.rb +160 -4
  31. data/lib/openhab/core/rules/registry.rb +2 -2
  32. data/lib/openhab/core/rules/rule.rb +4 -8
  33. data/lib/openhab/core/script_handling.rb +2 -2
  34. data/lib/openhab/core/sitemaps/provider.rb +1 -1
  35. data/lib/openhab/core/things/channel.rb +0 -28
  36. data/lib/openhab/core/things/profile_callback.rb +3 -3
  37. data/lib/openhab/core/things/proxy.rb +8 -51
  38. data/lib/openhab/core/things/registry.rb +1 -1
  39. data/lib/openhab/core/things/thing.rb +3 -5
  40. data/lib/openhab/core/types/command_description.rb +31 -0
  41. data/lib/openhab/core/types/date_time_type.rb +5 -10
  42. data/lib/openhab/core/types/decimal_type.rb +1 -1
  43. data/lib/openhab/core/types/hsb_type.rb +3 -5
  44. data/lib/openhab/core/types/point_type.rb +1 -1
  45. data/lib/openhab/core/types/quantity_type.rb +22 -2
  46. data/lib/openhab/core/types/raw_type.rb +10 -4
  47. data/lib/openhab/core/types/state_description.rb +54 -0
  48. data/lib/openhab/core/types/time_series.rb +0 -3
  49. data/lib/openhab/core/types.rb +2 -2
  50. data/lib/openhab/core/value_cache.rb +3 -3
  51. data/lib/openhab/core.rb +3 -5
  52. data/lib/openhab/core_ext/java/duration.rb +27 -8
  53. data/lib/openhab/core_ext/java/list.rb +1 -1
  54. data/lib/openhab/core_ext/java/local_date.rb +6 -2
  55. data/lib/openhab/core_ext/java/local_time.rb +4 -2
  56. data/lib/openhab/core_ext/java/map.rb +2 -2
  57. data/lib/openhab/core_ext/java/period.rb +9 -6
  58. data/lib/openhab/core_ext/java/temporal_amount.rb +5 -0
  59. data/lib/openhab/core_ext/java/zoned_date_time.rb +12 -6
  60. data/lib/openhab/core_ext/ruby/date.rb +8 -7
  61. data/lib/openhab/core_ext/ruby/date_time.rb +2 -2
  62. data/lib/openhab/core_ext/ruby/time.rb +2 -2
  63. data/lib/openhab/core_ext.rb +1 -1
  64. data/lib/openhab/dsl/config_description/builder.rb +1 -1
  65. data/lib/openhab/dsl/items/builder.rb +5 -13
  66. data/lib/openhab/dsl/items/ensure.rb +3 -5
  67. data/lib/openhab/dsl/items/timed_command.rb +4 -4
  68. data/lib/openhab/dsl/rules/automation_rule.rb +3 -3
  69. data/lib/openhab/dsl/rules/builder.rb +40 -52
  70. data/lib/openhab/dsl/rules/rule_triggers.rb +1 -1
  71. data/lib/openhab/dsl/rules/triggers/changed.rb +16 -15
  72. data/lib/openhab/dsl/rules/triggers/channel.rb +1 -1
  73. data/lib/openhab/dsl/rules/triggers/command.rb +2 -2
  74. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +4 -4
  75. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +4 -14
  76. data/lib/openhab/dsl/rules/triggers/updated.rb +6 -6
  77. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +69 -124
  78. data/lib/openhab/dsl/sitemaps/builder.rb +7 -17
  79. data/lib/openhab/dsl/things/builder.rb +8 -8
  80. data/lib/openhab/dsl/timer_manager.rb +2 -2
  81. data/lib/openhab/dsl/version.rb +1 -1
  82. data/lib/openhab/dsl.rb +14 -15
  83. data/lib/openhab/log.rb +3 -3
  84. data/lib/openhab/osgi.rb +1 -1
  85. data/lib/openhab/rspec/helpers.rb +3 -3
  86. data/lib/openhab/rspec/hooks.rb +2 -8
  87. data/lib/openhab/rspec/jruby.rb +1 -1
  88. data/lib/openhab/rspec/karaf.rb +5 -27
  89. data/lib/openhab/rspec/mocks/persistence_service.rb +5 -5
  90. data/lib/openhab/yard/html_helper.rb +1 -1
  91. data/lib/openhab/yard.rb +1 -1
  92. metadata +18 -13
  93. data/lib/openhab/core/items/semantics/tag_class_methods.rb +0 -73
  94. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +0 -118
@@ -96,7 +96,7 @@ module OpenHAB
96
96
  # @yieldparam [GroupItemBuilder] builder Item for further customization
97
97
  # @return [GroupItem]
98
98
  def group_item(*args, **kwargs, &block)
99
- item = GroupItemBuilder.new(*args, provider: provider, **kwargs)
99
+ item = GroupItemBuilder.new(*args, provider:, **kwargs)
100
100
  item.instance_eval(&block) if block
101
101
  result = provider.add(item)
102
102
  item.members.each do |i|
@@ -108,7 +108,7 @@ module OpenHAB
108
108
  private
109
109
 
110
110
  def item(*args, **kwargs, &block)
111
- item = ItemBuilder.new(*args, provider: provider, **kwargs)
111
+ item = ItemBuilder.new(*args, provider:, **kwargs)
112
112
  item.instance_eval(&block) if block
113
113
  r = provider.add(item)
114
114
  return Core::Items::Proxy.new(r) if r.is_a?(Item)
@@ -189,7 +189,7 @@ module OpenHAB
189
189
  attr_reader :provider
190
190
 
191
191
  def initialize(provider, update:)
192
- @provider = ProviderWrapper.new(Core::Items::Provider.current(provider), update: update)
192
+ @provider = ProviderWrapper.new(Core::Items::Provider.current(provider), update:)
193
193
  end
194
194
  end
195
195
 
@@ -216,9 +216,6 @@ module OpenHAB
216
216
  attr_accessor :dimension
217
217
  # Unit (for number items only)
218
218
  #
219
- # Due to {format} inference, setting the unit is cross-compatible with
220
- # openHAB 3.4 and 4.0.
221
- #
222
219
  # @return [String, nil]
223
220
  attr_reader :unit
224
221
  # The formatting pattern for the item's state
@@ -294,15 +291,10 @@ module OpenHAB
294
291
  #
295
292
  # @!visibility private
296
293
  def normalize_tags(*tags)
297
- # @deprecated OH3.4 didn't have SemanticTag
298
- old_semantics = proc { |tag| tag.is_a?(Module) && tag < Semantics::Tag }
299
- # @deprecated OH3.4 defined? check is unnecessary
300
- semantics = proc { |tag| defined?(Semantics::SemanticTag) && tag.is_a?(Semantics::SemanticTag) }
301
-
302
294
  tags.compact.map do |tag|
303
295
  case tag
304
296
  when String then tag
305
- when Symbol, semantics, old_semantics then tag.to_s
297
+ when Symbol, Semantics::SemanticTag then tag.to_s
306
298
  else raise ArgumentError, "`#{tag}` must be a subclass of Semantics::Tag, a `Symbol`, or a `String`."
307
299
  end
308
300
  end
@@ -793,7 +785,7 @@ module OpenHAB
793
785
  RUBY
794
786
  end
795
787
 
796
- FUNCTION_REGEX = /^([a-z]+)(?:\((.*)\))?/i.freeze
788
+ FUNCTION_REGEX = /^([a-z]+)(?:\((.*)\))?/i
797
789
  private_constant :FUNCTION_REGEX
798
790
 
799
791
  # The combiner function for this group
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "ruby2_keywords"
4
-
5
3
  module OpenHAB
6
4
  module DSL
7
5
  module Items
@@ -29,7 +27,7 @@ module OpenHAB
29
27
  module Item
30
28
  include Ensurable
31
29
 
32
- Core::Items::GenericItem.prepend(self)
30
+ Core::Items::Item.prepend(self)
33
31
 
34
32
  # If `ensure_states` is active (by block or chained method), then
35
33
  # check if this item is in the command's state before actually
@@ -85,11 +83,11 @@ module OpenHAB
85
83
  end
86
84
 
87
85
  # activate `ensure_states` before forwarding to the wrapped object
88
- ruby2_keywords def method_missing(method, *args, &block)
86
+ def method_missing(method, ...)
89
87
  return super unless @item.respond_to?(method)
90
88
 
91
89
  DSL.ensure_states do
92
- @item.__send__(method, *args, &block)
90
+ @item.__send__(method, ...)
93
91
  end
94
92
  end
95
93
 
@@ -100,7 +100,7 @@ module OpenHAB
100
100
  attr_reader :timed_commands
101
101
  end
102
102
 
103
- Core::Items::GenericItem.prepend(self)
103
+ Core::Items::Item.prepend(self)
104
104
  Core::Items::GroupItem.prepend(self)
105
105
 
106
106
  #
@@ -159,11 +159,11 @@ module OpenHAB
159
159
  on_expire ||= default_on_expire(command)
160
160
  if only_when_ensured
161
161
  DSL.ensure_states do
162
- create_timed_command(command, duration: duration, on_expire: on_expire) if super(command, **kwargs)
162
+ create_timed_command(command, duration:, on_expire:) if super(command, **kwargs)
163
163
  end
164
164
  else
165
165
  super(command, **kwargs)
166
- create_timed_command(command, duration: duration, on_expire: on_expire)
166
+ create_timed_command(command, duration:, on_expire:)
167
167
  end
168
168
  end
169
169
 
@@ -201,7 +201,7 @@ module OpenHAB
201
201
  # Creates a new timed command and places it in the TimedCommand hash
202
202
  def create_timed_command(command, duration:, on_expire:)
203
203
  timed_command_details = TimedCommandDetails.new(item: self,
204
- on_expire: on_expire,
204
+ on_expire:,
205
205
  mutex: Mutex.new)
206
206
 
207
207
  timed_command_details.timer = timed_command_timer(timed_command_details, duration)
@@ -9,7 +9,7 @@ module OpenHAB
9
9
  # @!visibility private
10
10
  class AutomationRule < org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule
11
11
  # @!visibility private
12
- INPUT_KEY_PATTERN = /^[a-z_]+[a-zA-Z0-9_]*$/.freeze
12
+ INPUT_KEY_PATTERN = /^[a-z_]+[a-zA-Z0-9_]*$/
13
13
 
14
14
  class << self
15
15
  #
@@ -83,7 +83,7 @@ module OpenHAB
83
83
  logger.trace("Execute called with mod (#{mod&.to_string}) and inputs (#{inputs.inspect})")
84
84
  logger.trace("Event details #{inputs["event"].inspect}") if inputs&.key?("event")
85
85
  end
86
- trigger_conditions(inputs).process(mod: mod, inputs: inputs) do
86
+ trigger_conditions(inputs).process(mod:, inputs:) do
87
87
  event = extract_event(inputs)
88
88
  @debouncer.call { process_queue(create_queue(event), mod, event) }
89
89
  end
@@ -120,7 +120,7 @@ module OpenHAB
120
120
  # @return [Queue] <description>
121
121
  #
122
122
  def create_queue(event)
123
- case check_guards(event: event)
123
+ case check_guards(event:)
124
124
  when true
125
125
  @run_queue.dup.grep_v(BuilderDSL::Otherwise)
126
126
  when false
@@ -7,7 +7,7 @@ require_relative "guard"
7
7
  require_relative "rule_triggers"
8
8
  require_relative "terse"
9
9
 
10
- Dir[File.expand_path("triggers/*.rb", __dir__)].sort.each do |f|
10
+ Dir[File.expand_path("triggers/*.rb", __dir__)].each do |f|
11
11
  require f
12
12
  end
13
13
 
@@ -76,7 +76,6 @@ module OpenHAB
76
76
  def rule(name = nil, id: nil, replace: nil, script: nil, binding: nil, &block)
77
77
  raise ArgumentError, "Block is required" unless block
78
78
 
79
- inferred_id = nil
80
79
  id ||= inferred_id = NameInference.infer_rule_id_from_block(block)
81
80
  script ||= block.source rescue nil # rubocop:disable Style/RescueModifier
82
81
 
@@ -158,7 +157,7 @@ module OpenHAB
158
157
  def script(name = nil, description: nil, id: nil, tag: nil, tags: nil, replace: false, script: nil, &block)
159
158
  raise ArgumentError, "Block is required" unless block
160
159
 
161
- inferred_id = nil # rubocop:disable Lint/UselessAssignment it is used below
160
+ inferred_id = nil # rubocop:disable Lint/UselessAssignment -- it is used below
162
161
  id ||= inferred_id = NameInference.infer_rule_id_from_block(block)
163
162
  name ||= id
164
163
  script ||= block.source rescue nil # rubocop:disable Style/RescueModifier
@@ -749,7 +748,7 @@ module OpenHAB
749
748
  #
750
749
  def debounce_for(debounce_time)
751
750
  idle_time = debounce_time.is_a?(Range) ? debounce_time.begin : debounce_time
752
- debounce(for: debounce_time, idle_time: idle_time)
751
+ debounce(for: debounce_time, idle_time:)
753
752
  end
754
753
  # rubocop:enable Layout/LineLength
755
754
 
@@ -981,12 +980,12 @@ module OpenHAB
981
980
  #
982
981
  def channel(*channels, thing: nil, triggered: nil, attach: nil)
983
982
  channel_trigger = Channel.new(rule_triggers: @rule_triggers)
984
- flattened_channels = Channel.channels(channels: channels, thing: thing)
983
+ flattened_channels = Channel.channels(channels:, thing:)
985
984
  triggers = [triggered].flatten
986
- @ruby_triggers << [:channel, flattened_channels, { triggers: triggers }]
985
+ @ruby_triggers << [:channel, flattened_channels, { triggers: }]
987
986
  flattened_channels.each do |channel|
988
987
  triggers.each do |trigger|
989
- channel_trigger.trigger(channel: channel, trigger: trigger, attach: attach)
988
+ channel_trigger.trigger(channel:, trigger:, attach:)
990
989
  end
991
990
  end
992
991
  end
@@ -1014,7 +1013,7 @@ module OpenHAB
1014
1013
  def channel_linked(item: nil, channel: nil, attach: nil)
1015
1014
  pattern = (item.nil? && channel.nil?) ? "*" : "#{item || "*"}-#{channel || "*"}"
1016
1015
  @ruby_triggers << [:channel_linked, pattern]
1017
- event("openhab/links/#{pattern}/added", types: "ItemChannelLinkAddedEvent", attach: attach)
1016
+ event("openhab/links/#{pattern}/added", types: "ItemChannelLinkAddedEvent", attach:)
1018
1017
  end
1019
1018
 
1020
1019
  #
@@ -1043,7 +1042,7 @@ module OpenHAB
1043
1042
  def channel_unlinked(item: nil, channel: nil, attach: nil)
1044
1043
  pattern = (item.nil? && channel.nil?) ? "*" : "#{item || "*"}-#{channel || "*"}"
1045
1044
  @ruby_triggers << [:channel_unlinked, pattern]
1046
- event("openhab/links/#{pattern}/removed", types: "ItemChannelLinkRemovedEvent", attach: attach)
1045
+ event("openhab/links/#{pattern}/removed", types: "ItemChannelLinkRemovedEvent", attach:)
1047
1046
  end
1048
1047
 
1049
1048
  #
@@ -1166,7 +1165,7 @@ module OpenHAB
1166
1165
  # for is a reserved word in ruby, so use local_variable_get :for
1167
1166
  duration = binding.local_variable_get(:for)
1168
1167
 
1169
- @ruby_triggers << [:changed, items, { to: to, from: from, duration: duration }]
1168
+ @ruby_triggers << [:changed, items, { to:, from:, duration: }]
1170
1169
 
1171
1170
  from = [nil] if from.nil?
1172
1171
  to = [nil] if to.nil?
@@ -1187,7 +1186,7 @@ module OpenHAB
1187
1186
 
1188
1187
  Array.wrap(from).each do |from_state|
1189
1188
  Array.wrap(to).each do |to_state|
1190
- changed.trigger(item: item, from: from_state, to: to_state, duration: duration, attach: attach)
1189
+ changed.trigger(item:, from: from_state, to: to_state, duration:, attach:)
1191
1190
  end
1192
1191
  end
1193
1192
  end
@@ -1264,13 +1263,13 @@ module OpenHAB
1264
1263
  raise ArgumentError, "Cron elements cannot be used with a cron expression" if expression
1265
1264
 
1266
1265
  cron_expression = Cron.from_fields(fields)
1267
- return cron(cron_expression, attach: attach)
1266
+ return cron(cron_expression, attach:)
1268
1267
  end
1269
1268
 
1270
1269
  raise ArgumentError, "Missing cron expression or elements" unless expression
1271
1270
 
1272
1271
  cron = Cron.new(rule_triggers: @rule_triggers)
1273
- cron.trigger(config: { "cronExpression" => expression }, attach: attach)
1272
+ cron.trigger(config: { "cronExpression" => expression }, attach:)
1274
1273
  end
1275
1274
 
1276
1275
  #
@@ -1387,8 +1386,8 @@ module OpenHAB
1387
1386
  raise ArgumentError, "Offset can only be used when 'at' is given a DateTimeItem" if offset && !at.is_a?(Item)
1388
1387
 
1389
1388
  if Cron.all_dow_symbols?(values)
1390
- @ruby_triggers << [:every, values.join(", "), { at: at }]
1391
- return cron(Cron.from_dow_symbols(values, at), attach: attach)
1389
+ @ruby_triggers << [:every, values.join(", "), { at: }]
1390
+ return cron(Cron.from_dow_symbols(values, at), attach:)
1392
1391
  end
1393
1392
 
1394
1393
  if values.size != 1
@@ -1400,18 +1399,13 @@ module OpenHAB
1400
1399
  value = values.first
1401
1400
  value = java.time.MonthDay.parse(value.to_str) if value.respond_to?(:to_str)
1402
1401
 
1403
- @ruby_triggers << [:every, value, { at: at }]
1402
+ @ruby_triggers << [:every, value, { at: }]
1404
1403
 
1405
1404
  if value == :day && at.is_a?(Item)
1406
- # @deprecated OH 3.4 - attachments are supported in OH 4.0+
1407
- if Core.version <= Core::V4_0 && !attach.nil?
1408
- raise ArgumentError, "Attachments are not supported with dynamic datetime triggers in openHAB 3.x"
1409
- end
1410
-
1411
1405
  offset ||= 0
1412
1406
  offset = offset.to_i # Duration#to_i converts it to seconds, but we also want to convert float/string to int
1413
1407
  @ruby_triggers.last[2][:offset] = offset
1414
- return trigger("timer.DateTimeTrigger", itemName: at.name, timeOnly: true, offset: offset, attach: attach)
1408
+ return trigger("timer.DateTimeTrigger", itemName: at.name, timeOnly: true, offset:, attach:)
1415
1409
  end
1416
1410
 
1417
1411
  cron_expression = case value
@@ -1420,7 +1414,7 @@ module OpenHAB
1420
1414
  when java.time.MonthDay then Cron.from_monthday(value, at)
1421
1415
  else raise ArgumentError, "Unknown interval"
1422
1416
  end
1423
- cron(cron_expression, attach: attach)
1417
+ cron(cron_expression, attach:)
1424
1418
  end
1425
1419
 
1426
1420
  #
@@ -1453,7 +1447,7 @@ module OpenHAB
1453
1447
  # prevent overwriting @on_load
1454
1448
  raise ArgumentError, "on_load can only be used once within a rule" if @on_load
1455
1449
 
1456
- @on_load = { module: SecureRandom.uuid, delay: delay }
1450
+ @on_load = { module: SecureRandom.uuid, delay: }
1457
1451
  attachments[@on_load[:module]] = attach
1458
1452
  end
1459
1453
 
@@ -1525,7 +1519,7 @@ module OpenHAB
1525
1519
  config = { startlevel: level }
1526
1520
  logger.trace { "Creating a SystemStartlevelTrigger with startlevel=#{level}" }
1527
1521
  Triggers::Trigger.new(rule_triggers: @rule_triggers)
1528
- .append_trigger(type: "core.SystemStartlevelTrigger", config: config, attach: attach)
1522
+ .append_trigger(type: "core.SystemStartlevelTrigger", config:, attach:)
1529
1523
  end
1530
1524
  end
1531
1525
 
@@ -1624,7 +1618,7 @@ module OpenHAB
1624
1618
  commands.each do |cmd|
1625
1619
  logger.trace { "Creating received command trigger for items #{item.inspect} and commands #{cmd.inspect}" }
1626
1620
 
1627
- command_trigger.trigger(item: item, command: cmd, attach: attach)
1621
+ command_trigger.trigger(item:, command: cmd, attach:)
1628
1622
  end
1629
1623
  end
1630
1624
  end
@@ -1649,7 +1643,7 @@ module OpenHAB
1649
1643
  # end
1650
1644
  def item_added(pattern = "*", attach: nil)
1651
1645
  @ruby_triggers << [:item_added, pattern]
1652
- event("openhab/items/#{pattern}/added", types: "ItemAddedEvent", attach: attach)
1646
+ event("openhab/items/#{pattern}/added", types: "ItemAddedEvent", attach:)
1653
1647
  end
1654
1648
 
1655
1649
  #
@@ -1672,7 +1666,7 @@ module OpenHAB
1672
1666
  # end
1673
1667
  def item_removed(pattern = "*", attach: nil)
1674
1668
  @ruby_triggers << [:item_removed, pattern]
1675
- event("openhab/items/#{pattern}/removed", types: "ItemRemovedEvent", attach: attach)
1669
+ event("openhab/items/#{pattern}/removed", types: "ItemRemovedEvent", attach:)
1676
1670
  end
1677
1671
 
1678
1672
  #
@@ -1694,7 +1688,7 @@ module OpenHAB
1694
1688
  #
1695
1689
  def item_updated(pattern = "*", attach: nil)
1696
1690
  @ruby_triggers << [:item_updated, pattern]
1697
- event("openhab/items/#{pattern}/updated", types: "ItemUpdatedEvent", attach: attach)
1691
+ event("openhab/items/#{pattern}/updated", types: "ItemUpdatedEvent", attach:)
1698
1692
  end
1699
1693
 
1700
1694
  #
@@ -1717,7 +1711,7 @@ module OpenHAB
1717
1711
  # end
1718
1712
  def thing_added(pattern = "*", attach: nil)
1719
1713
  @ruby_triggers << [:thing_added, pattern]
1720
- event("openhab/things/#{pattern}/added", types: "ThingAddedEvent", attach: attach)
1714
+ event("openhab/things/#{pattern}/added", types: "ThingAddedEvent", attach:)
1721
1715
  end
1722
1716
 
1723
1717
  #
@@ -1740,7 +1734,7 @@ module OpenHAB
1740
1734
  # end
1741
1735
  def thing_removed(pattern = "*", attach: nil)
1742
1736
  @ruby_triggers << [:thing_removed, pattern]
1743
- event("openhab/things/#{pattern}/removed", types: "ThingRemovedEvent", attach: attach)
1737
+ event("openhab/things/#{pattern}/removed", types: "ThingRemovedEvent", attach:)
1744
1738
  end
1745
1739
 
1746
1740
  #
@@ -1764,7 +1758,7 @@ module OpenHAB
1764
1758
  #
1765
1759
  def thing_updated(pattern = "*", attach: nil)
1766
1760
  @ruby_triggers << [:thing_updated, pattern]
1767
- event("openhab/things/#{pattern}/updated", types: "ThingUpdatedEvent", attach: attach)
1761
+ event("openhab/things/#{pattern}/updated", types: "ThingUpdatedEvent", attach:)
1768
1762
  end
1769
1763
 
1770
1764
  #
@@ -1787,16 +1781,11 @@ module OpenHAB
1787
1781
  #
1788
1782
  def event(topic, source: nil, types: nil, attach: nil)
1789
1783
  types = types.join(",") if types.is_a?(Enumerable)
1790
- # @deprecated OH3.4 - OH3 config uses eventXXX vs OH4 uses `topic`, `source`, and `types`
1791
- # See https://github.com/openhab/openhab-core/pull/3299
1792
1784
  trigger("core.GenericEventTrigger",
1793
- eventTopic: topic,
1794
- eventSource: source,
1795
- eventTypes: types, # @deprecated OH3.4
1796
- topic: topic,
1797
- source: source,
1798
- types: types,
1799
- attach: attach)
1785
+ topic:,
1786
+ source:,
1787
+ types:,
1788
+ attach:)
1800
1789
  end
1801
1790
 
1802
1791
  #
@@ -1845,8 +1834,8 @@ module OpenHAB
1845
1834
  item = item.name if item.is_a?(Item)
1846
1835
  offset ||= 0
1847
1836
  offset = offset.to_i if offset.is_a?(Duration)
1848
- @ruby_triggers << [:at, item, { offset: offset }]
1849
- trigger("timer.DateTimeTrigger", itemName: item.to_s, offset: offset)
1837
+ @ruby_triggers << [:at, item, { offset: }]
1838
+ trigger("timer.DateTimeTrigger", itemName: item.to_s, offset:)
1850
1839
  end
1851
1840
 
1852
1841
  #
@@ -1888,7 +1877,7 @@ module OpenHAB
1888
1877
  def trigger(type, attach: nil, **configuration)
1889
1878
  logger.trace { "Creating trigger (#{type}) with configuration(#{configuration})" }
1890
1879
  Triggers::Trigger.new(rule_triggers: @rule_triggers)
1891
- .append_trigger(type: type, config: configuration, attach: attach)
1880
+ .append_trigger(type:, config: configuration, attach:)
1892
1881
  end
1893
1882
 
1894
1883
  #
@@ -1977,7 +1966,7 @@ module OpenHAB
1977
1966
  #
1978
1967
  def updated(*items, to: nil, attach: nil)
1979
1968
  updated = Updated.new(rule_triggers: @rule_triggers)
1980
- @ruby_triggers << [:updated, items, { to: to }]
1969
+ @ruby_triggers << [:updated, items, { to: }]
1981
1970
  items.map do |item|
1982
1971
  case item
1983
1972
  when Core::Things::Thing,
@@ -1991,7 +1980,7 @@ module OpenHAB
1991
1980
 
1992
1981
  logger.trace { "Creating updated trigger for item(#{item}) to(#{to})" }
1993
1982
  [to].flatten.map do |to_state|
1994
- updated.trigger(item: item, to: to_state, attach: attach)
1983
+ updated.trigger(item:, to: to_state, attach:)
1995
1984
  end
1996
1985
  end.flatten
1997
1986
  end
@@ -2027,7 +2016,7 @@ module OpenHAB
2027
2016
  items.map do |item|
2028
2017
  raise ArgumentError, "items must be an Item or GroupItem::Members" unless item.is_a?(Core::Items::Item)
2029
2018
 
2030
- event("openhab/items/#{item.name}/timeseriesupdated", types: "ItemTimeSeriesUpdatedEvent", attach: attach)
2019
+ event("openhab/items/#{item.name}/timeseriesupdated", types: "ItemTimeSeriesUpdatedEvent", attach:)
2031
2020
  end
2032
2021
  end
2033
2022
 
@@ -2062,8 +2051,7 @@ module OpenHAB
2062
2051
  # @param [String] path Path to watch. Can be a directory or a file.
2063
2052
  # @param [String] glob
2064
2053
  # Limit events to paths matching this glob. Globs are matched using `glob`
2065
- # [PathMatcher](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String))
2066
- # rules.
2054
+ # {java.nio.file.FileSystem#getPathMatcher(java.lang.String) PathMatcher} rules.
2067
2055
  # @param [Array<:created, :deleted, :modified>, :created, :deleted, :modified] for
2068
2056
  # Types of changes to watch for.
2069
2057
  # @param [Object] attach object to be attached to the trigger
@@ -2125,7 +2113,7 @@ module OpenHAB
2125
2113
  path: path.to_s,
2126
2114
  types: types.map(&:to_s),
2127
2115
  glob: glob.to_s,
2128
- attach: attach)
2116
+ attach:)
2129
2117
  end
2130
2118
 
2131
2119
  # @!endgroup
@@ -2207,7 +2195,7 @@ module OpenHAB
2207
2195
  #
2208
2196
  def create_rule?
2209
2197
  @tags = DSL::Items::ItemBuilder.normalize_tags(*tags)
2210
- return true unless (tags & %w[Script Scene]).empty?
2198
+ return true if tags.intersect?(%w[Script Scene])
2211
2199
 
2212
2200
  if !triggers?
2213
2201
  logger.warn "Rule '#{uid}' has no triggers, not creating rule"
@@ -2279,7 +2267,7 @@ module OpenHAB
2279
2267
 
2280
2268
  interval = binding.local_variable_get(:for)
2281
2269
  # This hash structure must match the parameter signature for Debouncer.new
2282
- @debounce_settings = { for: interval, leading: leading, idle_time: idle_time }
2270
+ @debounce_settings = { for: interval, leading:, idle_time: }
2283
2271
  end
2284
2272
  end
2285
2273
  end
@@ -43,7 +43,7 @@ module OpenHAB
43
43
  #
44
44
  def append_trigger(type:, config:, attach: nil, conditions: nil, label: nil)
45
45
  config.transform_keys!(&:to_s)
46
- RuleTriggers.trigger(type: type, config: config, label: label).tap do |trigger|
46
+ RuleTriggers.trigger(type:, config:, label:).tap do |trigger|
47
47
  logger.trace { "Appending trigger (#{trigger.inspect}) attach (#{attach}) conditions(#{conditions})" }
48
48
  @triggers << trigger
49
49
  @attachments[trigger.id] = attach if attach
@@ -31,14 +31,14 @@ module OpenHAB
31
31
  logger.trace("Creating Changed Wait Change Trigger for Item(#{item_name}) Duration(#{duration}) " \
32
32
  "To(#{to}) From(#{from}) Attach(#{attach})")
33
33
  end
34
- conditions = Conditions::Duration.new(to: to, from: from, duration: duration)
34
+ conditions = Conditions::Duration.new(to:, from:, duration:)
35
35
  label = NameInference.infer_rule_name_from_trigger(:changed,
36
36
  [item],
37
- from: from,
38
- to: to,
39
- duration: duration)
37
+ from:,
38
+ to:,
39
+ duration:)
40
40
 
41
- changed_trigger(item: item, from: nil, to: nil, attach: attach, conditions: conditions, label: label)
41
+ changed_trigger(item:, from: nil, to: nil, attach:, conditions:, label:)
42
42
  else
43
43
  # swap from/to w/ nil if from/to need to be processed in Ruby
44
44
  # rubocop:disable Style/ParallelAssignment
@@ -46,19 +46,20 @@ module OpenHAB
46
46
  to_proc, to = to, nil unless Conditions.state?(to)
47
47
  # rubocop:enable Style/ParallelAssignment
48
48
  conditions = Conditions::Generic.new(from: from_proc, to: to_proc) unless from_proc.nil? && to_proc.nil?
49
- changed_trigger(item: item, from: from, to: to, attach: attach, conditions: conditions)
49
+ changed_trigger(item:, from:, to:, attach:, conditions:)
50
50
  end
51
51
  end
52
52
 
53
+ # @!visibility private
54
+ # @return [String] An item state change trigger
55
+ ITEM_STATE_CHANGE = "core.ItemStateChangeTrigger"
56
+
53
57
  private
54
58
 
55
59
  # @return [String] A thing status Change trigger
56
60
  THING_CHANGE = "core.ThingStatusChangeTrigger"
57
61
  private_constant :THING_CHANGE
58
62
 
59
- # @return [String] An item state change trigger
60
- ITEM_STATE_CHANGE = "core.ItemStateChangeTrigger"
61
-
62
63
  # @return [String] A group state change trigger for items in the group
63
64
  GROUP_STATE_CHANGE = "core.GroupStateChangeTrigger"
64
65
  private_constant :GROUP_STATE_CHANGE
@@ -75,16 +76,16 @@ module OpenHAB
75
76
  def changed_trigger(item:, from:, to:, attach: nil, conditions: nil, label: nil)
76
77
  type, config = case item
77
78
  when GroupItem::Members
78
- group(group: item, from: from, to: to)
79
+ group(group: item, from:, to:)
79
80
  when Core::Things::Thing,
80
81
  Core::Things::ThingUID
81
- thing(thing: item, from: from, to: to)
82
+ thing(thing: item, from:, to:)
82
83
  when Core::Things::Registry
83
- thing(thing: "*", from: from, to: to)
84
+ thing(thing: "*", from:, to:)
84
85
  else
85
- item(item: item, from: from, to: to)
86
+ item(item:, from:, to:)
86
87
  end
87
- append_trigger(type: type, config: config, attach: attach, conditions: conditions, label: label)
88
+ append_trigger(type:, config:, attach:, conditions:, label:)
88
89
  end
89
90
 
90
91
  #
@@ -98,7 +99,7 @@ module OpenHAB
98
99
  # second element is a Hash configuring trigger
99
100
  #
100
101
  def thing(thing:, from:, to:)
101
- trigger_for_thing(thing: thing, type: THING_CHANGE, to: to, from: from)
102
+ trigger_for_thing(thing:, type: THING_CHANGE, to:, from:)
102
103
  end
103
104
 
104
105
  #
@@ -48,7 +48,7 @@ module OpenHAB
48
48
  config = { "channelUID" => channel }
49
49
  config["event"] = trigger.to_s unless trigger.nil?
50
50
  logger.trace { "Creating Channel Trigger for channels #{channel.inspect} and config #{config.inspect}" }
51
- append_trigger(type: CHANNEL_EVENT, config: config, attach: attach)
51
+ append_trigger(type: CHANNEL_EVENT, config:, attach:)
52
52
  end
53
53
  end
54
54
  end
@@ -22,7 +22,7 @@ module OpenHAB
22
22
  #
23
23
  def trigger(item:, command:, attach:)
24
24
  unless Conditions.state?(command)
25
- conditions = Conditions::Generic.new(command: command)
25
+ conditions = Conditions::Generic.new(command:)
26
26
  command = nil
27
27
  end
28
28
 
@@ -32,7 +32,7 @@ module OpenHAB
32
32
  [ITEM_COMMAND, { "itemName" => item.name }]
33
33
  end
34
34
  config["command"] = command.to_s unless command.nil?
35
- append_trigger(type: type, config: config, attach: attach, conditions: conditions)
35
+ append_trigger(type:, config:, attach:, conditions:)
36
36
  end
37
37
 
38
38
  # @return [String] item command trigger
@@ -19,7 +19,7 @@ module OpenHAB
19
19
  # @param [java.time.temporal.TemporalAmount] duration to state must stay at specific value before triggering
20
20
  #
21
21
  def initialize(to:, from:, duration:)
22
- @conditions = Generic.new(to: to, from: from)
22
+ @conditions = Generic.new(to:, from:)
23
23
  @duration = duration
24
24
  @timers = {}
25
25
  logger.trace do
@@ -35,7 +35,7 @@ module OpenHAB
35
35
  timer = @timers[inputs["triggeringItem"]&.name]
36
36
  if timer&.active?
37
37
  process_active_timer(timer, inputs, mod, &block)
38
- elsif @conditions.process(mod: mod, inputs: inputs)
38
+ elsif @conditions.process(mod:, inputs:)
39
39
  logger.trace { "Trigger Guards Matched for #{self}, delaying rule execution" }
40
40
  # Add timer and attach timer to delay object, and also state being tracked to so
41
41
  # timer can be cancelled if state changes
@@ -80,7 +80,7 @@ module OpenHAB
80
80
  # @param [Hash] inputs rule trigger inputs
81
81
  # @param [Hash] mod rule trigger mods
82
82
  #
83
- def process_active_timer(timer, inputs, mod, &block)
83
+ def process_active_timer(timer, inputs, mod, &)
84
84
  old_state = Conditions.old_state_from(inputs)
85
85
  new_state = Conditions.new_state_from(inputs)
86
86
  if @conditions.from? && new_state != @tracking_from &&
@@ -90,7 +90,7 @@ module OpenHAB
90
90
  logger.trace { "Item changed from #{old_state} to #{new_state} for #{self}, canceling timer." }
91
91
  timer.cancel
92
92
  # Reprocess trigger delay after canceling to track new state (if guards matched, etc)
93
- process(mod: mod, inputs: inputs, &block)
93
+ process(mod:, inputs:, &)
94
94
  end
95
95
  end
96
96
  end