openhab-scripting 4.28.0 → 4.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/dsl/items/group_item.rb +7 -0
  3. data/lib/openhab/dsl/items/item_registry.rb +1 -1
  4. data/lib/openhab/dsl/rules/automation_rule.rb +10 -158
  5. data/lib/openhab/dsl/rules/rule.rb +4 -46
  6. data/lib/openhab/dsl/rules/rule_config.rb +4 -3
  7. data/lib/openhab/dsl/rules/triggers/changed.rb +51 -18
  8. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +158 -0
  9. data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +150 -0
  10. data/lib/openhab/dsl/rules/triggers/cron.rb +118 -0
  11. data/lib/openhab/dsl/rules/triggers/trigger.rb +2 -1
  12. data/lib/openhab/dsl/rules/triggers/updated.rb +59 -16
  13. data/lib/openhab/dsl/rules/triggers/watch.rb +1 -3
  14. data/lib/openhab/dsl/types/date_time_type.rb +2 -2
  15. data/lib/openhab/dsl/types/decimal_type.rb +1 -1
  16. data/lib/openhab/dsl/types/hsb_type.rb +1 -1
  17. data/lib/openhab/dsl/types/increase_decrease_type.rb +1 -1
  18. data/lib/openhab/dsl/types/next_previous_type.rb +1 -1
  19. data/lib/openhab/dsl/types/on_off_type.rb +1 -1
  20. data/lib/openhab/dsl/types/open_closed_type.rb +1 -1
  21. data/lib/openhab/dsl/types/percent_type.rb +1 -1
  22. data/lib/openhab/dsl/types/play_pause_type.rb +1 -1
  23. data/lib/openhab/dsl/types/point_type.rb +1 -1
  24. data/lib/openhab/dsl/types/quantity_type.rb +1 -1
  25. data/lib/openhab/dsl/types/refresh_type.rb +1 -1
  26. data/lib/openhab/dsl/types/rewind_fastforward_type.rb +1 -1
  27. data/lib/openhab/dsl/types/stop_move_type.rb +1 -1
  28. data/lib/openhab/dsl/types/string_type.rb +1 -1
  29. data/lib/openhab/dsl/types/un_def_type.rb +1 -1
  30. data/lib/openhab/dsl/types/up_down_type.rb +1 -1
  31. data/lib/openhab/log/configuration.rb +1 -1
  32. data/lib/openhab/log/logger.rb +10 -0
  33. data/lib/openhab/version.rb +1 -1
  34. metadata +4 -3
  35. data/lib/openhab/dsl/rules/cron_trigger_rule.rb +0 -42
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openhab/log/logger'
4
+
5
+ module OpenHAB
6
+ module DSL
7
+ module Rules
8
+ module Triggers
9
+ #
10
+ # Module for conditions for triggers
11
+ #
12
+ module Conditions
13
+ include OpenHAB::Log
14
+
15
+ #
16
+ # This creates trigger conditions that work on procs
17
+ # @param [Proc] from Proc
18
+ # @param [Proc] to Proc
19
+ #
20
+ class Proc
21
+ include OpenHAB::Log
22
+
23
+ # Proc that doesn't check any fields
24
+ ANY = Proc.new.freeze
25
+
26
+ #
27
+ # Converts supplied ranges to procs that check range
28
+ # @param [Array] ranges objects to convert to range proc if they are ranges
29
+ # @return [Array] of procs or supplied arguments if argument was not of type Range
30
+ #
31
+ def self.range_procs(*ranges)
32
+ ranges.map { |range| range.is_a?(Range) ? range_proc(range) : range }
33
+ end
34
+
35
+ #
36
+ # Create a range proc for the supplied range object
37
+ # @param [Range] range to build proc for
38
+ #
39
+ def self.range_proc(range)
40
+ logger.trace("Creating range proc for #{range}")
41
+ lambda do |state|
42
+ logger.trace("Range proc checking if #{state} is in #{range}")
43
+ range.include? state
44
+ end
45
+ end
46
+
47
+ #
48
+ # Create a range proc for the supplied range object
49
+ # @param [Range] range to build proc for
50
+ #
51
+ def self.equality_proc(value)
52
+ logger.trace("Creating equality proc for #{value}")
53
+ lambda do |state|
54
+ logger.trace("Equality proc comparing #{value} against #{state}")
55
+ value == state
56
+ end
57
+ end
58
+
59
+ #
60
+ # Constructs a proc for the specific value type
61
+ # if the value is a proc return the proc
62
+ # if the value is a range create a range proc
63
+ # if the value is nil, return nil
64
+ # otherwise create an equality proc
65
+ # @param [Object] value to construct proc from
66
+ def self.from_value(value)
67
+ logger.trace("Creating proc for Value(#{value})")
68
+ return value if value.nil?
69
+ return value if value.is_a? ::Proc
70
+ return range_proc(value) if value.is_a? Range
71
+
72
+ equality_proc(value)
73
+ end
74
+
75
+ #
76
+ # Create a new Proc Condition that executes only if procs return true
77
+ # @param [Proc] from Proc to check against from value
78
+ # @param [Proc] to Proc to check against to value
79
+ #
80
+ def initialize(from: nil, to: nil)
81
+ @from = from
82
+ @to = to
83
+ end
84
+
85
+ #
86
+ # Process rule
87
+ # @param [Hash] inputs inputs from trigger
88
+ #
89
+ def process(mod:, inputs:) # rubocop:disable Lint/UnusedMethodArgument - mod is unused here but required
90
+ logger.trace("Checking #{inputs} against condition trigger #{self}")
91
+ yield if check_from(inputs: inputs) && check_to(inputs: inputs)
92
+ end
93
+
94
+ #
95
+ # Check if from condition match the proc
96
+ # @param [Hash] inputs from trigger must be supplied if state is not supplied
97
+ # @param [String] state if supplied proc will be passed state value for comparision
98
+ # @return [true/false] depending on if from is set and matches supplied conditions
99
+ #
100
+ def check_from(inputs: nil, state: nil)
101
+ state ||= input_state(inputs, 'oldState')
102
+ logger.trace "Checking from(#{@from}) against state(#{state})"
103
+ check_proc(proc: @from, state: state)
104
+ end
105
+
106
+ #
107
+ # Check if to conditions match the proc
108
+ # @param [Hash] inputs from trigger must be supplied if state is not supplied
109
+ # @param [String] state if supplied proc will be passed state value for comparision
110
+ # @return [true/false] depending on if from is set and matches supplied conditions
111
+ #
112
+ def check_to(inputs: nil, state: nil)
113
+ state ||= input_state(inputs, 'newState', 'state')
114
+ logger.trace "Checking to(#{@to}) against state(#{state})"
115
+ check_proc(proc: @to, state: state)
116
+ end
117
+
118
+ # Describe the Proc Condition as a string
119
+ # @return [String] string representation of proc condition
120
+ #
121
+ def to_s
122
+ "From:(#{@from}) To:(#{@to})"
123
+ end
124
+
125
+ private
126
+
127
+ # Check if a field matches the proc condition
128
+ # @param [Proc] proc to call
129
+ # @param [Hash] inputs containing fields
130
+ # @param [Array] fields array of fields to extract from inputs, first one found is passed to proc
131
+ # @return [true,false] true if proc is nil or proc.call returns true, false otherwise
132
+ def check_proc(proc:, state:)
133
+ return true if proc.nil? || proc.call(state)
134
+
135
+ logger.trace("Skipped execution of rule because state #{state} evalulated false for (#{proc})")
136
+ false
137
+ end
138
+
139
+ # Get the first field from supplied fields in inputs
140
+ # @param [Hash] inputs containing fields
141
+ # @param [Array] fields array of fields to extract from inputs, first one found is returned
142
+ def input_state(inputs, *fields)
143
+ fields.map { |f| inputs[f] }.compact.first
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -164,7 +164,125 @@ module OpenHAB
164
164
  end
