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
@@ -12,13 +12,7 @@ module OpenHAB
12
12
  #
13
13
  class Cron < Trigger
14
14
  # Trigger ID for Cron Triggers
15
- # @deprecated OH 3.4
16
- CRON_TRIGGER_MODULE_ID = if OpenHAB::Core.version >= OpenHAB::Core::V4_0
17
- "timer.GenericCronTrigger"
18
- else
19
- # @deprecated OH3.4 We need to use a custom CronTrigger handler
20
- "jsr223.jruby.CronTrigger"
21
- end
15
+ CRON_TRIGGER_MODULE_ID = "timer.GenericCronTrigger"
22
16
 
23
17
  #
24
18
  # Returns a default map for cron expressions that fires every second
@@ -125,7 +119,7 @@ module OpenHAB
125
119
  # @return [Boolean] true if all symbols are day-of-week symbols
126
120
  #
127
121
  def self.all_dow_symbols?(symbols)
128
- (symbols & DAY_OF_WEEK) == symbols
122
+ (symbols - DAY_OF_WEEK).empty?
129
123
  end
130
124
 
131
125
  #
@@ -138,7 +132,7 @@ module OpenHAB
138
132
  #
139
133
  def self.from_dow_symbols(symbols, at)
140
134
  dow = DAY_OF_WEEK_MAP.fetch_values(*symbols).join(",")
141
- expression_map = CRON_EXPRESSION_MAP.merge(dow: dow, hour: 0, minute: 0, second: 0)
135
+ expression_map = CRON_EXPRESSION_MAP.merge(dow:, hour: 0, minute: 0, second: 0)
142
136
  expression_map = at_condition(expression_map, at) if at
143
137
  map_to_cron(expression_map)
144
138
  end
@@ -239,11 +233,7 @@ module OpenHAB
239
233
  #
240
234
  #
241
235
  def trigger(config:, attach:)
242
- # @deprecated OH3.4 needs a custom CronTriggerHandlerFactory
243
- if OpenHAB::Core.version < OpenHAB::Core::V4_0
244
- CronHandler::CronTriggerHandlerFactory.instance # ensure it's registered
245
- end
246
- append_trigger(type: CRON_TRIGGER_MODULE_ID, config: config, attach: attach)
236
+ append_trigger(type: CRON_TRIGGER_MODULE_ID, config:, attach:)
247
237
  end
248
238
  end
249
239
  end
@@ -22,20 +22,20 @@ module OpenHAB
22
22
  #
23
23
  def trigger(item:, to:, attach:)
24
24
  unless Conditions.state?(to)
25
- conditions = Conditions::Generic.new(to: to)
25
+ conditions = Conditions::Generic.new(to:)
26
26
  to = nil
27
27
  end
28
28
 
29
29
  type, config = case item
30
30
  when GroupItem::Members
31
- group_update(item: item, to: to)
31
+ group_update(item:, to:)
32
32
  when Core::Things::Thing,
33
33
  Core::Things::ThingUID
34
- thing_update(thing: item, to: to)
34
+ thing_update(thing: item, to:)
35
35
  else
36
- item_update(item: item, to: to)
36
+ item_update(item:, to:)
37
37
  end
38
- append_trigger(type: type, config: config, attach: attach, conditions: conditions)
38
+ append_trigger(type:, config:, attach:, conditions:)
39
39
  end
40
40
 
41
41
  private
@@ -92,7 +92,7 @@ module OpenHAB
92
92
  # second element is a Hash configuring trigger
93
93
  #
94
94
  def thing_update(thing:, to:)
95
- trigger_for_thing(thing: thing, type: THING_UPDATE, to: to)
95
+ trigger_for_thing(thing:, type: THING_UPDATE, to:)
96
96
  end
97
97
  end
98
98
  end
@@ -21,138 +21,83 @@ module OpenHAB
21
21
  @factory ||= OSGi.service("org.openhab.core.service.WatchServiceFactory")
