openhab-scripting 5.4.2 → 5.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/core/configuration.rb +70 -0
- data/lib/openhab/core/emulate_hash.rb +241 -0
- data/lib/openhab/core/events/abstract_event.rb +11 -0
- data/lib/openhab/core/events/timer_event.rb +48 -0
- data/lib/openhab/core/items/group_function.rb +37 -0
- data/lib/openhab/core/items/group_item.rb +10 -4
- data/lib/openhab/core/items/item.rb +31 -0
- data/lib/openhab/core/items/metadata/hash.rb +9 -179
- data/lib/openhab/core/items/metadata/namespace_hash.rb +38 -141
- data/lib/openhab/core/items/persistence.rb +45 -12
- data/lib/openhab/core/items/semantics/semantic_tag.rb +5 -0
- data/lib/openhab/core/items/semantics/tag_class_methods.rb +9 -0
- data/lib/openhab/core/items/semantics.rb +3 -1
- data/lib/openhab/core/rules/rule.rb +17 -4
- data/lib/openhab/core/things/links/provider.rb +1 -1
- data/lib/openhab/core/things/thing.rb +23 -0
- data/lib/openhab/core/value_cache.rb +1 -1
- data/lib/openhab/dsl/items/builder.rb +10 -5
- data/lib/openhab/dsl/rules/automation_rule.rb +29 -5
- data/lib/openhab/dsl/rules/builder.rb +0 -3
- data/lib/openhab/dsl/rules/rule_triggers.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +2 -1
- data/lib/openhab/dsl/rules/triggers/conditions/generic.rb +7 -0
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +10 -2
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +101 -96
- data/lib/openhab/dsl/things/builder.rb +4 -4
- data/lib/openhab/dsl/thread_local.rb +1 -0
- data/lib/openhab/dsl/timer_manager.rb +4 -4
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +23 -4
- data/lib/openhab/log.rb +2 -2
- data/lib/openhab/rspec/helpers.rb +10 -1
- data/lib/openhab/rspec/karaf.rb +2 -2
- data/lib/openhab/rspec.rb +1 -1
- metadata +6 -2
@@ -37,6 +37,29 @@ module OpenHAB
|
|
37
37
|
# @!attribute [r] channels
|
38
38
|
# @return [ChannelArray]
|
39
39
|
#
|
40
|
+
# @!attribute [r] uid
|
41
|
+
# Return the UID.
|
42
|
+
# @return [org.openhab.core.thing.ThingUID]
|
43
|
+
#
|
44
|
+
# @!attribute [r] bridge_uid
|
45
|
+
# Return the Bridge UID when available.
|
46
|
+
# @return [org.openhab.core.thing.ThingUID]
|
47
|
+
#
|
48
|
+
# @!attribute [r] configuration
|
49
|
+
# Return the thing's configuration.
|
50
|
+
# @return [OpenHAB::Core::Configuration]
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# logger.info things["smtp:mail:local"].configuration["hostname"]
|
54
|
+
# logger.info things["ipcamera:dahua:frontporch"].configuration["ipAddress"]
|
55
|
+
#
|
56
|
+
# @!attribute [r] properties
|
57
|
+
# Return the properties when available.
|
58
|
+
# @return [Hash]
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# logger.info things["fronius:meter:mybridge:mymeter"].properties["modelId"]
|
62
|
+
#
|
40
63
|
module Thing
|
41
64
|
# Array wrapper class to allow searching a list of channels
|
42
65
|
# by channel id
|
@@ -28,7 +28,7 @@ module OpenHAB
|
|
28
28
|
# For a private cache, simply use an instance variable. See
|
29
29
|
# {file:docs/ruby-basics.md#variables Instance Variables}.
|
30
30
|
#
|
31
|
-
# @note Because every script or UI rule gets
|
31
|
+
# @note Because every script or UI rule gets its own JRuby engine instance,
|
32
32
|
# you cannot rely on being able to access Ruby objects between them. Only
|
33
33
|
# objects that implement a Java interface that's part of Java or openHAB
|
34
34
|
# Core (such as Hash implements {java.util.Map}, or other basic
|
@@ -230,9 +230,7 @@ module OpenHAB
|
|
230
230
|
tags.compact.map do |tag|
|
231
231
|
case tag
|
232
232
|
when String then tag
|
233
|
-
when Symbol then tag.to_s
|
234
|
-
when old_semantics then tag.java_class.simple_name
|
235
|
-
when semantics then tag.name
|
233
|
+
when Symbol, semantics, old_semantics then tag.to_s
|
236
234
|
else raise ArgumentError, "`#{tag}` must be a subclass of Semantics::Tag, a `Symbol`, or a `String`."
|
237
235
|
end
|
238
236
|
end
|
@@ -260,6 +258,8 @@ module OpenHAB
|
|
260
258
|
# @param tags [String, Symbol, Semantics::Tag, Array<String, Symbol, Semantics::Tag>, nil]
|
261
259
|
# Fluent alias for `tag`.
|
262
260
|
# @param autoupdate [true, false, nil] Autoupdate setting (see {ItemBuilder#autoupdate})
|
261
|
+
# @param thing [String, Core::Things::Thing, Core::Things::ThingUID, nil]
|
262
|
+
# A Thing to be used as the base for the channel
|
263
263
|
# @param channel [String, Core::Things::ChannelUID, nil] Channel to link the item to
|
264
264
|
# @param expire [String] An expiration specification.
|
265
265
|
# @param alexa [String, Symbol, Array<(String, Hash<String, Object>)>, nil]
|
@@ -281,6 +281,7 @@ module OpenHAB
|
|
281
281
|
tag: nil,
|
282
282
|
tags: nil,
|
283
283
|
autoupdate: nil,
|
284
|
+
thing: nil,
|
284
285
|
channel: nil,
|
285
286
|
expire: nil,
|
286
287
|
alexa: nil,
|
@@ -310,6 +311,7 @@ module OpenHAB
|
|
310
311
|
@metadata.merge!(metadata) if metadata
|
311
312
|
@autoupdate = autoupdate
|
312
313
|
@channels = []
|
314
|
+
@thing = thing
|
313
315
|
@expire = nil
|
314
316
|
if expire
|
315
317
|
expire = Array(expire)
|
@@ -420,6 +422,7 @@ module OpenHAB
|
|
420
422
|
# end
|
421
423
|
#
|
422
424
|
def channel(channel, config = {})
|
425
|
+
channel = "#{@thing}:#{channel}" if @thing && !channel.include?(":")
|
423
426
|
@channels << [channel, config]
|
424
427
|
end
|
425
428
|
|
@@ -569,7 +572,7 @@ module OpenHAB
|
|
569
572
|
RUBY
|
570
573
|
end
|
571
574
|
|
572
|
-
FUNCTION_REGEX = /^([a-z]+)(?:\((
|
575
|
+
FUNCTION_REGEX = /^([a-z]+)(?:\((.*)\))?/i.freeze
|
573
576
|
private_constant :FUNCTION_REGEX
|
574
577
|
|
575
578
|
# The combiner function for this group
|
@@ -607,11 +610,13 @@ module OpenHAB
|
|
607
610
|
def create_item
|
608
611
|
base_item = super if type
|
609
612
|
if function
|
613
|
+
require "csv"
|
614
|
+
|
610
615
|
match = function.match(FUNCTION_REGEX)
|
611
616
|
|
612
617
|
dto = org.openhab.core.items.dto.GroupFunctionDTO.new
|
613
618
|
dto.name = match[1]
|
614
|
-
dto.params = match[2
|
619
|
+
dto.params = CSV.parse_line(match[2]) if match[2]
|
615
620
|
function = org.openhab.core.items.dto.ItemDTOMapper.map_function(base_item, dto)
|
616
621
|
Core::Items::GroupItem.new(name, base_item, function)
|
617
622
|
else
|
@@ -74,6 +74,10 @@ module OpenHAB
|
|
74
74
|
|
75
75
|
# This method gets called in rspec's SuspendRules as well
|
76
76
|
def execute!(mod, inputs)
|
77
|
+
# Store the context in a thread variable. It is accessed through DSL#method_missing
|
78
|
+
# which is triggered when the context variable is referenced inside the run block.
|
79
|
+
# It is added to @thread_locals so it is also available in #process_task below.
|
80
|
+
@thread_locals[:openhab_context] = extract_context(inputs)
|
77
81
|
ThreadLocal.thread_local(**@thread_locals) do
|
78
82
|
if logger.trace?
|
79
83
|
logger.trace("Execute called with mod (#{mod&.to_string}) and inputs (#{inputs.inspect})")
|
@@ -84,10 +88,12 @@ module OpenHAB
|
|
84
88
|
@debouncer.call { process_queue(create_queue(event), mod, event) }
|
85
89
|
end
|
86
90
|
rescue Exception => e
|
87
|
-
raise if defined?(::RSpec) && ::RSpec.current_example
|
91
|
+
raise if defined?(::RSpec) && ::RSpec.current_example&.example_group&.propagate_exceptions?
|
88
92
|
|
89
93
|
@run_context.send(:logger).log_exception(e)
|
90
94
|
end
|
95
|
+
ensure
|
96
|
+
@thread_locals.delete(:openhab_context)
|
91
97
|
end
|
92
98
|
|
93
99
|
def cleanup
|
@@ -157,6 +163,24 @@ module OpenHAB
|
|
157
163
|
struct_class.new(**inputs)
|
158
164
|
end
|
159
165
|
|
166
|
+
#
|
167
|
+
# Converts inputs into context hash
|
168
|
+
# @return [Hash] Context hash.
|
169
|
+
#
|
170
|
+
def extract_context(inputs)
|
171
|
+
return unless inputs
|
172
|
+
|
173
|
+
inputs.reject { |key, _| key.include?(".") }
|
174
|
+
.to_h do |key, value|
|
175
|
+
[key.to_sym,
|
176
|
+
if value.is_a?(Item) && !value.is_a?(Core::Items::Proxy)
|
177
|
+
Core::Items::Proxy.new(value)
|
178
|
+
else
|
179
|
+
value
|
180
|
+
end]
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
160
184
|
#
|
161
185
|
# Get the trigger_id for the trigger that caused the rule creation
|
162
186
|
#
|
@@ -230,7 +254,7 @@ module OpenHAB
|
|
230
254
|
ThreadLocal.thread_local(**@thread_locals) do
|
231
255
|
case task
|
232
256
|
when BuilderDSL::Run then process_run_task(event, task)
|
233
|
-
when BuilderDSL::Script then process_script_task(task)
|
257
|
+
when BuilderDSL::Script then process_script_task(event, task)
|
234
258
|
when BuilderDSL::Trigger then process_trigger_task(event, task)
|
235
259
|
when BuilderDSL::Otherwise then process_otherwise_task(event, task)
|
236
260
|
end
|
@@ -294,9 +318,9 @@ module OpenHAB
|
|
294
318
|
#
|
295
319
|
# @param [Script] task to execute
|
296
320
|
#
|
297
|
-
def process_script_task(task)
|
298
|
-
logger.trace { "Executing script '#{name}' run block" }
|
299
|
-
@run_context.instance_exec(&task.block)
|
321
|
+
def process_script_task(event, task)
|
322
|
+
logger.trace { "Executing script '#{name}' run block with event(#{event})" }
|
323
|
+
@run_context.instance_exec(event, &task.block)
|
300
324
|
end
|
301
325
|
|
302
326
|
#
|
@@ -1112,7 +1112,6 @@ module OpenHAB
|
|
1112
1112
|
|
1113
1113
|
raise ArgumentError, "Missing cron expression or elements" unless expression
|
1114
1114
|
|
1115
|
-
add_tag("Schedule")
|
1116
1115
|
cron = Cron.new(rule_triggers: @rule_triggers)
|
1117
1116
|
cron.trigger(config: { "cronExpression" => expression }, attach: attach)
|
1118
1117
|
end
|
@@ -1211,7 +1210,6 @@ module OpenHAB
|
|
1211
1210
|
if value == :day && at.is_a?(Item)
|
1212
1211
|
raise ArgumentError, "Attachments are not supported with dynamic datetime triggers" unless attach.nil?
|
1213
1212
|
|
1214
|
-
add_tag("Schedule")
|
1215
1213
|
return trigger("timer.DateTimeTrigger", itemName: at.name, timeOnly: true)
|
1216
1214
|
end
|
1217
1215
|
|
@@ -1593,7 +1591,6 @@ module OpenHAB
|
|
1593
1591
|
#
|
1594
1592
|
def at(item)
|
1595
1593
|
item = item.name if item.is_a?(Item)
|
1596
|
-
add_tag("Schedule")
|
1597
1594
|
trigger("timer.DateTimeTrigger", itemName: item.to_s)
|
1598
1595
|
end
|
1599
1596
|
|
@@ -64,7 +64,7 @@ module OpenHAB
|
|
64
64
|
org.openhab.core.automation.util.TriggerBuilder.create
|
65
65
|
.with_id(uuid)
|
66
66
|
.with_type_uid(type)
|
67
|
-
.with_configuration(
|
67
|
+
.with_configuration(Core::Configuration.new(config))
|
68
68
|
.build
|
69
69
|
end
|
70
70
|
|
@@ -81,7 +81,8 @@ module OpenHAB
|
|
81
81
|
def process_active_timer(timer, inputs, mod, &block)
|
82
82
|
old_state = Conditions.old_state_from(inputs)
|
83
83
|
new_state = Conditions.new_state_from(inputs)
|
84
|
-
if new_state != @tracking_from &&
|
84
|
+
if @conditions.from? && new_state != @tracking_from &&
|
85
|
+
@conditions.process(mod: nil, inputs: { "state" => new_state })
|
85
86
|
logger.trace("Item changed from #{old_state} to #{new_state} for #{self}, keep waiting.")
|
86
87
|
else
|
87
88
|
logger.trace("Item changed from #{old_state} to #{new_state} for #{self}, canceling timer.")
|
@@ -12,7 +12,12 @@ module OpenHAB
|
|
12
12
|
#
|
13
13
|
class Cron < Trigger
|
14
14
|
# Trigger ID for Cron Triggers
|
15
|
-
CRON_TRIGGER_MODULE_ID = "
|
15
|
+
CRON_TRIGGER_MODULE_ID = if Gem::Version.new(OpenHAB::Core::VERSION) >= Gem::Version.new("4.0.0")
|
16
|
+
"timer.GenericCronTrigger"
|
17
|
+
else
|
18
|
+
# @deprecated OH3.4 We need to use a custom CronTrigger handler
|
19
|
+
"jsr223.jruby.CronTrigger"
|
20
|
+
end
|
16
21
|
|
17
22
|
#
|
18
23
|
# Returns a default map for cron expressions that fires every second
|
@@ -186,7 +191,10 @@ module OpenHAB
|
|
186
191
|
#
|
187
192
|
#
|
188
193
|
def trigger(config:, attach:)
|
189
|
-
|
194
|
+
# @deprecated OH3.4 needs a custom CronTriggerHandlerFactory
|
195
|
+
if Gem::Version.new(OpenHAB::Core::VERSION) < Gem::Version.new("4.0.0")
|
196
|
+
CronHandler::CronTriggerHandlerFactory.instance # ensure it's registered
|
197
|
+
end
|
190
198
|
append_trigger(type: CRON_TRIGGER_MODULE_ID, config: config, attach: attach)
|
191
199
|
end
|
192
200
|
end
|
@@ -1,115 +1,120 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative "cron"
|
6
|
-
|
7
|
-
module OpenHAB
|
8
|
-
module DSL
|
9
|
-
module Rules
|
10
|
-
module Triggers
|
11
|
-
# @!visibility private
|
12
|
-
#
|
13
|
-
# Cron trigger handler that provides trigger ID
|
14
|
-
#
|
15
|
-
module CronHandler
|
16
|
-
# Cron Trigger Handler that provides trigger IDs
|
17
|
-
# Unfortunatly because the CronTriggerHandler in openHAB core is marked internal
|
18
|
-
# the entire thing must be recreated here
|
19
|
-
class CronTriggerHandler < org.openhab.core.automation.handler.BaseTriggerModuleHandler
|
20
|
-
include org.openhab.core.scheduler.SchedulerRunnable
|
21
|
-
include org.openhab.core.automation.handler.TimeBasedTriggerHandler
|
22
|
-
|
23
|
-
# Provides access to protected fields
|
24
|
-
field_accessor :callback
|
25
|
-
|
26
|
-
# Creates a new CronTriggerHandler
|
27
|
-
# @param [org.openhab.core.automation.Trigger] trigger openHAB trigger associated with handler
|
28
|
-
#
|
29
|
-
def initialize(trigger)
|
30
|
-
@trigger = trigger
|
31
|
-
@scheduler = OSGi.service("org.openhab.core.scheduler.CronScheduler")
|
32
|
-
@schedule = nil
|
33
|
-
@expression = trigger.configuration.get("cronExpression")
|
34
|
-
super(trigger)
|
35
|
-
end
|
3
|
+
# @deprecated OH3.4 this module is not needed in OH4+
|
4
|
+
if Gem::Version.new(OpenHAB::Core::VERSION) < Gem::Version.new("4.0.0")
|
36
5
|
|
37
|
-
|
38
|
-
# Set the callback to execute when cron trigger fires
|
39
|
-
# @param [Object] callback to run
|
40
|
-
#
|
41
|
-
def setCallback(callback) # rubocop:disable Naming/MethodName
|
42
|
-
synchronized do
|
43
|
-
super(callback)
|
44
|
-
@schedule = @scheduler.schedule(self, @expression)
|
45
|
-
logger.trace("Scheduled cron job '#{@expression}' for trigger '#{@trigger.id}'.")
|
46
|
-
end
|
47
|
-
end
|
6
|
+
require "singleton"
|
48
7
|
|
49
|
-
|
50
|
-
# Get the temporal adjuster
|
51
|
-
# @return [CronAdjuster]
|
52
|
-
#
|
53
|
-
def getTemporalAdjuster # rubocop:disable Naming/MethodName
|
54
|
-
org.openhab.core.scheduler.CronAdjuster.new(@expression)
|
55
|
-
end
|
8
|
+
require_relative "cron"
|
56
9
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
10
|
+
module OpenHAB
|
11
|
+
module DSL
|
12
|
+
module Rules
|
13
|
+
module Triggers
|
14
|
+
# @!visibility private
|
15
|
+
#
|
16
|
+
# Cron trigger handler that provides trigger ID
|
17
|
+
#
|
18
|
+
module CronHandler
|
19
|
+
# Cron Trigger Handler that provides trigger IDs
|
20
|
+
# Unfortunatly because the CronTriggerHandler in openHAB core is marked internal
|
21
|
+
# the entire thing must be recreated here
|
22
|
+
class CronTriggerHandler < org.openhab.core.automation.handler.BaseTriggerModuleHandler
|
23
|
+
include org.openhab.core.scheduler.SchedulerRunnable
|
24
|
+
include org.openhab.core.automation.handler.TimeBasedTriggerHandler
|
63
25
|
|
64
|
-
|
65
|
-
|
66
|
-
# cancel the cron scheduled task
|
67
|
-
#
|
68
|
-
def dispose
|
69
|
-
synchronized do
|
70
|
-
super
|
71
|
-
return unless @schedule
|
26
|
+
# Provides access to protected fields
|
27
|
+
field_accessor :callback
|
72
28
|
|
73
|
-
|
29
|
+
# Creates a new CronTriggerHandler
|
30
|
+
# @param [org.openhab.core.automation.Trigger] trigger openHAB trigger associated with handler
|
31
|
+
#
|
32
|
+
def initialize(trigger)
|
33
|
+
@trigger = trigger
|
34
|
+
@scheduler = OSGi.service("org.openhab.core.scheduler.CronScheduler")
|
74
35
|
@schedule = nil
|
36
|
+
@expression = trigger.configuration.get("cronExpression")
|
37
|
+
super(trigger)
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Set the callback to execute when cron trigger fires
|
42
|
+
# @param [Object] callback to run
|
43
|
+
#
|
44
|
+
def setCallback(callback) # rubocop:disable Naming/MethodName
|
45
|
+
synchronized do
|
46
|
+
super(callback)
|
47
|
+
@schedule = @scheduler.schedule(self, @expression)
|
48
|
+
logger.trace("Scheduled cron job '#{@expression}' for trigger '#{@trigger.id}'.")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Get the temporal adjuster
|
54
|
+
# @return [CronAdjuster]
|
55
|
+
#
|
56
|
+
def getTemporalAdjuster # rubocop:disable Naming/MethodName
|
57
|
+
org.openhab.core.scheduler.CronAdjuster.new(@expression)
|
75
58
|
end
|
76
|
-
logger.trace("cancelled job for trigger '#{@trigger.id}'.")
|
77
|
-
end
|
78
|
-
end
|
79
59
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
60
|
+
#
|
61
|
+
# Execute the callback
|
62
|
+
#
|
63
|
+
def run
|
64
|
+
callback&.triggered(@trigger, { "module" => @trigger.id })
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Dispose of the handler
|
69
|
+
# cancel the cron scheduled task
|
70
|
+
#
|
71
|
+
def dispose
|
72
|
+
synchronized do
|
73
|
+
super
|
74
|
+
return unless @schedule
|
75
|
+
|
76
|
+
@schedule.cancel(true)
|
77
|
+
@schedule = nil
|
78
|
+
end
|
79
|
+
logger.trace("cancelled job for trigger '#{@trigger.id}'.")
|
80
|
+
end
|
101
81
|
end
|
102
82
|
|
103
|
-
#
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
83
|
+
# Implements the ScriptedTriggerHandlerFactory interface to create a new Cron Trigger Handler
|
84
|
+
class CronTriggerHandlerFactory
|
85
|
+
include Singleton
|
86
|
+
include org.openhab.core.automation.module.script.rulesupport.shared.factories.ScriptedTriggerHandlerFactory # rubocop:disable Layout/LineLength
|
87
|
+
|
88
|
+
def initialize
|
89
|
+
Core.automation_manager.add_trigger_handler(
|
90
|
+
Cron::CRON_TRIGGER_MODULE_ID,
|
91
|
+
self
|
92
|
+
)
|
93
|
+
|
94
|
+
Core.automation_manager.add_trigger_type(org.openhab.core.automation.type.TriggerType.new(
|
95
|
+
Cron::CRON_TRIGGER_MODULE_ID,
|
96
|
+
nil,
|
97
|
+
"A specific instant occurs",
|
98
|
+
"Triggers when the specified instant occurs",
|
99
|
+
nil,
|
100
|
+
org.openhab.core.automation.Visibility::VISIBLE,
|
101
|
+
nil
|
102
|
+
))
|
103
|
+
logger.trace("Added script cron trigger handler")
|
104
|
+
end
|
105
|
+
|
106
|
+
# Invoked by openHAB core to get a trigger handler for the supplied trigger
|
107
|
+
# @param [org.openhab.core.automation.Trigger] trigger
|
108
|
+
#
|
109
|
+
# @return [WatchTriggerHandler] trigger handler for supplied trigger
|
110
|
+
def get(trigger)
|
111
|
+
CronTriggerHandler.new(trigger)
|
112
|
+
end
|
109
113
|
end
|
110
114
|
end
|
111
115
|
end
|
112
116
|
end
|
113
117
|
end
|
114
118
|
end
|
119
|
+
|
115
120
|
end
|
@@ -24,10 +24,10 @@ module OpenHAB
|
|
24
24
|
# things.build do
|
25
25
|
# thing("mqtt:topic:my-switch", "My Switch", bridge: "mqtt:bridge:mosquitto", config: thing_config) do
|
26
26
|
# channel("switch1", "switch", config: {
|
27
|
-
# stateTopic: "stat/my-switch/switch1/state", commandTopic
|
27
|
+
# stateTopic: "stat/my-switch/switch1/state", commandTopic: "cmnd/my-switch/switch1/command"
|
28
28
|
# })
|
29
29
|
# channel("button1", "string", config: {
|
30
|
-
# stateTopic: "stat/my-switch/button1/state", commandTopic
|
30
|
+
# stateTopic: "stat/my-switch/button1/state", commandTopic: "cmnd/my-switch/button1/command"
|
31
31
|
# })
|
32
32
|
# end
|
33
33
|
# end
|
@@ -184,7 +184,7 @@ module OpenHAB
|
|
184
184
|
|
185
185
|
# @!visibility private
|
186
186
|
def build
|
187
|
-
configuration =
|
187
|
+
configuration = Core::Configuration.new(config)
|
188
188
|
if thing_type
|
189
189
|
self.class.thing_factory_helper.apply_default_configuration(
|
190
190
|
configuration, thing_type,
|
@@ -280,7 +280,7 @@ module OpenHAB
|
|
280
280
|
org.openhab.core.thing.binding.builder.ChannelBuilder.create(uid)
|
281
281
|
.with_kind(kind)
|
282
282
|
.with_type(type)
|
283
|
-
.with_configuration(
|
283
|
+
.with_configuration(Core::Configuration.new(config))
|
284
284
|
.build
|
285
285
|
end
|
286
286
|
|
@@ -89,7 +89,7 @@ module OpenHAB
|
|
89
89
|
# @param [Object] id
|
90
90
|
# @param [java.time.temporal.TemporalAmount, #to_zoned_date_time, Proc, nil] duration
|
91
91
|
# When to reschedule the timer for. `nil` to retain its current interval.
|
92
|
-
# @return [Timer, nil] the timer if it was rescheduled, otherwise `nil`
|
92
|
+
# @return [Core::Timer, nil] the timer if it was rescheduled, otherwise `nil`
|
93
93
|
#
|
94
94
|
def reschedule(id, duration = nil)
|
95
95
|
@timers_by_id.compute_if_present(id) do |_key, timer|
|
@@ -105,10 +105,10 @@ module OpenHAB
|
|
105
105
|
# state. The timer is created in a thread-safe manner.
|
106
106
|
#
|
107
107
|
# @param [Object] id
|
108
|
-
# @yieldparam [Timer, nil] timer The existing timer with this id, if one exists.
|
109
|
-
# @yieldreturn [Timer, nil] A new timer to associate with this id, the existing
|
108
|
+
# @yieldparam [Core::Timer, nil] timer The existing timer with this id, if one exists.
|
109
|
+
# @yieldreturn [Core::Timer, nil] A new timer to associate with this id, the existing
|
110
110
|
# timer, or nil. If nil, any existing timer will be cancelled.
|
111
|
-
# @return [Timer, nil]
|
111
|
+
# @return [Core::Timer, nil]
|
112
112
|
#
|
113
113
|
# @example Extend an existing timer, or schedule a new one
|
114
114
|
# # This is technically the same functionality as just calling `after()` with an `id`,
|
data/lib/openhab/dsl/version.rb
CHANGED
data/lib/openhab/dsl.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "java"
|
4
4
|
require "method_source"
|
5
|
+
require "ruby2_keywords"
|
5
6
|
|
6
7
|
require "bundler/inline"
|
7
8
|
|
@@ -77,16 +78,16 @@ module OpenHAB
|
|
77
78
|
# Defines a new profile that can be applied to item channel links.
|
78
79
|
#
|
79
80
|
# @param [String, Symbol] id The id for the profile.
|
80
|
-
# @yield [event, command: nil, state: nil, link:, item:, channel_uid:, configuration:, context:]
|
81
|
+
# @yield [event, command: nil, state: nil, callback:, link:, item:, channel_uid:, configuration:, context:]
|
81
82
|
# All keyword params are optional. Any that aren't defined won't be passed.
|
82
|
-
# @yieldparam [Core::Things::ProfileCallback] callback
|
83
|
-
# The callback to be used to customize the action taken.
|
84
83
|
# @yieldparam [:command_from_item, :state_from_item, :command_from_handler, :state_from_handler] event
|
85
84
|
# The event that needs to be processed.
|
86
85
|
# @yieldparam [Command, nil] command
|
87
86
|
# The command being sent for `:command_from_item` and `:command_from_handler` events.
|
88
87
|
# @yieldparam [State, nil] state
|
89
88
|
# The state being sent for `:state_from_item` and `:state_from_handler` events.
|
89
|
+
# @yieldparam [Core::Things::ProfileCallback] callback
|
90
|
+
# The callback to be used to customize the action taken.
|
90
91
|
# @yieldparam [Core::Things::ItemChannelLink] link
|
91
92
|
# The link between the item and the channel, including its configuration.
|
92
93
|
# @yieldparam [Item] item The linked item.
|
@@ -115,7 +116,7 @@ module OpenHAB
|
|
115
116
|
# # Rollershutter MyShade { channel="thing:rollershutter"[profile="ruby:veto_closing_shades"] }
|
116
117
|
#
|
117
118
|
# @example Overriding units from a binding
|
118
|
-
# profile(:set_uom) do |event, configuration:, state:, command:|
|
119
|
+
# profile(:set_uom) do |event, callback:, configuration:, state:, command:|
|
119
120
|
# unless configuration["unit"]
|
120
121
|
# logger.warn("Unit configuration not provided for set_uom profile")
|
121
122
|
# next true
|
@@ -970,6 +971,24 @@ module OpenHAB
|
|
970
971
|
|
971
972
|
raise exception
|
972
973
|
end
|
974
|
+
|
975
|
+
#
|
976
|
+
# Provide access to the script context / variables
|
977
|
+
# see OpenHAB::DSL::Rules::AutomationRule#execute!
|
978
|
+
#
|
979
|
+
# @!visibility private
|
980
|
+
ruby2_keywords def method_missing(method, *args)
|
981
|
+
return super unless args.empty? && !block_given?
|
982
|
+
return super unless (context = Thread.current[:openhab_context]) && context.key?(method)
|
983
|
+
|
984
|
+
logger.trace("DSL#method_missing found context variable: '#{method}'")
|
985
|
+
context[method]
|
986
|
+
end
|
987
|
+
|
988
|
+
# @!visibility private
|
989
|
+
def respond_to_missing?(method, include_private = false)
|
990
|
+
Thread.current[:openhab_context]&.key?(method) || super
|
991
|
+
end
|
973
992
|
end
|
974
993
|
end
|
975
994
|
|
data/lib/openhab/log.rb
CHANGED
@@ -296,8 +296,8 @@ module OpenHAB
|
|
296
296
|
return error if debug?
|
297
297
|
|
298
298
|
if error.respond_to? :backtrace_locations
|
299
|
-
backtrace = error.backtrace_locations
|
300
|
-
error.set_backtrace(backtrace)
|
299
|
+
backtrace = error.backtrace_locations&.map(&:to_s)&.grep_v(INTERNAL_CALL_REGEX)
|
300
|
+
error.set_backtrace(backtrace) if backtrace
|
301
301
|
elsif error.respond_to? :stack_trace
|
302
302
|
backtrace = error.stack_trace.reject { |line| JAVA_INTERNAL_CALL_REGEX.match? line.to_s }
|
303
303
|
error.set_stack_trace(backtrace)
|
@@ -229,8 +229,17 @@ module OpenHAB
|
|
229
229
|
bundle = org.osgi.framework.FrameworkUtil.get_bundle(org.openhab.core.persistence.PersistenceService.java_class)
|
230
230
|
bundle.bundle_context.register_service(org.openhab.core.persistence.PersistenceService.java_class, ps, nil)
|
231
231
|
|
232
|
-
# wait for the rule engine
|
233
232
|
rs = OSGi.service("org.openhab.core.service.ReadyService")
|
233
|
+
|
234
|
+
# Add a fake automation:scriptEngineFactories to satisfy startlevel 30
|
235
|
+
begin
|
236
|
+
sef_marker = org.openhab.core.automation.module.script.internal.ScriptEngineFactoryBundleTracker::READY_MARKER
|
237
|
+
rs.mark_ready(sef_marker)
|
238
|
+
rescue NameError
|
239
|
+
# @deprecated OH3.4 NOOP - the ScriptEngineFactoryBundleTracker doesn't exist in OH3
|
240
|
+
end
|
241
|
+
|
242
|
+
# wait for the rule engine
|
234
243
|
filter = org.openhab.core.service.ReadyMarkerFilter.new
|
235
244
|
.with_type(org.openhab.core.service.StartLevelService::STARTLEVEL_MARKER_TYPE)
|
236
245
|
.with_identifier(org.openhab.core.service.StartLevelService::STARTLEVEL_RULEENGINE.to_s)
|