165
165
  expression_map
166
166
  end
167
+
168
+ #
169
+ # Cron trigger that provides trigger ID
170
+ #
171
+ module Cron
172
+ include OpenHAB::Log
173
+
174
+ #
175
+ # Creates trigger types and trigger type factories for OpenHAB
176
+ #
177
+ def self.add_script_cron_handler
178
+ java_import org.openhab.core.automation.type.TriggerType
179
+ OpenHAB::Core.automation_manager.add_trigger_handler(
180
+ OpenHAB::DSL::Rules::Triggers::Cron::CRON_TRIGGER_MODULE_ID,
181
+ OpenHAB::DSL::Rules::Triggers::Cron::CronTriggerHandlerFactory.new
182
+ )
183
+
184
+ OpenHAB::Core.automation_manager.add_trigger_type(cron_trigger_type)
185
+ OpenHAB::Log.logger(self).trace('Added script cron trigger handler')
186
+ end
187
+
188
+ #
189
+ # Creates trigger types and trigger type factories for OpenHAB
190
+ #
191
+ private_class_method def self.cron_trigger_type
192
+ TriggerType.new(
193
+ OpenHAB::DSL::Rules::Triggers::Cron::CRON_TRIGGER_MODULE_ID,
194
+ nil,
195
+ 'A specific instant occurs',
196
+ 'Triggers when the specified instant occurs',
197
+ nil,
198
+ org.openhab.core.automation.Visibility::VISIBLE,
199
+ nil
200
+ )
201
+ end
202
+
203
+ # Trigger ID for Watch Triggers
204
+ CRON_TRIGGER_MODULE_ID = 'jsr223.jruby.CronTrigger'
205
+
206
+ # Cron Trigger Handler that provides trigger IDs
207
+ # Unfortunatly because the CronTriggerHandler in OpenHAB core is marked internal
208
+ # the entire thing must be recreated here
209
+ class CronTriggerHandler < org.openhab.core.automation.handler.BaseTriggerModuleHandler
210
+ include OpenHAB::Log
211
+ include org.openhab.core.scheduler.SchedulerRunnable
212
+ include org.openhab.core.automation.handler.TimeBasedTriggerHandler
213
+
214
+ # Provides access to protected fields
215
+ field_accessor :callback
216
+
217
+ # Creates a new CronTriggerHandler
218
+ # @param [Trigger] OpenHAB trigger associated with handler
219
+ #
220
+ def initialize(trigger)
221
+ @trigger = trigger
222
+ @scheduler = OpenHAB::Core::OSGI.service('org.openhab.core.scheduler.CronScheduler')
223
+ @expression = trigger.configuration.get('cronExpression')
224
+ super(trigger)
225
+ end
226
+
227
+ #
228
+ # Set the callback to execute when cron trigger fires
229
+ # @param [Object] callback to run
230
+ #
231
+ def setCallback(callback) # rubocop:disable Naming/MethodName
232
+ synchronized do
233
+ super(callback)
234
+ @scheduler.schedule(self, @expression)
235
+ logger.trace("Scheduled cron job '#{@expression}' for trigger '#{@trigger.id}'.")
236
+ end
237
+ end
238
+
239
+ #
240
+ # Get the temporal adjuster
241
+ # @return [CronAdjuster]
242
+ #
243
+ def getTemporalAdjuster # rubocop:disable Naming/MethodName
244
+ org.openhab.core.scheduler.CronAdjuster.new(expression)
245
+ end
246
+
247
+ #
248
+ # Execute the callback
249
+ #
250
+ def run
251
+ callback&.triggered(@trigger, { 'module' => @trigger.id })
252
+ end
253
+
254
+ #
255
+ # Displose of the handler
256
+ # cancel the cron scheduled task
257
+ #
258
+ def dispose
259
+ synchronized do
260
+ super
261
+ return unless @schedule
262
+
263
+ @schedule&.cancel(true)
264
+ end
265
+ logger.trace("cancelled job for trigger '#{@trigger.id}'.")
266
+ end
267
+ end
268
+
269
+ # Implements the ScriptedTriggerHandlerFactory interface to create a new Cron Trigger Handler
270
+ class CronTriggerHandlerFactory
271
+ include org.openhab.core.automation.module.script.rulesupport.shared.factories.ScriptedTriggerHandlerFactory
272
+
273
+ # Invoked by the OpenHAB core to get a trigger handler for the supllied trigger
274
+ # @param [Trigger] OpenHAB trigger
275
+ #
276
+ # @return [WatchTriggerHandler] trigger handler for supplied trigger
277
+ def get(trigger)
278
+ CronTriggerHandler.new(trigger)
279
+ end
280
+ end
281
+ end
167
282
  end
