openhab-scripting 4.32.5 → 4.33.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/entity_lookup.rb +0 -4
- data/lib/openhab/core/openhab_setup.rb +1 -2
- data/lib/openhab/core/thread_local.rb +12 -2
- data/lib/openhab/dsl/actions.rb +2 -0
- data/lib/openhab/dsl/between.rb +2 -0
- data/lib/openhab/dsl/dsl.rb +2 -2
- data/lib/openhab/dsl/group.rb +15 -11
- data/lib/openhab/dsl/items/ensure.rb +68 -66
- data/lib/openhab/dsl/items/generic_item.rb +1 -1
- data/lib/openhab/dsl/items/item_registry.rb +11 -6
- data/lib/openhab/dsl/items/items.rb +2 -2
- data/lib/openhab/dsl/items/metadata.rb +1 -2
- data/lib/openhab/dsl/items/timed_command.rb +11 -9
- data/lib/openhab/dsl/monkey_patch/ruby/number.rb +0 -2
- data/lib/openhab/dsl/openhab.rb +2 -0
- data/lib/openhab/dsl/persistence.rb +2 -0
- data/lib/openhab/dsl/rules/automation_rule.rb +4 -5
- data/lib/openhab/dsl/rules/rule.rb +104 -95
- data/lib/openhab/dsl/rules/rule_config.rb +1 -2
- data/lib/openhab/dsl/rules/rule_triggers.rb +1 -3
- data/lib/openhab/dsl/rules/terse.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/changed.rb +6 -5
- data/lib/openhab/dsl/rules/triggers/channel.rb +2 -0
- data/lib/openhab/dsl/rules/triggers/command.rb +6 -5
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +2 -2
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +2 -2
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +4 -2
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +2 -2
- data/lib/openhab/dsl/rules/triggers/generic.rb +3 -2
- data/lib/openhab/dsl/rules/triggers/trigger.rb +2 -2
- data/lib/openhab/dsl/rules/triggers/updated.rb +9 -8
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +8 -3
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +3 -3
- data/lib/openhab/dsl/states.rb +34 -20
- data/lib/openhab/dsl/things.rb +2 -0
- data/lib/openhab/dsl/time/month_day.rb +2 -2
- data/lib/openhab/dsl/timers/manager.rb +4 -3
- data/lib/openhab/dsl/timers/reentrant_timer.rb +22 -27
- data/lib/openhab/dsl/timers/timer.rb +89 -95
- data/lib/openhab/dsl/timers.rb +7 -3
- data/lib/openhab/dsl/types/decimal_type.rb +3 -2
- data/lib/openhab/dsl/types/point_type.rb +4 -3
- data/lib/openhab/dsl/types/quantity_type.rb +0 -4
- data/lib/openhab/dsl/types/types.rb +24 -24
- data/lib/openhab/dsl/units.rb +2 -0
- data/lib/openhab/log/logger.rb +10 -24
- data/lib/openhab/version.rb +1 -1
- data/lib/openhab.rb +2 -8
- metadata +2 -2
data/lib/openhab/dsl/states.rb
CHANGED
@@ -8,12 +8,45 @@ module OpenHAB
|
|
8
8
|
# Manages storing and restoring item state
|
9
9
|
#
|
10
10
|
module States
|
11
|
-
|
11
|
+
module_function
|
12
12
|
|
13
|
+
#
|
14
|
+
# Store states of supplied items
|
15
|
+
#
|
16
|
+
# @param [Array] items to store states of
|
17
|
+
#
|
18
|
+
# @return [StateStorage] item states
|
19
|
+
#
|
20
|
+
def store_states(*items)
|
21
|
+
items = items.flatten.map do |item|
|
22
|
+
item.respond_to?(:__getobj__) ? item.__getobj__ : item
|
23
|
+
end
|
24
|
+
states = OpenHAB::DSL::Support::StateStorage.from_items(*items)
|
25
|
+
if block_given?
|
26
|
+
yield
|
27
|
+
states.restore
|
28
|
+
end
|
29
|
+
states
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Support
|
34
|
+
java_import org.openhab.core.model.script.actions.BusEvent
|
13
35
|
#
|
14
36
|
# Delegates state storage to a Hash providing methods to operate with states
|
15
37
|
#
|
16
38
|
class StateStorage < SimpleDelegator
|
39
|
+
#
|
40
|
+
# Create a StateStorage object that stores the states of the given items
|
41
|
+
#
|
42
|
+
# @param [Array<Item>] *items A list of items
|
43
|
+
#
|
44
|
+
# @return [StateStorage] A state storage object
|
45
|
+
#
|
46
|
+
def self.from_items(*items)
|
47
|
+
StateStorage.new(BusEvent.storeStates(*items).to_h)
|
48
|
+
end
|
49
|
+
|
17
50
|
#
|
18
51
|
# Restore the stored states of all items
|
19
52
|
#
|
@@ -39,25 +72,6 @@ module OpenHAB
|
|
39
72
|
any? { |item, value| item != value }
|
40
73
|
end
|
41
74
|
end
|
42
|
-
|
43
|
-
#
|
44
|
-
# Store states of supplied items
|
45
|
-
#
|
46
|
-
# @param [Array] items to store states of
|
47
|
-
#
|
48
|
-
# @return [StateStorage] item states
|
49
|
-
#
|
50
|
-
def store_states(*items)
|
51
|
-
items = items.flatten.map do |item|
|
52
|
-
item.respond_to?(:__getobj__) ? item.__getobj__ : item
|
53
|
-
end
|
54
|
-
states = StateStorage.new(BusEvent.storeStates(*items).to_h)
|
55
|
-
if block_given?
|
56
|
-
yield
|
57
|
-
states.restore
|
58
|
-
end
|
59
|
-
states
|
60
|
-
end
|
61
75
|
end
|
62
76
|
end
|
63
77
|
end
|
data/lib/openhab/dsl/things.rb
CHANGED
@@ -48,8 +48,8 @@ module OpenHAB
|
|
48
48
|
DAYS_IN_YEAR = 366
|
49
49
|
|
50
50
|
# Create a new MonthDayRange element
|
51
|
-
# @param [MonthDay] MonthDay element
|
52
|
-
# @param [Range] Underlying MonthDay range
|
51
|
+
# @param [MonthDay] month_day MonthDay element
|
52
|
+
# @param [Range] range Underlying MonthDay range
|
53
53
|
#
|
54
54
|
def initialize(month_day:, range:)
|
55
55
|
@month_day = month_day
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'set'
|
3
4
|
require 'openhab/log/logger'
|
4
5
|
require_relative 'reentrant_timer'
|
5
6
|
|
6
7
|
module OpenHAB
|
7
8
|
module DSL
|
8
9
|
#
|
9
|
-
# Provides
|
10
|
+
# Provides supporting classes for Timers module
|
10
11
|
#
|
11
|
-
module
|
12
|
+
module Support
|
12
13
|
#
|
13
14
|
# Manages data structures that track timers
|
14
15
|
#
|
@@ -52,7 +53,7 @@ module OpenHAB
|
|
52
53
|
|
53
54
|
# Fetches the reentrant timer that matches the supplied id and block if it exists
|
54
55
|
#
|
55
|
-
# @param [Object] Object to associate with timer
|
56
|
+
# @param [Object] id Object to associate with timer
|
56
57
|
# @param [Block] block to execute, block is passed a Timer object
|
57
58
|
#
|
58
59
|
# @return [RentrantTimer] Timer object if it exists, nil otherwise
|
@@ -5,38 +5,33 @@ require_relative 'timer'
|
|
5
5
|
|
6
6
|
module OpenHAB
|
7
7
|
module DSL
|
8
|
+
# A reentrant timer is a timer that is automatically rescheduled
|
9
|
+
# when the block it refers to is encountered again
|
8
10
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
# when the block it refers to is encountered again
|
14
|
-
#
|
15
|
-
# @author Brian O'Connell
|
16
|
-
# @since 2.0.0
|
17
|
-
class ReentrantTimer < Timer
|
18
|
-
include OpenHAB::Log
|
11
|
+
# @author Brian O'Connell
|
12
|
+
# @since 2.0.0
|
13
|
+
class ReentrantTimer < Timer
|
14
|
+
include OpenHAB::Log
|
19
15
|
|
20
|
-
|
16
|
+
attr_reader :id, :reentrant_id
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
#
|
19
|
+
# Create a new Timer Object
|
20
|
+
#
|
21
|
+
# @param [Duration] duration Duration until timer should fire
|
22
|
+
# @param [Block] block Block to execute when timer fires
|
23
|
+
#
|
24
|
+
def initialize(duration:, id:, thread_locals: {}, &block)
|
25
|
+
raise 'Reentrant timers do not work in dynamically generated code' unless block.source_location
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
@id = id
|
28
|
+
@reentrant_id = self.class.reentrant_id(id: id, &block)
|
29
|
+
super(duration: duration, thread_locals: thread_locals, &block)
|
30
|
+
logger.trace("Created Reentrant Timer #{self} with reentrant Key #{@reentrant_id}")
|
31
|
+
end
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
33
|
+
def self.reentrant_id(id:, &block)
|
34
|
+
[id, block.source_location].flatten
|
40
35
|
end
|
41
36
|
end
|
42
37
|
end
|
@@ -8,115 +8,109 @@ require 'openhab/core/thread_local'
|
|
8
8
|
|
9
9
|
module OpenHAB
|
10
10
|
module DSL
|
11
|
+
java_import org.openhab.core.model.script.actions.ScriptExecution
|
12
|
+
java_import java.time.ZonedDateTime
|
13
|
+
|
14
|
+
# Ruby wrapper for OpenHAB Timer
|
15
|
+
# This class implements delegator to delegate methods to the OpenHAB timer
|
11
16
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
17
|
+
# @author Brian O'Connell
|
18
|
+
# @since 2.0.0
|
19
|
+
class Timer < SimpleDelegator
|
15
20
|
include OpenHAB::Log
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# Ruby wrapper for OpenHAB Timer
|
20
|
-
# This class implements delegator to delegate methods to the OpenHAB timer
|
21
|
-
#
|
22
|
-
# @author Brian O'Connell
|
23
|
-
# @since 2.0.0
|
24
|
-
class Timer < SimpleDelegator
|
25
|
-
include OpenHAB::Log
|
26
|
-
include OpenHAB::Core::ThreadLocal
|
27
|
-
extend Forwardable
|
21
|
+
include OpenHAB::Core::ThreadLocal
|
22
|
+
extend Forwardable
|
28
23
|
|
29
|
-
|
24
|
+
def_delegator :@timer, :has_terminated, :terminated?
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
26
|
+
#
|
27
|
+
# Create a new Timer Object
|
28
|
+
#
|
29
|
+
# @param [Duration] duration Duration until timer should fire
|
30
|
+
# @param [Block] block Block to execute when timer fires
|
31
|
+
#
|
32
|
+
# rubocop: disable Metrics/MethodLength
|
33
|
+
def initialize(duration:, thread_locals: {}, &block)
|
34
|
+
@duration = duration
|
35
|
+
@thread_locals = thread_locals
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
# A semaphore is used to prevent a race condition in which calling the block from the timer thread
|
38
|
+
# occurs before the @timer variable can be set resulting in @timer being nil
|
39
|
+
semaphore = Mutex.new
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
41
|
+
semaphore.synchronize do
|
42
|
+
@timer = ScriptExecution.createTimer(
|
43
|
+
ZonedDateTime.now.plus(to_duration(@duration)), timer_block(semaphore, &block)
|
44
|
+
)
|
45
|
+
@rule_timers = Thread.current[:rule_timers]
|
46
|
+
super(@timer)
|
47
|
+
Timers.timer_manager.add(self)
|
54
48
|
end
|
55
|
-
|
49
|
+
end
|
50
|
+
# rubocop: enable Metrics/MethodLength
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
#
|
53
|
+
# Reschedule timer
|
54
|
+
#
|
55
|
+
# @param [Duration] duration
|
56
|
+
#
|
57
|
+
# @return [Timer] Rescheduled timer instances
|
58
|
+
#
|
59
|
+
def reschedule(duration = nil)
|
60
|
+
duration ||= @duration
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
Timers.timer_manager.add(self)
|
63
|
+
@timer.reschedule(ZonedDateTime.now.plus(to_duration(duration)))
|
64
|
+
end
|
70
65
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
66
|
+
#
|
67
|
+
# Cancel timer
|
68
|
+
#
|
69
|
+
# @return [Boolean] True if cancel was successful, false otherwise
|
70
|
+
#
|
71
|
+
def cancel
|
72
|
+
Timers.timer_manager.delete(self)
|
73
|
+
@timer.cancel
|
74
|
+
end
|
80
75
|
|
81
|
-
|
76
|
+
private
|
82
77
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
78
|
+
#
|
79
|
+
# Constructs a block to execute timer within
|
80
|
+
#
|
81
|
+
# @param [Semaphore] semaphore to obtain before executing
|
82
|
+
#
|
83
|
+
# @return [Proc] Block for timer to execute
|
84
|
+
#
|
85
|
+
def timer_block(semaphore)
|
86
|
+
proc {
|
87
|
+
semaphore.synchronize do
|
88
|
+
Timers.timer_manager.delete(self)
|
89
|
+
thread_local(@thread_locals) do
|
90
|
+
yield(self)
|
97
91
|
end
|
98
|
-
}
|
99
|
-
end
|
100
|
-
|
101
|
-
#
|
102
|
-
# Convert argument to a duration
|
103
|
-
#
|
104
|
-
# @params [Java::JavaTimeTemporal::TemporalAmount, #to_f, #to_i, nil] duration Duration
|
105
|
-
#
|
106
|
-
# @raise if duration cannot be used for a timer
|
107
|
-
#
|
108
|
-
# @return Argument converted to seconds if it responds to #to_f or #to_i, otherwise duration unchanged
|
109
|
-
#
|
110
|
-
def to_duration(duration)
|
111
|
-
if duration.nil? || duration.is_a?(Java::JavaTimeTemporal::TemporalAmount)
|
112
|
-
duration
|
113
|
-
elsif duration.respond_to?(:to_f)
|
114
|
-
duration.to_f.seconds
|
115
|
-
elsif duration.respond_to?(:to_i)
|
116
|
-
duration.to_i.seconds
|
117
|
-
else
|
118
|
-
raise ArgumentError, "Supplied argument '#{duration}' cannot be converted to a duration"
|
119
92
|
end
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Convert argument to a duration
|
98
|
+
#
|
99
|
+
# @param [Java::JavaTimeTemporal::TemporalAmount, #to_f, #to_i, nil] duration Duration
|
100
|
+
#
|
101
|
+
# @raise if duration cannot be used for a timer
|
102
|
+
#
|
103
|
+
# @return Argument converted to seconds if it responds to #to_f or #to_i, otherwise duration unchanged
|
104
|
+
#
|
105
|
+
def to_duration(duration)
|
106
|
+
if duration.nil? || duration.is_a?(Java::JavaTimeTemporal::TemporalAmount)
|
107
|
+
duration
|
108
|
+
elsif duration.respond_to?(:to_f)
|
109
|
+
duration.to_f.seconds
|
110
|
+
elsif duration.respond_to?(:to_i)
|
111
|
+
duration.to_i.seconds
|
112
|
+
else
|
113
|
+
raise ArgumentError, "Supplied argument '#{duration}' cannot be converted to a duration"
|
120
114
|
end
|
121
115
|
end
|
122
116
|
end
|
data/lib/openhab/dsl/timers.rb
CHANGED
@@ -13,12 +13,14 @@ module OpenHAB
|
|
13
13
|
include OpenHAB::Log
|
14
14
|
|
15
15
|
# Manages timers
|
16
|
-
@timer_manager = TimerManager.new
|
16
|
+
@timer_manager = OpenHAB::DSL::Support::TimerManager.new
|
17
17
|
|
18
18
|
class << self
|
19
19
|
attr_reader :timer_manager
|
20
20
|
end
|
21
21
|
|
22
|
+
module_function
|
23
|
+
|
22
24
|
#
|
23
25
|
# Execute the supplied block after the specified duration
|
24
26
|
#
|
@@ -34,8 +36,10 @@ module OpenHAB
|
|
34
36
|
thread_locals ||= {}
|
35
37
|
return Timers.reentrant_timer(duration: duration, thread_locals: thread_locals, id: id, &block) if id
|
36
38
|
|
37
|
-
Timer.new(duration: duration, thread_locals: thread_locals, &block)
|
39
|
+
OpenHAB::DSL::Timer.new(duration: duration, thread_locals: thread_locals, &block)
|
38
40
|
end
|
41
|
+
# An alias for +after+
|
42
|
+
alias create_timer after
|
39
43
|
|
40
44
|
#
|
41
45
|
# Provdes access to the hash for mapping timer ids to the set of active timers associated with that id
|
@@ -66,7 +70,7 @@ module OpenHAB
|
|
66
70
|
else
|
67
71
|
logger.trace('No reentrant timer found, creating new timer')
|
68
72
|
end
|
69
|
-
ReentrantTimer.new(duration: duration, id: id, thread_locals: thread_locals, &block)
|
73
|
+
OpenHAB::DSL::ReentrantTimer.new(duration: duration, id: id, thread_locals: thread_locals, &block)
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
@@ -22,9 +22,10 @@ module OpenHAB
|
|
22
22
|
include ComparableType
|
23
23
|
|
24
24
|
#
|
25
|
-
# Create a new instance of
|
25
|
+
# Create a new instance of DecimalType
|
26
|
+
#
|
27
|
+
# @param [java.math.BigDecimal, Items::NumericItem, Numeric] args Create a DecimalType from the given value
|
26
28
|
#
|
27
|
-
# @param value [java.math.BigDecimal, Items::NumericItem, Numeric]
|
28
29
|
def initialize(*args) # rubocop:disable Metrics
|
29
30
|
unless args.length == 1
|
30
31
|
super
|
@@ -13,9 +13,10 @@ module OpenHAB
|
|
13
13
|
class PointType
|
14
14
|
# @!parse include PrimitiveType
|
15
15
|
|
16
|
-
# @
|
17
|
-
#
|
18
|
-
#
|
16
|
+
# @overload initialize(latitude, longitude, altitude)
|
17
|
+
# @param [DecimalType, QuantityType, StringType, Numeric] latitude
|
18
|
+
# @param [DecimalType, QuantityType, StringType, Numeric] longitude
|
19
|
+
# @param [DecimalType, QuantityType, StringType, Numeric] altitude
|
19
20
|
def initialize(*args) # rubocop:disable Metrics
|
20
21
|
args = from_hash(args.first.to_hash) if args.first.respond_to? :to_hash
|
21
22
|
if (2..3).cover?(args.length)
|
@@ -24,6 +24,28 @@ require_relative 'un_def_type'
|
|
24
24
|
|
25
25
|
module OpenHAB
|
26
26
|
module DSL
|
27
|
+
# Hash taking a Enum value, and returning two symbols of
|
28
|
+
# predicates to be defined for it. the first is the "command" form,
|
29
|
+
# which should be defined on ItemCommandEvent, and on the Type itself.
|
30
|
+
# the second is "state" form, which should be defined on the applicable
|
31
|
+
# Item, and on the Type itself.
|
32
|
+
# @!visibility private
|
33
|
+
PREDICATE_ALIASES = Hash.new { |_h, k| [:"#{k.downcase}?"] * 2 }
|
34
|
+
.merge({
|
35
|
+
'PLAY' => %i[play? playing?],
|
36
|
+
'PAUSE' => %i[pause? paused?],
|
37
|
+
'REWIND' => %i[rewind? rewinding?],
|
38
|
+
'FASTFORWARD' => %i[fast_forward? fast_forwarding?]
|
39
|
+
}).freeze
|
40
|
+
|
41
|
+
# Hash taking a Enum value, and returning an array of symbols
|
42
|
+
# of the command to define for it
|
43
|
+
# @!visibility private
|
44
|
+
COMMAND_ALIASES = Hash.new { |_h, k| k.downcase.to_sym }
|
45
|
+
.merge({
|
46
|
+
'FASTFORWARD' => :fast_forward
|
47
|
+
}).freeze
|
48
|
+
|
27
49
|
#
|
28
50
|
# Contains all OpenHAB *Type classes, as well as associated support
|
29
51
|
# modules
|
@@ -31,28 +53,6 @@ module OpenHAB
|
|
31
53
|
module Types
|
32
54
|
include OpenHAB::Log
|
33
55
|
|
34
|
-
# Hash taking a Enum value, and returning two symbols of
|
35
|
-
# predicates to be defined for it. the first is the "command" form,
|
36
|
-
# which should be defined on ItemCommandEvent, and on the Type itself.
|
37
|
-
# the second is "state" form, which should be defined on the applicable
|
38
|
-
# Item, and on the Type itself.
|
39
|
-
# @!visibility private
|
40
|
-
PREDICATE_ALIASES = Hash.new { |_h, k| [:"#{k.downcase}?"] * 2 }
|
41
|
-
.merge({
|
42
|
-
'PLAY' => %i[play? playing?],
|
43
|
-
'PAUSE' => %i[pause? paused?],
|
44
|
-
'REWIND' => %i[rewind? rewinding?],
|
45
|
-
'FASTFORWARD' => %i[fast_forward? fast_forwarding?]
|
46
|
-
}).freeze
|
47
|
-
|
48
|
-
# Hash taking a Enum value, and returning an array of symbols
|
49
|
-
# of the command to define for it
|
50
|
-
# @!visibility private
|
51
|
-
COMMAND_ALIASES = Hash.new { |_h, k| k.downcase.to_sym }
|
52
|
-
.merge({
|
53
|
-
'FASTFORWARD' => :fast_forward
|
54
|
-
}).freeze
|
55
|
-
|
56
56
|
constants.map { |c| const_get(c) }
|
57
57
|
.grep(Module)
|
58
58
|
.select { |k| k < java.lang.Enum }
|
@@ -65,8 +65,8 @@ module OpenHAB
|
|
65
65
|
# include all the aliases that we define for items both command and
|
66
66
|
# state aliases (since types can be interrogated as an incoming
|
67
67
|
# command, or as the state of an item)
|
68
|
-
command = :"#{COMMAND_ALIASES[value.to_s]}?"
|
69
|
-
states = PREDICATE_ALIASES[value.to_s]
|
68
|
+
command = :"#{OpenHAB::DSL::COMMAND_ALIASES[value.to_s]}?"
|
69
|
+
states = OpenHAB::DSL::PREDICATE_ALIASES[value.to_s]
|
70
70
|
|
71
71
|
([command] | states).each do |method|
|
72
72
|
logger.trace("Defining #{klass}##{method} for #{value}")
|
data/lib/openhab/dsl/units.rb
CHANGED
@@ -17,6 +17,8 @@ module OpenHAB
|
|
17
17
|
# Provides support for interacting with OpenHAB Units of Measurement
|
18
18
|
#
|
19
19
|
module Units
|
20
|
+
module_function
|
21
|
+
|
20
22
|
# @return The default unit for the current thread
|
21
23
|
def unit(unit = nil, &block)
|
22
24
|
return with_unit(unit, &block) if unit || block # back-compat
|
data/lib/openhab/log/logger.rb
CHANGED
@@ -2,13 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'openhab/log/configuration'
|
4
4
|
require 'java'
|
5
|
-
require 'pp'
|
6
5
|
|
7
6
|
module OpenHAB
|
8
|
-
#
|
9
|
-
# Provides access to the OpenHAB logging using a Ruby logging methods
|
10
|
-
#
|
11
|
-
|
12
7
|
module Core
|
13
8
|
#
|
14
9
|
# Ruby Logger that forwards messages at appropriate levels to OpenHAB Logger
|
@@ -65,7 +60,7 @@ module OpenHAB
|
|
65
60
|
#
|
66
61
|
# Logs a map of key(value) with an optional preamble at trace level
|
67
62
|
# @param [String] preamble to put at start of log message
|
68
|
-
# @param [Hash] key and values to log
|
63
|
+
# @param [Hash] kwargs key and values to log
|
69
64
|
def state(preamble = 'State:', **kwargs)
|
70
65
|
return unless trace_enabled?
|
71
66
|
|
@@ -102,7 +97,8 @@ module OpenHAB
|
|
102
97
|
#
|
103
98
|
# Print error and stack trace without calls to internal classes
|
104
99
|
#
|
105
|
-
# @param [Exception]
|
100
|
+
# @param [Exception] exception A rescued error
|
101
|
+
# @param [String] rule_name The name of the rule where the exception occurred
|
106
102
|
#
|
107
103
|
def log_exception(exception, rule_name)
|
108
104
|
exception = clean_backtrace(exception)
|
@@ -157,10 +153,11 @@ module OpenHAB
|
|
157
153
|
end
|
158
154
|
end
|
159
155
|
|
156
|
+
#
|
157
|
+
# Provides access to the OpenHAB logging using a Ruby logging methods
|
158
|
+
#
|
160
159
|
module Log
|
161
|
-
|
162
|
-
# Ruby Logger that forwards messages at appropriate levels to OpenHAB Logger
|
163
|
-
#
|
160
|
+
module_function
|
164
161
|
|
165
162
|
# Logger caches
|
166
163
|
@loggers = {}
|
@@ -180,7 +177,7 @@ module OpenHAB
|
|
180
177
|
#
|
181
178
|
# Injects a logger into the base class
|
182
179
|
#
|
183
|
-
# @param [
|
180
|
+
# @param [Object] object the logger is for
|
184
181
|
#
|
185
182
|
# @return [Logger] for the supplied name
|
186
183
|
#
|
@@ -189,7 +186,7 @@ module OpenHAB
|
|
189
186
|
# of logger name requires lots of operations and logger
|
190
187
|
# names for some objects are specific to the class
|
191
188
|
logger_name = logger_name(object)
|
192
|
-
@loggers[logger_name] ||=
|
189
|
+
@loggers[logger_name] ||= Core::Logger.new(logger_name)
|
193
190
|
end
|
194
191
|
|
195
192
|
private
|
@@ -230,11 +227,7 @@ module OpenHAB
|
|
230
227
|
end
|
231
228
|
|
232
229
|
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
# @param [String] classname to create logger for
|
236
|
-
#
|
237
|
-
# @return [Logger] Logger for the supplied classname
|
230
|
+
# Returns the rules file name
|
238
231
|
#
|
239
232
|
def rules_file
|
240
233
|
# Each rules file gets its own context
|
@@ -256,13 +249,6 @@ module OpenHAB
|
|
256
249
|
klass_name
|
257
250
|
end
|
258
251
|
|
259
|
-
# "#{rule_name.downcase}.#{klass_name}"
|
260
|
-
# if klass_name == 'Object'
|
261
|
-
# "rules.#{rules_file_name.downcase}"
|
262
|
-
# else
|
263
|
-
# "rules.#{rules_file_name.downcase}.#{klass_name}"
|
264
|
-
# end
|
265
|
-
|
266
252
|
#
|
267
253
|
# Figure out the log prefix
|
268
254
|
#
|
data/lib/openhab/version.rb
CHANGED
data/lib/openhab.rb
CHANGED
@@ -19,16 +19,13 @@ module OpenHAB
|
|
19
19
|
#
|
20
20
|
# @param [Object] base Object to decorate with DSL and helper methods
|
21
21
|
#
|
22
|
-
#
|
23
|
-
# Number of extensions and includes requires more lines
|
24
22
|
def self.extended(base)
|
25
23
|
OpenHAB::Core.wait_till_openhab_ready
|
26
|
-
base.extend Log
|
27
24
|
base.extend OpenHAB::Core::ScriptHandling
|
25
|
+
base.extend OpenHAB::Core::ScriptHandlingCallbacks
|
28
26
|
base.extend OpenHAB::Core::EntityLookup
|
29
27
|
base.extend OpenHAB::DSL
|
30
28
|
|
31
|
-
base.send :include, OpenHAB::Core::ScriptHandlingCallbacks
|
32
29
|
logger.debug "OpenHAB JRuby Scripting Library Version #{OpenHAB::VERSION} Loaded"
|
33
30
|
|
34
31
|
OpenHAB::Core.add_rubylib_to_load_path
|
@@ -36,7 +33,4 @@ module OpenHAB
|
|
36
33
|
end
|
37
34
|
|
38
35
|
# Extend caller with OpenHAB methods
|
39
|
-
|
40
|
-
# rubocop: disable Style/MixinUsage
|
41
|
-
extend OpenHAB
|
42
|
-
# rubocop: enable Style/MixinUsage
|
36
|
+
extend OpenHAB # rubocop:disable Style/MixinUsage
|