22
22
  end
23
23
 
24
- # Due to the refactoring in OH4, we need a different watcher implementation
25
- if WatchHandler.factory
26
- # A class that implements openHAB4's WatchEventListener
27
- # and also creates and removes a unique WatchService for each instance
28
- class Watcher
29
- # Use full java class name here to satisfy YARD linter
30
- include org.openhab.core.service.WatchService::WatchEventListener
31
- java_import org.openhab.core.service.WatchService
32
-
33
- # Hash of event symbols as strings to map to WatchService events
34
- STRING_TO_EVENT = {
35
- created: WatchService::Kind::CREATE,
36
- deleted: WatchService::Kind::DELETE,
37
- modified: WatchService::Kind::MODIFY
38
- }.transform_keys(&:to_s).freeze
39
-
40
- # Hash of WatchService event kinds to ruby symbols
41
- EVENT_TO_SYMBOL = STRING_TO_EVENT.invert.transform_values(&:to_sym).freeze
42
-
43
- # constructor
44
- def initialize(path, subdirs, types, &block)
45
- @types = types.map { |type| STRING_TO_EVENT[type] }
46
- @block = block
47
- @subdirs = subdirs
48
- @path = Pathname.new(path)
49
- @custom_watcher = nil
50
- return if path.to_s.start_with?(OpenHAB::Core.config_folder.to_s)
51
-
52
- @custom_watcher = "jrubyscripting-#{SecureRandom.uuid}"
53
- end
54
-
55
- # Creates a new Watch Service and registers ourself as a listener
56
- # This isn't an OSGi service, but it's called by {WatchTriggerHandler} below.
57
- def activate
58
- java_path = java.nio.file.Path.of(@path.to_s)
59
-
60
- service_name = WatchService::SERVICE_PID
61
- filter = if @custom_watcher
62
- WatchHandler.factory.create_watch_service(@custom_watcher, java_path)
63
- logger.trace { "Created a watch service #{@custom_watcher} for #{@path}" }
64
- "(name=#{@custom_watcher})"
65
- else
66
- logger.trace { "Using configWatcher service for #{@path}" }
67
- WatchService::CONFIG_WATCHER_FILTER
68
- end
69
-
70
- start = Time.now
71
- sleep 0.1 until (@watch_service = OSGi.service(service_name, filter: filter)) || Time.now - start > 2
72
-
73
- unless @watch_service
74
- logger.warn("Watch service is not ready in time. #{@path} will not be monitored!")
75
- return
76
- end
77
-
78
- @watch_service.register_listener(self, java_path, @subdirs)
79
- logger.trace { "Registered watch service listener for #{@path} including subdirs: #{@subdirs}" }
80
- end
81
-
82
- # Unregister ourself as a listener and remove the watch service
83
- def deactivate
84
- @watch_service&.unregister_listener(self)
85
- return unless @custom_watcher
24
+ # A class that implements openHAB4's WatchEventListener
25
+ # and also creates and removes a unique WatchService for each instance
26
+ class Watcher
27
+ # Use full java class name here to satisfy YARD linter
28
+ include org.openhab.core.service.WatchService::WatchEventListener
29
+ java_import org.openhab.core.service.WatchService
30
+
31
+ # Hash of event symbols as strings to map to WatchService events
32
+ STRING_TO_EVENT = {
33
+ created: WatchService::Kind::CREATE,
34
+ deleted: WatchService::Kind::DELETE,
35
+ modified: WatchService::Kind::MODIFY
36
+ }.transform_keys(&:to_s).freeze
37
+
38
+ # Hash of WatchService event kinds to ruby symbols
39
+ EVENT_TO_SYMBOL = STRING_TO_EVENT.invert.transform_values(&:to_sym).freeze
40
+
41
+ # constructor
42
+ def initialize(path, subdirs, types, &block)
43
+ @types = types.map { |type| STRING_TO_EVENT[type] }
44
+ @block = block
45
+ @subdirs = subdirs
46
+ @path = Pathname.new(path)
47
+ @custom_watcher = nil
48
+ return if path.to_s.start_with?(OpenHAB::Core.config_folder.to_s)
49
+
50
+ @custom_watcher = "jrubyscripting-#{SecureRandom.uuid}"
51
+ end
86
52
 