168
283
  end
169
284
  end
170
285
  end
286
+
287
+ # Add the cron handler to OpenHAB
288
+ OpenHAB::DSL::Rules::Triggers::Cron.add_script_cron_handler
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'securerandom'
4
4
  require 'java'
5
+ require_relative 'cron'
5
6
 
6
7
  module OpenHAB
7
8
  module DSL
@@ -111,7 +112,7 @@ module OpenHAB
111
112
  TIME_OF_DAY = 'timer.TimeOfDayTrigger'
112
113
 
113
114
  # @return [String] A cron trigger
114
- CRON = 'timer.GenericCronTrigger'
115
+ CRON = OpenHAB::DSL::Rules::Triggers::Cron::CRON_TRIGGER_MODULE_ID
115
116
 
116
117
  #
117
118
  # Create a trigger
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'openhab/log/logger'
4
+ require_relative 'trigger'
4
5
 
5
6
  module OpenHAB
6
7
  module DSL
@@ -23,29 +24,71 @@ module OpenHAB
23
24
  separate_groups(items).map do |item|
24
25
  logger.trace("Creating updated trigger for item(#{item}) to(#{to})")
25
26
  [to].flatten.map do |to_state|
26
- trigger, config = create_update_trigger(item, to_state)
27
- append_trigger(trigger, config, attach: attach)
27
+ update_trigger(item: item, to: to_state, attach: attach)
28
28
  end
