openhab-scripting 4.32.6 → 4.32.7
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.
- 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 +71 -71
- 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 +7 -6
- 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 +2 -3
- data/lib/openhab/dsl/timers.rb +4 -2
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1741788eaf0826f7b5e2c69935c96b21399771b3332a89debc77992c4ef687d0
|
4
|
+
data.tar.gz: b1200a71458efe21d389631bc29d2ef7d073ae5128706009a12b9a35af559bd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9317316f15b212005f6f9cb4013c6fb80739b8c427a8685b0610d5c6127a1ed676584f62258efe38a757966f4c9e51f61064a70a486ec2bd4d0e98c52dbe9255
|
7
|
+
data.tar.gz: d28a7872616e92eefa43e198f8211ee6ccb4408f418bb942ea82b6a8c9af572f9d6adc2e8fe929d8a2ba5bff19138f238be0e7951f75bf9567800e5681c68381
|
@@ -17,9 +17,8 @@ module OpenHAB
|
|
17
17
|
#
|
18
18
|
# Wait until OpenHAB engine ready to process
|
19
19
|
#
|
20
|
-
#
|
21
20
|
def self.wait_till_openhab_ready
|
22
|
-
logger.trace('Checking
|
21
|
+
logger.trace('Checking readiness of OpenHAB')
|
23
22
|
until OpenHAB::Core.automation_manager
|
24
23
|
logger.trace("Automation manager not loaded, checking again in #{CHECK_DELAY} seconds.")
|
25
24
|
sleep CHECK_DELAY
|
@@ -15,9 +15,9 @@ module OpenHAB
|
|
15
15
|
# Execute the supplied block with the supplied values set for the currently running thread
|
16
16
|
# The previous values for each key are restored after the block is executed
|
17
17
|
#
|
18
|
-
# @param [Hash] Keys and values to set for running thread, if hash is nil no values are set
|
18
|
+
# @param [Hash] values Keys and values to set for running thread, if hash is nil no values are set
|
19
19
|
#
|
20
|
-
def thread_local(**values)
|
20
|
+
def self.thread_local(**values)
|
21
21
|
old_values = values.map { |key, _value| [key, Thread.current[key]] }.to_h
|
22
22
|
values.each { |key, value| Thread.current[key] = value }
|
23
23
|
logger.trace "Executing block with thread local context: #{values} - old context: #{old_values}"
|
@@ -25,6 +25,16 @@ module OpenHAB
|
|
25
25
|
ensure
|
26
26
|
old_values.each { |key, value| Thread.current[key] = value }
|
27
27
|
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Execute the supplied block with the supplied values set for the currently running thread
|
31
|
+
# The previous values for each key are restored after the block is executed
|
32
|
+
#
|
33
|
+
# @param [Hash] values Keys and values to set for running thread, if hash is nil no values are set
|
34
|
+
#
|
35
|
+
def thread_local(**values, &block)
|
36
|
+
ThreadLocal.thread_local(values, &block)
|
37
|
+
end
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
data/lib/openhab/dsl/actions.rb
CHANGED
data/lib/openhab/dsl/between.rb
CHANGED
data/lib/openhab/dsl/dsl.rb
CHANGED
@@ -39,8 +39,8 @@ module OpenHAB
|
|
39
39
|
base.send :include, OpenHAB::DSL::Groups
|
40
40
|
base.send :include, OpenHAB::DSL::Items
|
41
41
|
base.send :include, OpenHAB::DSL::Persistence
|
42
|
-
base.send :include, OpenHAB::DSL::Rules
|
43
|
-
base.send :include, OpenHAB::DSL::Rules::
|
42
|
+
base.send :include, OpenHAB::DSL::Rules::Rule
|
43
|
+
base.send :include, OpenHAB::DSL::Rules::TerseRule
|
44
44
|
base.send :include, OpenHAB::DSL::States
|
45
45
|
base.send :include, OpenHAB::DSL::Things
|
46
46
|
base.send :include, OpenHAB::DSL::Timers
|
data/lib/openhab/dsl/group.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'singleton'
|
4
4
|
|
5
|
-
require 'openhab/dsl/lazy_array'
|
6
5
|
require 'openhab/core/entity_lookup'
|
6
|
+
require 'openhab/dsl/lazy_array'
|
7
7
|
|
8
8
|
module OpenHAB
|
9
9
|
module DSL
|
@@ -11,6 +11,19 @@ module OpenHAB
|
|
11
11
|
# Provides access to OpenHAB Groups
|
12
12
|
#
|
13
13
|
module Groups
|
14
|
+
module_function
|
15
|
+
|
16
|
+
#
|
17
|
+
# Retrieve all OpenHAB groups
|
18
|
+
#
|
19
|
+
# @return [Set] of OpenHAB Groups
|
20
|
+
#
|
21
|
+
def groups
|
22
|
+
OpenHAB::DSL::Support::Groups.instance
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Support
|
14
27
|
#
|
15
28
|
# Provide access to groups as a set
|
16
29
|
#
|
@@ -26,7 +39,7 @@ module OpenHAB
|
|
26
39
|
#
|
27
40
|
def [](name)
|
28
41
|
group = OpenHAB::Core::EntityLookup.lookup_item(name)
|
29
|
-
group.is_a?(Items::GroupItem) ? group : nil
|
42
|
+
group.is_a?(OpenHAB::DSL::Items::GroupItem) ? group : nil
|
30
43
|
end
|
31
44
|
alias include? []
|
32
45
|
alias key? include?
|
@@ -36,15 +49,6 @@ module OpenHAB
|
|
36
49
|
$ir.items.grep(org.openhab.core.items.GroupItem) # rubocop:disable Style/GlobalVars
|
37
50
|
end
|
38
51
|
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Retreive all OpenHAB groups
|
42
|
-
#
|
43
|
-
# @return [Set] of OpenHAB Groups
|
44
|
-
#
|
45
|
-
def groups
|
46
|
-
Groups.instance
|
47
|
-
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -4,94 +4,94 @@ require_relative 'generic_item'
|
|
4
4
|
|
5
5
|
module OpenHAB
|
6
6
|
module DSL
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Thread.current[:ensure_states] = old
|
27
|
-
end
|
28
|
-
module_function :ensure_states
|
7
|
+
# Functionality to implement +ensure+/+ensure_states+
|
8
|
+
module Ensure
|
9
|
+
# Contains the global +ensure_states+ method
|
10
|
+
module EnsureStates
|
11
|
+
# Global method that takes a block and for the duration of the block
|
12
|
+
# all commands sent will check if the item is in the command's state
|
13
|
+
# before sending the command.
|
14
|
+
#
|
15
|
+
# @example Turn on several switches only if they're not already on
|
16
|
+
# ensure_states do
|
17
|
+
# Switch1.on
|
18
|
+
# Switch2.on
|
19
|
+
# end
|
20
|
+
def ensure_states
|
21
|
+
old = Thread.current[:ensure_states]
|
22
|
+
Thread.current[:ensure_states] = true
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
Thread.current[:ensure_states] = old
|
29
26
|
end
|
27
|
+
module_function :ensure_states
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
30
|
+
# Contains the +ensure+ method mixed into {GenericItem} and {GroupItem::GroupMembers}
|
31
|
+
module Ensurable
|
32
|
+
# Fluent method call that you can chain commands on to, that will
|
33
|
+
# then automatically ensure that the item is not in the command's
|
34
|
+
# state before sending the command.
|
35
|
+
#
|
36
|
+
# @example Turn switch on only if it's not on
|
37
|
+
# MySwitch.ensure.on
|
38
|
+
# @example Turn on all switches in a group that aren't already on
|
39
|
+
# MySwitchGroup.members.ensure.on
|
40
|
+
def ensure
|
41
|
+
GenericItemDelegate.new(self)
|
44
42
|
end
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# If +ensure_states+ is active (by block or chained method), then
|
52
|
-
# check if this item is in the command's state before actually
|
53
|
-
# sending the command
|
54
|
-
def command(command)
|
55
|
-
return super unless Thread.current[:ensure_states]
|
45
|
+
# Extensions for {Items::GenericItem} to implement {Ensure}'s
|
46
|
+
# functionality
|
47
|
+
module GenericItem
|
48
|
+
include Ensurable
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
50
|
+
# If +ensure_states+ is active (by block or chained method), then
|
51
|
+
# check if this item is in the command's state before actually
|
52
|
+
# sending the command
|
53
|
+
def command(command)
|
54
|
+
return super unless Thread.current[:ensure_states]
|
61
55
|
|
62
|
-
|
56
|
+
logger.trace do
|
57
|
+
"#{name} ensure #{command}, format_type_pre: #{format_type_pre(command)}, current state: #{state}"
|
63
58
|
end
|
64
|
-
|
59
|
+
return if state == format_type_pre(command)
|
60
|
+
|
61
|
+
super
|
65
62
|
end
|
63
|
+
alias << command
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
# "anonymous" class that wraps any method call in +ensure_states+
|
67
|
+
# before forwarding to the wrapped object
|
68
|
+
# @!visibility private
|
69
|
+
class GenericItemDelegate
|
70
|
+
def initialize(item)
|
71
|
+
@item = item
|
72
|
+
end
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
# activate +ensure_states+ before forwarding to the wrapped object
|
75
|
+
def method_missing(method, *args, &block)
|
76
|
+
return super unless @item.respond_to?(method)
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
end
|
78
|
+
ensure_states do
|
79
|
+
@item.__send__(method, *args, &block)
|
82
80
|
end
|
81
|
+
end
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
83
|
+
# .
|
84
|
+
def respond_to_missing?(method, include_private = false)
|
85
|
+
@item.respond_to?(method, include_private) || super
|
88
86
|
end
|
89
87
|
end
|
88
|
+
end
|
90
89
|
|
91
|
-
|
92
|
-
|
90
|
+
module Items
|
91
|
+
GenericItem.prepend(OpenHAB::DSL::Ensure::GenericItem)
|
92
|
+
GroupItem::GroupMembers.include(OpenHAB::DSL::Ensure::Ensurable)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
Object.include OpenHAB::DSL::
|
97
|
+
Object.include OpenHAB::DSL::Ensure::EnsureStates
|
@@ -153,7 +153,7 @@ module OpenHAB
|
|
153
153
|
def things
|
154
154
|
registry = OpenHAB::Core::OSGI.service('org.openhab.core.thing.link.ItemChannelLinkRegistry')
|
155
155
|
channels = registry.get_bound_channels(name).to_a
|
156
|
-
channels.map(&:thing_uid).uniq.map { |tuid|
|
156
|
+
channels.map(&:thing_uid).uniq.map { |tuid| OpenHAB::DSL::Things.things[tuid] }
|
157
157
|
end
|
158
158
|
alias all_linked_things things
|
159
159
|
|
@@ -8,6 +8,17 @@ require 'openhab/dsl/lazy_array'
|
|
8
8
|
module OpenHAB
|
9
9
|
module DSL
|
10
10
|
module Items
|
11
|
+
module_function
|
12
|
+
|
13
|
+
# Fetches all non-group items from the item registry
|
14
|
+
# @return [ItemRegistry]
|
15
|
+
def items
|
16
|
+
OpenHAB::DSL::Support::ItemRegistry.instance
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Provide supporting objects for DSL functions
|
21
|
+
module Support
|
11
22
|
#
|
12
23
|
# Provides access to all OpenHAB items, and acts like an array.
|
13
24
|
#
|
@@ -38,12 +49,6 @@ module OpenHAB
|
|
38
49
|
$ir.items.to_a # rubocop:disable Style/GlobalVars
|
39
50
|
end
|
40
51
|
end
|
41
|
-
|
42
|
-
# Fetches all non-group items from the item registry
|
43
|
-
# @return [ItemRegistry]
|
44
|
-
def items
|
45
|
-
ItemRegistry.instance
|
46
|
-
end
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -43,7 +43,7 @@ module OpenHAB
|
|
43
43
|
# define predicates for checking if an item is in one of the Enum states
|
44
44
|
def def_predicate_methods(klass)
|
45
45
|
values_for_enums(klass.ACCEPTED_DATA_TYPES).each do |state|
|
46
|
-
_command_predicate, state_predicate =
|
46
|
+
_command_predicate, state_predicate = OpenHAB::DSL::PREDICATE_ALIASES[state.to_s]
|
47
47
|
next if klass.instance_methods.include?(state_predicate)
|
48
48
|
|
49
49
|
logger.trace("Defining #{klass}##{state_predicate} for #{state}")
|
@@ -59,7 +59,7 @@ module OpenHAB
|
|
59
59
|
# as well as predicates for if an ItemCommandEvent is one of those commands
|
60
60
|
def def_command_methods(klass) # rubocop:disable Metrics method has single purpose
|
61
61
|
values_for_enums(klass.ACCEPTED_COMMAND_TYPES).each do |value|
|
62
|
-
command =
|
62
|
+
command = OpenHAB::DSL::COMMAND_ALIASES[value.to_s]
|
63
63
|
next if klass.instance_methods.include?(command)
|
64
64
|
|
65
65
|
logger.trace("Defining #{klass}##{command} for #{value}")
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'delegate'
|
4
|
-
require 'pp'
|
5
4
|
require 'forwardable'
|
6
5
|
require 'openhab/core/osgi'
|
7
6
|
require 'openhab/log/logger'
|
@@ -89,7 +88,7 @@ module OpenHAB
|
|
89
88
|
#
|
90
89
|
# Recursively convert the supplied Hash object into a Ruby Hash and recreate the keys and values
|
91
90
|
#
|
92
|
-
# @param [Hash]
|
91
|
+
# @param [Hash] hash to convert
|
93
92
|
#
|
94
93
|
# @return [Hash] The converted hash
|
95
94
|
#
|
@@ -43,7 +43,7 @@ module OpenHAB
|
|
43
43
|
#
|
44
44
|
#
|
45
45
|
# rubocop: disable Metrics/MethodLength
|
46
|
-
# The mutex makes this over 10 lines, but there is usable way to break
|
46
|
+
# The mutex makes this over 10 lines, but there is usable way to break this method up
|
47
47
|
def command(command, for: nil, on_expire: nil, &block)
|
48
48
|
duration = binding.local_variable_get(:for)
|
49
49
|
return super(command) unless duration
|
@@ -86,8 +86,9 @@ module OpenHAB
|
|
86
86
|
timed_command_details.timer = timed_command_timer(timed_command_details, semaphore, &block)
|
87
87
|
timed_command_details.cancel_rule = TimedCommandCancelRule.new(timed_command_details, semaphore,
|
88
88
|
&block)
|
89
|
-
timed_command_details.rule_uid = OpenHAB::DSL::Rules.automation_manager
|
90
|
-
|
89
|
+
timed_command_details.rule_uid = OpenHAB::DSL::Rules::Rule.automation_manager
|
90
|
+
.addRule(timed_command_details.cancel_rule)
|
91
|
+
.getUID
|
91
92
|
logger.trace "Created Timed Command #{timed_command_details}"
|
92
93
|
TimedCommand.timed_commands[self] = timed_command_details
|
93
94
|
end
|
@@ -120,10 +121,10 @@ module OpenHAB
|
|
120
121
|
# rubocop: enable Metrics/MethodLength
|
121
122
|
|
122
123
|
# Cancels timed command rule
|
123
|
-
# @param [TimedCommandDetailed]
|
124
|
+
# @param [TimedCommandDetailed] timed_command_details details about the timed command
|
124
125
|
def cancel_timed_command_rule(timed_command_details)
|
125
126
|
logger.trace "Removing rule: #{timed_command_details.rule_uid}"
|
126
|
-
OpenHAB::DSL::Rules.registry.remove(timed_command_details.rule_uid)
|
127
|
+
OpenHAB::DSL::Rules::Rule.registry.remove(timed_command_details.rule_uid)
|
127
128
|
end
|
128
129
|
|
129
130
|
#
|
@@ -162,7 +163,7 @@ module OpenHAB
|
|
162
163
|
#
|
163
164
|
# Execute the rule
|
164
165
|
#
|
165
|
-
# @param [Map]
|
166
|
+
# @param [Map] _mod map provided by OpenHAB rules engine
|
166
167
|
# @param [Map] inputs map provided by OpenHAB rules engine containing event and other information
|
167
168
|
#
|
168
169
|
#
|
data/lib/openhab/dsl/openhab.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'java'
|
4
|
-
require 'set'
|
5
4
|
require 'openhab/core/thread_local'
|
6
5
|
require 'openhab/log/logger'
|
7
6
|
require 'openhab/dsl/between'
|
@@ -57,8 +56,8 @@ module OpenHAB
|
|
57
56
|
#
|
58
57
|
def execute(mod = nil, inputs = nil)
|
59
58
|
thread_local(RULE_NAME: name) do
|
60
|
-
logger.trace { "Execute called with mod (#{mod&.to_string}) and inputs (#{inputs
|
61
|
-
logger.trace { "Event details #{inputs['event'].
|
59
|
+
logger.trace { "Execute called with mod (#{mod&.to_string}) and inputs (#{inputs.inspect})" }
|
60
|
+
logger.trace { "Event details #{inputs['event'].inspect}" } if inputs&.key?('event')
|
62
61
|
trigger_conditions(inputs).process(mod: mod, inputs: inputs) do
|
63
62
|
process_queue(create_queue(inputs), mod, inputs)
|
64
63
|
end
|
@@ -131,8 +130,8 @@ module OpenHAB
|
|
131
130
|
end
|
132
131
|
|
133
132
|
# If an attachment exists for the trigger for this event add it to the event object
|
134
|
-
# @param [Object] Event
|
135
|
-
# @param [Hash] Inputs into event
|
133
|
+
# @param [Object] event Event
|
134
|
+
# @param [Hash] inputs Inputs into event
|
136
135
|
# @return [Object] Event with attachment added
|
137
136
|
#
|
138
137
|
def add_attachment(event, inputs)
|