87
- WatchHandler.factory.remove_watch_service(@custom_watcher)
88
- logger.trace { "Removed watch service #{@custom_watcher} for #{@path}" }
53
+ # Creates a new Watch Service and registers ourself as a listener
54
+ # This isn't an OSGi service, but it's called by {WatchTriggerHandler} below.
55
+ def activate
56
+ java_path = java.nio.file.Path.of(@path.to_s)
57
+
58
+ service_name = WatchService::SERVICE_PID
59
+ filter = if @custom_watcher
60
+ WatchHandler.factory.create_watch_service(@custom_watcher, java_path)
61
+ logger.trace { "Created a watch service #{@custom_watcher} for #{@path}" }
62
+ "(name=#{@custom_watcher})"
63
+ else
64
+ logger.trace { "Using configWatcher service for #{@path}" }
65
+ WatchService::CONFIG_WATCHER_FILTER
66
+ end
67
+
68
+ start = Time.now
69
+ sleep 0.1 until (@watch_service = OSGi.service(service_name, filter:)) || Time.now - start > 2
70
+
71
+ unless @watch_service
72
+ logger.warn("Watch service is not ready in time. #{@path} will not be monitored!")
73
+ return
89
74
  end
90
75
 
91
- # Invoked by the WatchService when a watch event occurs
92
- # @param [org.openhab.core.service.WatchService.Kind] kind WatchService event kind
93
- # @param [java.nio.file.Path] path The path that had an event
94
- def processWatchEvent(kind, path) # rubocop:disable Naming/MethodName
95
- logger.trace { "processWatchEvent triggered #{path} #{kind} #{@types}" }
96
- return unless @types.include?(kind)
97
-
98
- # OH4 WatchService feeds us a relative path,
99
- # but just in case its implementation changes in the future
100
- path = path.absolute? ? Pathname.new(path.to_s) : @path + path.to_s
101
- @block.call(Events::WatchEvent.new(EVENT_TO_SYMBOL[kind], path))
102
- end
76
+ @watch_service.register_listener(self, java_path, @subdirs)
77
+ logger.trace { "Registered watch service listener for #{@path} including subdirs: #{@subdirs}" }
103
78
  end
104
- else
105
- # @deprecated OH3.4
106
- #
107
- # Extends the openHAB3 watch service to watch directories
108
- #
109
- # Must match java method name style
110
- # rubocop:disable Naming/MethodName
111
- class Watcher < org.openhab.core.service.AbstractWatchService
112
- java_import java.nio.file.StandardWatchEventKinds
113
-
114
- # Hash of event symbols as strings to map to NIO events
115
- STRING_TO_EVENT = {
116
- created: StandardWatchEventKinds::ENTRY_CREATE,
117
- deleted: StandardWatchEventKinds::ENTRY_DELETE,
118
- modified: StandardWatchEventKinds::ENTRY_MODIFY
119
- }.transform_keys(&:to_s).freeze
120
-
121
- # Hash of NIO event kinds to ruby symbols
122
- EVENT_TO_SYMBOL = STRING_TO_EVENT.invert.transform_values(&:to_sym).freeze
123
-
124
- # Creates a new Watch Service
125
- def initialize(path, subdirs, types, &block)
126
- super(path)
127
- @types = types.map { |type| STRING_TO_EVENT[type] }
128
- @block = block
129
- @subdirs = subdirs
130
- end
131
79
 