29
29
  end.flatten
30
30
  end
31
31
 
32
32
  private
33
33
 
34
+ #
35
+ # Create the trigger
36
+ #
37
+ # @param [Object] item item to create trigger for
38
+ # @param [Item State] from state to restrict trigger to
39
+ # @param [Item State] to state to restrict trigger to
40
+ # @param attach attachment
41
+ #
42
+ # @return [Trigger] OpenHAB triggers
43
+ #
44
+ def update_trigger(item:, to:, attach:)
45
+ case to
46
+ when Range then create_update_range_trigger(item: item, to: to, attach: attach)
47
+ when Proc then create_update_proc_trigger(item: item, to: to, attach: attach)
48
+ else create_update_trigger(item: item, to: to, attach: attach)
49
+ end
50
+ end
51
+
52
+ #
53
+ # Creates a trigger with a range condition on the 'to' field
54
+ # @param [Object] item to create changed trigger on
55
+ # @param [Object] to state restrict trigger to
56
+ # @param [Object] attach to trigger
57
+ # @return [Trigger] OpenHAB trigger
58
+ #
59
+ def create_update_range_trigger(item:, to:, attach:)
60
+ to, * = Conditions::Proc.range_procs(to)
61
+ create_update_proc_trigger(item: item, to: to, attach: attach)
62
+ end
63
+
64
+ #
65
+ # Creates a trigger with a proc condition on the 'to' field
66
+ # @param [Object] item to create changed trigger on
67
+ # @param [Object] to state restrict trigger to
68
+ # @param [Object] attach to trigger
69
+ # @return [Trigger] OpenHAB trigger
70
+ #
71
+ def create_update_proc_trigger(item:, to:, attach:)
72
+ create_update_trigger(item: item, to: nil, attach: attach).tap do |trigger|
73
+ @trigger_conditions[trigger.id] = Conditions::Proc.new(to: to)
74
+ end
75
+ end
76
+
34
77
  #
35
78
  # Create a trigger for updates
36
79
  #
37
80
  # @param [Object] item Type of item [Group,Thing,Item] to create update trigger for
38
81
  # @param [State] to_state state restriction on trigger
39
82
  #
40
- # @return [Array<Hash,String>] first element is a String specifying trigger type
41
- # second element is a Hash configuring trigger
83
+ # @return [Trigger] OpenHAB triggers
42
84
  #
43
- def create_update_trigger(item, to_state)
44
- case item
45
- when OpenHAB::DSL::Items::GroupItem::GroupMembers then group_update(item, to_state)
46
- when Thing then thing_update(item, to_state)
47
- else item_update(item, to_state)
48
- end
85
+ def create_update_trigger(item:, to:, attach:)
86
+ trigger, config = case item
87
+ when OpenHAB::DSL::Items::GroupItem::GroupMembers then group_update(item: item, to: to)
88
+ when Thing then thing_update(thing: item, to: to)
89
+ else item_update(item: item, to: to)
90
+ end
91
+ append_trigger(trigger, config, attach: attach)
49
92
  end