132
- # Invoked by java super class to get type of events to watch for
133
- # @param [String] _path ignored
134
- #
135
- # @return [Array] array of NIO event kinds
136
- def getWatchEventKinds(_path)
137
- @types
138
- end
80
+ # Unregister ourself as a listener and remove the watch service
81
+ def deactivate
82
+ @watch_service&.unregister_listener(self)
83
+ return unless @custom_watcher
139
84
 
140
- # Invoked by java super class to check if sub directories should be watched
141
- # @return [false] false
142
- def watchSubDirectories
143
- logger.trace { "watchSubDirectories returning #{@subdirs}" }
144
- @subdirs
145
- end
85
+ WatchHandler.factory.remove_watch_service(@custom_watcher)
86
+ logger.trace { "Removed watch service #{@custom_watcher} for #{@path}" }
87
+ end
146
88
 
147
- # Invoked by java super class when a watch event occurs
148
- # @param [String] _event ignored
149
- # @param [StandardWatchEventKind] kind NIO watch event kind
150
- # @param [java.nio.file.Path] path that had an event
151
- def processWatchEvent(_event, kind, path)
152
- @block.call(Events::WatchEvent.new(EVENT_TO_SYMBOL[kind], Pathname.new(path.to_s)))
153
- end
89
+ # Invoked by the WatchService when a watch event occurs
90
+ # @param [org.openhab.core.service.WatchService.Kind] kind WatchService event kind
91
+ # @param [java.nio.file.Path] path The path that had an event
92
+ def processWatchEvent(kind, path) # rubocop:disable Naming/MethodName
93
+ logger.trace { "processWatchEvent triggered #{path} #{kind} #{@types}" }
94
+ return unless @types.include?(kind)
95
+
96
+ # OH4 WatchService feeds us a relative path,
97
+ # but just in case its implementation changes in the future
98
+ path = path.absolute? ? Pathname.new(path.to_s) : @path + path.to_s
99
+ @block.call(Events::WatchEvent.new(EVENT_TO_SYMBOL[kind], path))
154
100
  end
155
- # rubocop:enable Naming/MethodName
156
101
  end
157
102
 
158
103
  # Implements the openHAB TriggerHandler interface to process Watch Triggers
@@ -49,7 +49,7 @@ module OpenHAB
49
49
  # @return [SitemapBuilder]
50
50
  # @!visibility public
51
51
  def sitemap(name, label: nil, icon: nil, &block)
52
- sitemap = SitemapBuilder.new(name, @builder_proxy, label: label, icon: icon, &block)
52
+ sitemap = SitemapBuilder.new(name, @builder_proxy, label:, icon:, &block)
53
53
  sitemap = sitemap.build
54
54
  if @update && @provider.get(sitemap.uid)
55
55
  @provider.update(sitemap)
@@ -67,9 +67,7 @@ module OpenHAB
67
67
  # This is copied out of UIComponentSitemapProvider.java
68
68
  # The original pattern will match plain state e.g. "ON" as item="O" and state="N"
69
69
  # this pattern is modified so it matches as item=nil and state="ON" by using atomic grouping `(?>subexpression)`
70
- # rubocop:disable Layout/LineLength
71
- CONDITION_PATTERN = /(?>(?<item>[A-Za-z]\w*)?\s*(?<condition>==|!=|<=|>=|<|>))?\s*(?<sign>\+|-)?(?<state>.+)/.freeze
72
- # rubocop:enable Layout/LineLength
70
+ CONDITION_PATTERN = /(?>(?<item>[A-Za-z]\w*)?\s*(?<condition>==|!=|<=|>=|<|>))?\s*(?<sign>\+|-)?(?<state>.+)/
73
71
  private_constant :CONDITION_PATTERN
74
72
 
75
73
  # @return [String, nil]
@@ -242,7 +240,7 @@ module OpenHAB
242
240
 
243
241
  # @!visibility private
244
242
  def inspect
245
- s = +"#<OpenHAB::DSL::Sitemaps::#{@type.capitalize}Builder "
243
+ s = "#<OpenHAB::DSL::Sitemaps::#{@type.capitalize}Builder "
246
244
  s << (instance_variables - [:@children]).map do |iv|
247
245
  "#{iv}=#{instance_variable_get(iv).inspect}"
248
246
  end.join(" ")
@@ -272,10 +270,6 @@ module OpenHAB
272
270
  return if conditions.empty?
273
271
 
274
272
  object = widget.send(method)
275
- # @deprecated OH 4.0
276
- if conditions.any?(Array) && !SitemapBuilder.factory.respond_to?(:create_condition)
277
- raise ArgumentError, "AND conditions not supported prior to openHAB 4.1"
278
- end
279
273
 
280
274
  conditions.each do |sub_conditions|
281
275
  container = SitemapBuilder.factory.send(container_method)
@@ -287,9 +281,6 @@ module OpenHAB
287
281
  end
288
282
 
289
283
  def add_conditions_to_container(container, conditions)
290
- # @deprecated OH 4.0
291
- supports_and_conditions = SitemapBuilder.factory.respond_to?(:create_condition)
292
-
293
284
  Array.wrap(conditions).each do |c|
294
285
  c = c.to_s if c.is_a?(Core::Types::State)
295
286
  unless c.is_a?(String) || c.is_a?(Symbol)
@@ -299,12 +290,12 @@ module OpenHAB
299
290
  raise ArgumentError, "Syntax error in condition #{c.inspect} for #{inspect}"
300
291
  end
301
292
 
302
- condition = supports_and_conditions ? SitemapBuilder.factory.create_condition : container
293
+ condition = SitemapBuilder.factory.create_condition
303
294
  condition.item = match["item"]
304
295
  condition.condition = match["condition"]
305
296
  condition.sign = match["sign"]
306
297
  condition.state = match["state"]
307
- container.conditions.add(condition) if supports_and_conditions
298
+ container.conditions.add(condition)
308
299
  end
309
300
  end
310
301
  end
@@ -546,7 +537,7 @@ module OpenHAB
546
537
  # @return [String, nil]
547
538
  # @example
548
539
  # "#.##" # => formats a number with two decimals.
549
- # @see https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/text/DecimalFormat.html DecimalFormat
540
+ # @see java.text.DecimalFormat DecimalFormat
550
541
  attr_accessor :y_axis_pattern
551
542
 
552
543
  # (see WidgetBuilder#initialize)
@@ -809,7 +800,6 @@ module OpenHAB
809
800
  stateless: nil,
810
801
  **kwargs,
811
802
  &block)
812
-
813
803
  super(:button, builder_proxy, **kwargs, &block)
814
804
 
815
805
  @row = row
@@ -1483,7 +1473,7 @@ module OpenHAB
1483
1473
  # @param icon [String, nil]
1484
1474
  # @!visibility private
1485
1475
  def initialize(name, builder_proxy, label: nil, icon: nil)
1486
- super(:sitemap, builder_proxy, label: label, icon: icon)
1476
+ super(:sitemap, builder_proxy, label:, icon:)
1487
1477
 
1488
1478
  @name = name
1489
1479
  end
@@ -77,14 +77,14 @@ module OpenHAB
77
77
 
78
78
  # Create a new Bridge
79
79
  # @see BridgeBuilder#initialize
80
- def bridge(*args, **kwargs, &block)
81
- build(BridgeBuilder, *args, **kwargs, &block)
80
+ def bridge(...)
81
+ build(BridgeBuilder, ...)
82
82
  end
83
83
 
84
84
  # Create a new Thing
85
85
  # @see ThingBuilder#initialize
86
- def thing(*args, **kwargs, &block)
87
- build(ThingBuilder, *args, **kwargs, &block)
86
+ def thing(...)
87
+ build(ThingBuilder, ...)
88
88
  end
89
89
 
90
90
  private
@@ -287,14 +287,14 @@ module OpenHAB
287
287
 
288
288
  # Create a new Bridge with this Bridge as its Bridge
289
289
  # @see BridgeBuilder#initialize