50
93
 
51
94
  #
@@ -57,9 +100,9 @@ module OpenHAB
57
100
  # @return [Array<Hash,String>] first element is a String specifying trigger type
58
101
  # second element is a Hash configuring trigger
59
102
  #
60
- def item_update(item, to_state)
103
+ def item_update(item:, to:)
61
104
  config = { 'itemName' => item.name }
62
- config['state'] = to_state.to_s unless to_state.nil?
105
+ config['state'] = to.to_s unless to.nil?
63
106
  trigger = Trigger::ITEM_STATE_UPDATE
64
107
  [trigger, config]
65
108
  end
@@ -73,9 +116,9 @@ module OpenHAB
73
116
  # @return [Array<Hash,String>] first element is a String specifying trigger type
74
117
  # second element is a Hash configuring trigger
75
118
  #
76
- def group_update(item, to_state)
119
+ def group_update(item:, to:)
77
120
  config = { 'groupName' => item.group.name }
78
- config['state'] = to_state.to_s unless to_state.nil?
121
+ config['state'] = to.to_s unless to.nil?
79
122
  trigger = Trigger::GROUP_STATE_UPDATE
80
123
  [trigger, config]
81
124
  end
@@ -89,8 +132,8 @@ module OpenHAB
89
132
  # @return [Array<Hash,String>] first element is a String specifying trigger type
90
133
  # second element is a Hash configuring trigger
91
134
  #
92
- def thing_update(thing, to_state)
93
- trigger_for_thing(thing, Trigger::THING_UPDATE, to_state)
135
+ def thing_update(thing:, to:)
136
+ trigger_for_thing(thing, Trigger::THING_UPDATE, to)
94
137
  end
95
138
  end
96
139
  end
@@ -138,11 +138,9 @@ module OpenHAB
138
138
 
139
139
  # Called by OpenHAB to set the rule engine to invoke when triggered
140
140
  # Must match java method name style
141
- # rubocop:disable Naming/MethodName
142
- def setCallback(callback)
141
+ def setCallback(callback) # rubocop:disable Naming/MethodName
143
142
  @rule_engine_callback = callback
144
143
  end
145
- # rubocop:enable Naming/MethodName
146
144
 
147
145
  #
148
146
  # Dispose of handler which deactivates watcher
@@ -7,8 +7,8 @@ require 'java'
7
7
  module OpenHAB
8
8
  module DSL
9
9
  module Types
10
- java_import org.openhab.core.library.types.DateTimeType
11
- java_import java.time.ZonedDateTime
10
+ DateTimeType = org.openhab.core.library.types.DateTimeType
11
+ java_import java.time.ZonedDateTime # This is needed for the addon prior to ruby_class fix (OH 3.2.0)
12
12
 
13
13
  # global alias
14
14
  ::DateTimeType = DateTimeType
@@ -6,7 +6,7 @@ require_relative 'numeric_type'
6
6
  module OpenHAB
7
7
  module DSL
8
8
  module Types
9
- java_import org.openhab.core.library.types.DecimalType
9
+ DecimalType = org.openhab.core.library.types.DecimalType
10
10
 
11
11
  #
12
12
  # Add methods to core OpenHAB DecimalType to make it behave as a Ruby
@@ -6,7 +6,7 @@ require_relative 'percent_type'
6
6
  module OpenHAB
7
7
  module DSL
8
8
  module Types
9
- java_import org.openhab.core.library.types.HSBType
9
+ HSBType = org.openhab.core.library.types.HSBType
10
10
 
11
11
  # global alias
12
12
  ::HSBType = HSBType
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.IncreaseDecreaseType
6
+ IncreaseDecreaseType = org.openhab.core.library.types.IncreaseDecreaseType
7
7
 
8
8
  # Adds methods to core OpenHAB IncreaseDecreaseType to make it more
9
9
  # natural in Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.NextPreviousType
6
+ NextPreviousType = org.openhab.core.library.types.NextPreviousType
7
7
 
8
8
  # Adds methods to core OpenHAB NextPreviousType to make it more