290
- def bridge(*args, **kwargs, &block)
291
- parent_builder.bridge(*args, bridge: self, **kwargs, &block)
290
+ def bridge(*args, **kwargs, &)
291
+ parent_builder.bridge(*args, bridge: self, **kwargs, &)
292
292
  end
293
293
 
294
294
  # Create a new Thing with this Bridge as its Bridge
295
295
  # @see ThingBuilder#initialize
296
- def thing(*args, **kwargs, &block)
297
- parent_builder.thing(*args, bridge: self, **kwargs, &block)
296
+ def thing(*args, **kwargs, &)
297
+ parent_builder.thing(*args, bridge: self, **kwargs, &)
298
298
  end
299
299
  end
300
300
 
@@ -35,11 +35,11 @@ module OpenHAB
35
35
  old_timer.cancel!
36
36
  @timers.remove(old_timer)
37
37
  end
38
- Core::Timer.new(duration, id: id, thread_locals: thread_locals, block: block)
38
+ Core::Timer.new(duration, id:, thread_locals:, block:)
39
39
  end
40
40
  end
41
41
 
42
- Core::Timer.new(duration, id: id, thread_locals: thread_locals, block: block)
42
+ Core::Timer.new(duration, id:, thread_locals:, block:)
43
43
  end
44
44
 
45
45
  # Add a timer that is now active
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.35.1"
7
+ VERSION = "5.36.0"
8
8
  end
9
9
  end
data/lib/openhab/dsl.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "java"
4
4
  require "method_source"
5
- require "ruby2_keywords"
6
5
 
7
6
  require "bundler/inline"
8
7
 
@@ -10,7 +9,7 @@ require_relative "log"
10
9
  require_relative "osgi"
11
10
  require_relative "core"
12
11
 
13
- Dir[File.expand_path("dsl/**/*.rb", __dir__)].sort.each do |f|
12
+ Dir[File.expand_path("dsl/**/*.rb", __dir__)].each do |f|
14
13
  require f
15
14
  end
16
15
 
@@ -59,38 +58,38 @@ module OpenHAB
59
58
 
60
59
  # (see Rules::Builder#rule)
61
60
  def rule(name = nil, id: nil, **kwargs, &block)
62
- rules.build { rule(name, id: id, **kwargs, &block) }
61
+ rules.build { rule(name, id:, **kwargs, &block) }
63
62
  end
64
63
 
65
64
  # Creates a rule that will remove existing rules with the same id, even when the id has been inferred.
66
65
  # @see rule
67
66
  def rule!(name = nil, id: nil, **kwargs, &block)
68
- rules.build { rule(name, id: id, replace: true, **kwargs, &block) }
67
+ rules.build { rule(name, id:, replace: true, **kwargs, &block) }
69
68
  end
70
69
 
71
70
  # (see Rules::Builder#scene)
72
71
  def scene(name = nil, description: nil, id: nil, tag: nil, tags: nil, **kwargs, &block)
73
- rules.build { scene(name, description: description, id: id, tag: tag, tags: tags, **kwargs, &block) }
72
+ rules.build { scene(name, description:, id:, tag:, tags:, **kwargs, &block) }
74
73
  end
75
74
 
76
75
  # Creates a scene that will remove existing rules/scenes with the same id, even when the id has been inferred.
77
76
  # @see scene
78
77
  def scene!(name = nil, description: nil, id: nil, tag: nil, tags: nil, **kwargs, &block)
79
78
  rules.build do
80
- scene(name, description: description, id: id, tag: tag, tags: tags, replace: true, **kwargs, &block)
79
+ scene(name, description:, id:, tag:, tags:, replace: true, **kwargs, &block)
81
80
  end
82
81
  end
83
82
 
84
83
  # (see Rules::Builder#script)
85
84
  def script(name = nil, description: nil, id: nil, tag: nil, tags: nil, **kwargs, &block)
86
- rules.build { script(name, description: description, id: id, tag: tag, tags: tags, **kwargs, &block) }
85
+ rules.build { script(name, description:, id:, tag:, tags:, **kwargs, &block) }
87
86
  end
88
87
 
89
88
  # Creates a script that will remove existing rules/scripts with the same id, even when the id has been inferred.
90
89
  # @see script
91
90
  def script!(name = nil, description: nil, id: nil, tag: nil, tags: nil, **kwargs, &block)
92
91
  rules.build do
93
- script(name, description: description, id: id, tag: tag, tags: tags, replace: true, **kwargs, &block)
92
+ script(name, description:, id:, tag:, tags:, replace: true, **kwargs, &block)
94
93
  end
95
94
  end
96
95
 
@@ -198,7 +197,7 @@ module OpenHAB
198
197
  id = id.to_s
199
198
 
200
199
  ThreadLocal.thread_local(openhab_rule_type: "profile", openhab_rule_uid: id) do
201
- Core::ProfileFactory.instance.register(id, block, label: label, type: type, config_description: config_description)
200
+ Core::ProfileFactory.instance.register(id, block, label:, type:, config_description:)
202
201
  end
203
202
  end
204
203
 
@@ -383,7 +382,7 @@ module OpenHAB
383
382
 
384
383
  # Carry rule name to timer
385
384
  thread_locals = ThreadLocal.persist
386
- timers.create(duration, id: id, reschedule: reschedule, thread_locals: thread_locals, block: block)
385
+ timers.create(duration, id:, reschedule:, thread_locals:, block:)
387
386
  end
388
387
 
389
388
  #
@@ -444,7 +443,7 @@ module OpenHAB
444
443
  interval = binding.local_variable_get(:for)
445
444
  id ||= block.source_location
446
445
  DSL.debouncers.compute(id) do |_key, debouncer|
447
- debouncer ||= Debouncer.new(for: interval, leading: leading, idle_time: idle_time)
446
+ debouncer ||= Debouncer.new(for: interval, leading:, idle_time:)
448
447
  debouncer.call(&block)
449
448
  debouncer
450
449
  end
@@ -482,7 +481,7 @@ module OpenHAB
482
481
  #
483
482
  def debounce_for(debounce_time, id: nil, &block)
484
483
  idle_time = debounce_time.is_a?(Range) ? debounce_time.begin : debounce_time
485
- debounce(for: debounce_time, idle_time: idle_time, id: id, &block)
484
+ debounce(for: debounce_time, idle_time:, id:, &block)
486
485
  end
487
486
 
488
487
  #
@@ -514,7 +513,7 @@ module OpenHAB
514
513
  # @see Rules::BuilderDSL#throttle_for
515
514
  #
516
515
  def throttle_for(duration, id: nil, &block)
517
- debounce(for: duration, id: id, &block)
516
+ debounce(for: duration, id:, &block)
518
517
  end
519
518
 
520
519
  # (see Core::Actions::Transformation.transform)
@@ -545,7 +544,7 @@ module OpenHAB
545
544
  #
546
545
  def only_every(interval, id: nil, &block)
547
546
  interval = 1.send(interval) if %i[second minute hour day].include?(interval)
548
- debounce(for: interval, leading: true, id: id, &block)
547
+ debounce(for: interval, leading: true, id:, &block)
549
548
  end
550
549
 
551
550
  #
@@ -1057,7 +1056,7 @@ module OpenHAB
1057
1056
  # see OpenHAB::DSL::Rules::AutomationRule#execute!
1058
1057
  #
1059
1058
  # @!visibility private
1060
- ruby2_keywords def method_missing(method, *args)
1059
+ def method_missing(method, *args)
1061
1060
  return super unless args.empty? && !block_given?
1062
1061
 
1063
1062
  if (context = Thread.current[:openhab_context]) && context.key?(method)
data/lib/openhab/log.rb CHANGED
@@ -166,13 +166,13 @@ module OpenHAB
166
166
  #