9
9
  # natural in Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.OnOffType
6
+ OnOffType = org.openhab.core.library.types.OnOffType
7
7
 
8
8
  # Adds methods to core OpenHAB OnOffType to make it more natural in Ruby
9
9
  class OnOffType
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.OpenClosedType
6
+ OpenClosedType = org.openhab.core.library.types.OpenClosedType
7
7
 
8
8
  # Adds methods to core OpenHAB OpenClosedType to make it more natural in Ruby
9
9
  class OpenClosedType
@@ -5,7 +5,7 @@ require_relative 'decimal_type'
5
5
  module OpenHAB
6
6
  module DSL
7
7
  module Types
8
- java_import org.openhab.core.library.types.PercentType
8
+ PercentType = org.openhab.core.library.types.PercentType
9
9
 
10
10
  # global alias
11
11
  ::PercentType = PercentType
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.PlayPauseType
6
+ PlayPauseType = org.openhab.core.library.types.PlayPauseType
7
7
 
8
8
  # Adds methods to core OpenHAB PlayPauseType to make it more
9
9
  # natural in Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.PointType
6
+ PointType = org.openhab.core.library.types.PointType
7
7
 
8
8
  # global scope
9
9
  # @!visibility private
@@ -5,7 +5,7 @@ require_relative 'numeric_type'
5
5
  module OpenHAB
6
6
  module DSL
7
7
  module Types
8
- java_import org.openhab.core.library.types.QuantityType
8
+ QuantityType = org.openhab.core.library.types.QuantityType
9
9
 
10
10
  # global alias
11
11
  ::QuantityType = QuantityType
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.types.RefreshType
6
+ RefreshType = org.openhab.core.types.RefreshType
7
7
 
8
8
  # Adds methods to core OpenHAB RefreshType to make it more natural in Ruby
9
9
  class RefreshType # rubocop:disable Lint/EmptyClass
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.RewindFastforwardType
6
+ RewindFastforwardType = org.openhab.core.library.types.RewindFastforwardType
7
7
 
8
8
  # Adds methods to core OpenHAB RewindFastforwardType to make it more
9
9
  # natural in Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.StopMoveType
6
+ StopMoveType = org.openhab.core.library.types.StopMoveType
7
7
 
8
8
  # Adds methods to core OpenHAB StopMoveType to make it more
9
9
  # natural in Ruby
@@ -7,7 +7,7 @@ require_relative 'comparable_type'
7
7
  module OpenHAB
8
8
  module DSL
9
9
  module Types
10
- java_import org.openhab.core.library.types.StringType
10
+ StringType = org.openhab.core.library.types.StringType
11
11
 
12
12
  #
13
13
  # Add methods to core OpenHAB StringType to make it behave as a Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.types.UnDefType
6
+ UnDefType = org.openhab.core.types.UnDefType
7
7
 
8
8
  # Adds methods to core OpenHAB UnDefType to make it more natural in Ruby
9
9
  class UnDefType # rubocop:disable Lint/EmptyClass
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.UpDownType
6
+ UpDownType = org.openhab.core.library.types.UpDownType
7
7
 
8
8
  # Adds methods to core OpenHAB UpDownType to make it more natural in Ruby
9
9
  class UpDownType
@@ -6,7 +6,7 @@ module OpenHAB
6
6
  # This module holds global configuration values
7
7
  module Configuration
8
8
  # -*- coding: utf-8 -*-
9
- LOG_PREFIX = 'jsr223.jruby'
9
+ LOG_PREFIX = 'org.openhab.automation.jruby'
10
10
 
11
11
  #
12
12
  # Gets the log prefix
@@ -82,6 +82,16 @@ module OpenHAB
82
82
  error
83
83
  end
84
84
 
85
+ #
86
+ # Print error and stack trace without calls to internal classes
87
+ #
88
+ # @param [Exception] error A rescued error
89
+ #
90
+ def log_exception(exception, rule_name)
91
+ exception = clean_backtrace(exception)
92
+ error { "#{exception.message} (#{exception.class})\nIn rule: #{rule_name}\n#{exception.backtrace&.join("\n")}" }
93
+ end
94
+
85
95
  private
86
96
 
87
97
  #
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.28.0'
8
+ VERSION = '4.30.0'
9
9
  end