167
167
  # Regex for matching internal calls in a stack trace
168
168
  #
169
- INTERNAL_CALL_REGEX = %r{(openhab-scripting-.*/lib)|org[./]jruby}.freeze
169
+ INTERNAL_CALL_REGEX = %r{(openhab-scripting-.*/lib)|org[./]jruby}
170
170
  private_constant :INTERNAL_CALL_REGEX
171
171
 
172
172
  #
173
173
  # Regex for matching internal calls in a java stack trace
174
174
  #
175
- EXCLUDED_JAVA_PACKAGES = /jdk\.internal\.reflect|java\.lang\.reflect|org\.openhab|java\.lang\.Thread\.run/.freeze
175
+ EXCLUDED_JAVA_PACKAGES = /jdk\.internal\.reflect|java\.lang\.reflect|org\.openhab|java\.lang\.Thread\.run/
176
176
  private_constant :EXCLUDED_JAVA_PACKAGES
177
177
 
178
178
  #
@@ -228,7 +228,7 @@ module OpenHAB
228
228
  #
229
229
  def def_level_method(level)
230
230
  define_method(level) do |msg = nil, &block|
231
- log(severity: level, msg: msg, &block)
231
+ log(severity: level, msg:, &block)
232
232
  end
233
233
  end
234
234
 
data/lib/openhab/osgi.rb CHANGED
@@ -13,7 +13,7 @@ module OpenHAB
13
13
  # @return [Object]
14
14
  #
15
15
  def service(name, filter: nil)
16
- services(name, filter: filter).first
16
+ services(name, filter:).first
17
17
  end
18
18
 
19
19
  #
@@ -147,8 +147,8 @@ module OpenHAB
147
147
  #
148
148
  # @return [Object] The return value from the block.
149
149
  #
150
- def suspend_rules(&block)
151
- SuspendRules.suspend_rules(&block)
150
+ def suspend_rules(&)
151
+ SuspendRules.suspend_rules(&)
152
152
  end
153
153
 
154
154
  #
@@ -444,7 +444,7 @@ module OpenHAB
444
444
  50
445
445
  end
446
446
 
447
- EMACS_MODELINE_REGEXP = /# -\*-(.+)-\*-/.freeze
447
+ EMACS_MODELINE_REGEXP = /# -\*-(.+)-\*-/
448
448
  private_constant :EMACS_MODELINE_REGEXP
449
449
 
450
450
  def parse_emacs_modeline(line)
@@ -80,14 +80,8 @@ module OpenHAB
80
80
  config.before do |example|
81
81
  # clear persisted thing status
82
82
  tm = Core::Things.manager
83
- begin
84
- tm.class.field_reader :disabledStorage
85
- tm.disabledStorage.keys.each { |k| tm.disabledStorage.remove(k) } # rubocop:disable Style/HashEachMethods not a hash
86
- rescue NameError
87
- # @deprecated OH3.4
88
- tm.class.field_reader :storage
89
- tm.storage.keys.each { |k| tm.storage.remove(k) } # rubocop:disable Style/HashEachMethods not a hash
90
- end
83
+ tm.class.field_reader :disabledStorage
84
+ tm.disabledStorage.keys.each { |k| tm.disabledStorage.remove(k) } # rubocop:disable Style/HashEachMethods -- not a hash
91
85
  @profile_factory = Core::ProfileFactory.send(:new)
92
86
  allow(Core::ProfileFactory).to receive(:instance).and_return(@profile_factory)
93
87
 
@@ -37,7 +37,7 @@ module OpenHAB
37
37
  if defined?(Java::OrgOsgiFramework::Bundle) && loader.is_a?(org.osgi.framework.Bundle)
38
38
  loader = OSGiBundleClassLoader.new(loader)
39
39
  end
40
- super(loader)
40
+ super
41
41
  end
42
42
  end
43
43
  org.jruby.RubyInstanceConfig.prepend(InstanceConfig)