openhab-scripting 4.30.3 → 4.30.4
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/dsl/items/timed_command.rb +4 -3
- data/lib/openhab/dsl/rules/automation_rule.rb +4 -6
- data/lib/openhab/dsl/rules/rule_config.rb +9 -22
- data/lib/openhab/dsl/rules/rule_triggers.rb +103 -0
- data/lib/openhab/dsl/rules/triggers/changed.rb +164 -152
- data/lib/openhab/dsl/rules/triggers/channel.rb +48 -20
- data/lib/openhab/dsl/rules/triggers/command.rb +74 -64
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +185 -0
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +130 -0
- data/lib/openhab/dsl/rules/triggers/generic.rb +2 -1
- data/lib/openhab/dsl/rules/triggers/trigger.rb +44 -112
- data/lib/openhab/dsl/rules/triggers/triggers.rb +11 -0
- data/lib/openhab/dsl/rules/triggers/updated.rb +111 -97
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +76 -0
- data/lib/openhab/dsl/rules/triggers/{watch.rb → watch/watch_handler.rb} +14 -56
- data/lib/openhab/log/logger.rb +16 -0
- data/lib/openhab/version.rb +1 -1
- metadata +8 -4
- data/lib/openhab/dsl/rules/triggers/cron.rb +0 -288
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5836c0c28481307c2e5b7e455f78e6a41db200d6d0479b6510ca920a6b4b1327
|
4
|
+
data.tar.gz: 3dae55830faebd93761bd1250c7d1a82c1fdb0e086fe152c9c7cb4b3791aa817
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf42c9413c725a57783cd261c89162186573739676f681e0d0a6749c461262a7dbe22fac2d7692a7c39dd36a525e75facb4345f0f61b2ee5e4ea81b09bd0875f
|
7
|
+
data.tar.gz: 588986cf6160cf230ffe403381cc55b267a29c9bd36f444bb38d446eddbdee7173c7f42efea39082302506eb50c92b60125a9575e19e9063f2015f42098c2ee1
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'openhab/dsl/timers'
|
4
|
-
require 'openhab/dsl/rules/
|
4
|
+
require 'openhab/dsl/rules/rule_triggers'
|
5
|
+
require 'openhab/dsl/rules/triggers/triggers'
|
5
6
|
require 'openhab/log/logger'
|
6
7
|
require 'java'
|
7
8
|
|
@@ -151,8 +152,8 @@ module OpenHAB
|
|
151
152
|
# Capture rule name if known
|
152
153
|
@thread_locals = Thread.current[:RULE_NAME] ? { RULE_NAME: Thread.current[:RULE_NAME] } : {}
|
153
154
|
set_name("Cancels implicit timer for #{timed_command_details.item.id}")
|
154
|
-
set_triggers([OpenHAB::DSL::Rules::
|
155
|
-
type: OpenHAB::DSL::Rules::Triggers::
|
155
|
+
set_triggers([OpenHAB::DSL::Rules::RuleTriggers.trigger(
|
156
|
+
type: OpenHAB::DSL::Rules::Triggers::Changed::ITEM_STATE_CHANGE,
|
156
157
|
config: { 'itemName' => timed_command_details.item.name }
|
157
158
|
)])
|
158
159
|
end
|
@@ -32,9 +32,8 @@ module OpenHAB
|
|
32
32
|
# @param [Config] config Rule configuration
|
33
33
|
#
|
34
34
|
# Constructor sets a number of variables, no further decomposition necessary
|
35
|
-
# rubocop:disable Metrics/MethodLength
|
36
|
-
|
37
|
-
def initialize(config:)
|
35
|
+
def initialize(config:) # rubocop:disable Metrics/MethodLength
|
36
|
+
# Metrics disabled because only setters are called or defaults set.
|
38
37
|
super()
|
39
38
|
set_name(config.name)
|
40
39
|
set_description(config.description)
|
@@ -42,13 +41,12 @@ module OpenHAB
|
|
42
41
|
@run_context = config.caller
|
43
42
|
@run_queue = config.run
|
44
43
|
@guard = config.guard
|
45
|
-
between = config.between&.yield_self { between(config.between) }
|
46
|
-
@between = between || OpenHAB::DSL::Between::ALL_DAY
|
47
44
|
# Convert between to correct range or nil if not set
|
45
|
+
between = config.between&.then { between(config.between) }
|
46
|
+
@between = between || OpenHAB::DSL::Between::ALL_DAY
|
48
47
|
@trigger_conditions = config.trigger_conditions
|
49
48
|
@attachments = config.attachments
|
50
49
|
end
|
51
|
-
# rubocop:enable Metrics/MethodLength
|
52
50
|
|
53
51
|
#
|
54
52
|
# Execute the rule
|
@@ -1,17 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'java'
|
4
|
-
require '
|
4
|
+
require 'forwardable'
|
5
5
|
require_relative 'property'
|
6
|
-
require_relative 'triggers/
|
7
|
-
require_relative 'triggers/changed'
|
8
|
-
require_relative 'triggers/channel'
|
9
|
-
require_relative 'triggers/command'
|
10
|
-
require_relative 'triggers/updated'
|
11
|
-
require_relative 'triggers/generic'
|
12
|
-
require_relative 'triggers/watch'
|
13
|
-
require_relative 'triggers/conditions/proc'
|
6
|
+
require_relative 'triggers/triggers'
|
14
7
|
require_relative 'guard'
|
8
|
+
require_relative 'rule_triggers'
|
15
9
|
require 'openhab/core/entity_lookup'
|
16
10
|
require 'openhab/dsl/between'
|
17
11
|
require 'openhab/dsl/dsl'
|
@@ -33,15 +27,10 @@ module OpenHAB
|
|
33
27
|
include OpenHAB::DSL::Rules::Guard
|
34
28
|
include OpenHAB::DSL::Rules::Property
|
35
29
|
extend OpenHAB::DSL
|
30
|
+
extend Forwardable
|
36
31
|
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
# @return [Array] Of trigger delays
|
41
|
-
attr_reader :trigger_conditions
|
42
|
-
|
43
|
-
# @return [Hash] Hash of trigger UIDs to attachments
|
44
|
-
attr_reader :attachments
|
32
|
+
# Provide backwards compatibility for these fields
|
33
|
+
delegate %i[triggers trigger_conditions attachments] => :@rule_triggers
|
45
34
|
|
46
35
|
# @return [Array] Of trigger guards
|
47
36
|
attr_accessor :guard
|
@@ -86,9 +75,7 @@ module OpenHAB
|
|
86
75
|
# Used to execute within the object's context
|
87
76
|
#
|
88
77
|
def initialize(rule_name, caller_binding)
|
89
|
-
@
|
90
|
-
@trigger_conditions = Hash.new(OpenHAB::DSL::Rules::Triggers::Conditions::Proc::ANY)
|
91
|
-
@attachments = {}
|
78
|
+
@rule_triggers = RuleTriggers.new
|
92
79
|
@caller = caller_binding.eval 'self'
|
93
80
|
name(rule_name)
|
94
81
|
enabled(true)
|
@@ -147,8 +134,8 @@ module OpenHAB
|
|
147
134
|
"Run blocks: (#{run}) " \
|
148
135
|
"on_start: (#{on_start?}) " \
|
149
136
|
"Trigger Conditions: #{trigger_conditions} " \
|
150
|
-
"Trigger UIDs: #{triggers.map(&:id).join(', ')}" \
|
151
|
-
"Attachments: #{attachments}
|
137
|
+
"Trigger UIDs: #{triggers.map(&:id).join(', ')} " \
|
138
|
+
"Attachments: #{attachments}"
|
152
139
|
end
|
153
140
|
end
|
154
141
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
require 'java'
|
5
|
+
require 'securerandom'
|
6
|
+
require 'openhab/log/logger'
|
7
|
+
require_relative 'triggers/conditions/proc'
|
8
|
+
|
9
|
+
module OpenHAB
|
10
|
+
module DSL
|
11
|
+
#
|
12
|
+
# Creates and manages OpenHAB Rules
|
13
|
+
#
|
14
|
+
module Rules
|
15
|
+
#
|
16
|
+
# Rule configuration for OpenHAB Rules engine
|
17
|
+
#
|
18
|
+
class RuleTriggers
|
19
|
+
include OpenHAB::Log
|
20
|
+
|
21
|
+
java_import org.openhab.core.automation.util.TriggerBuilder
|
22
|
+
java_import org.openhab.core.config.core.Configuration
|
23
|
+
|
24
|
+
# @return [Array] Of triggers
|
25
|
+
attr_accessor :triggers
|
26
|
+
|
27
|
+
# @return [Hash] Of trigger conditions
|
28
|
+
attr_reader :trigger_conditions
|
29
|
+
|
30
|
+
# @return [Hash] Hash of trigger UIDs to attachments
|
31
|
+
attr_reader :attachments
|
32
|
+
|
33
|
+
#
|
34
|
+
# Create a new RuleTrigger
|
35
|
+
#
|
36
|
+
# @param [Object] caller_binding The object initializing this configuration.
|
37
|
+
# Used to execute within the object's context
|
38
|
+
#
|
39
|
+
def initialize
|
40
|
+
@triggers = []
|
41
|
+
@trigger_conditions = Hash.new(OpenHAB::DSL::Rules::Triggers::Conditions::Proc::ANY)
|
42
|
+
@attachments = {}
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Append a trigger to the list of triggers
|
47
|
+
#
|
48
|
+
# @param [String] type of trigger to create
|
49
|
+
# @param [Map] config map describing trigger configuration
|
50
|
+
#
|
51
|
+
# @return [Trigger] OpenHAB trigger
|
52
|
+
#
|
53
|
+
def append_trigger(type:, config:, attach: nil, conditions: nil)
|
54
|
+
config.transform_keys!(&:to_s)
|
55
|
+
RuleTriggers.trigger(type: type, config: config).tap do |trigger|
|
56
|
+
logger.trace("Appending trigger (#{trigger}) attach (#{attach}) conditions(#{conditions})")
|
57
|
+
@triggers << trigger
|
58
|
+
@attachments[trigger.id] = attach if attach
|
59
|
+
@trigger_conditions[trigger.id] = conditions if conditions
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Create a trigger
|
65
|
+
#
|
66
|
+
# @param [String] type of trigger
|
67
|
+
# @param [Map] config map
|
68
|
+
#
|
69
|
+
# @return [OpenHAB Trigger] configured by type and supplied config
|
70
|
+
#
|
71
|
+
def self.trigger(type:, config:)
|
72
|
+
logger.trace("Creating trigger of type '#{type}' config: #{config}")
|
73
|
+
TriggerBuilder.create
|
74
|
+
.with_id(uuid)
|
75
|
+
.with_type_uid(type)
|
76
|
+
.with_configuration(Configuration.new(config))
|
77
|
+
.build
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Generate a UUID for triggers
|
82
|
+
#
|
83
|
+
# @return [String] UUID
|
84
|
+
#
|
85
|
+
def self.uuid
|
86
|
+
SecureRandom.uuid
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Inspect the config object
|
91
|
+
#
|
92
|
+
# @return [String] details of the config object
|
93
|
+
#
|
94
|
+
def inspect
|
95
|
+
"Triggers: (#{triggers}) " \
|
96
|
+
"Trigger Conditions: #{trigger_conditions} " \
|
97
|
+
"Trigger UIDs: #{triggers.map(&:id).join(', ')}" \
|
98
|
+
"Attachments: #{attachments} "
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'openhab/log/logger'
|
4
4
|
require_relative 'conditions/duration'
|
5
5
|
require_relative 'conditions/proc'
|
6
|
+
require_relative 'trigger'
|
6
7
|
|
7
8
|
module OpenHAB
|
8
9
|
module DSL
|
@@ -25,180 +26,191 @@ module OpenHAB
|
|
25
26
|
# @return [Trigger] OpenHAB trigger
|
26
27
|
#
|
27
28
|
def changed(*items, to: nil, from: nil, for: nil, attach: nil)
|
28
|
-
|
29
|
+
changed = Changed.new(rule_triggers: @rule_triggers)
|
30
|
+
Changed.flatten_items(items).map do |item|
|
29
31
|
logger.trace("Creating changed trigger for entity(#{item}), to(#{to}), from(#{from})")
|
30
32
|
|
31
33
|
# for is a reserved word in ruby, so use local_variable_get :for
|
32
34
|
wait_duration = binding.local_variable_get(:for)
|
33
35
|
|
34
|
-
each_state(from, to) do |from_state, to_state|
|
35
|
-
|
36
|
+
Changed.each_state(from, to) do |from_state, to_state|
|
37
|
+
changed.trigger(item: item, from: from_state, to: to_state, duration: wait_duration, attach: attach)
|
36
38
|
end
|
37
39
|
end.flatten
|
38
40
|
end
|
39
41
|
|
40
|
-
private
|
41
|
-
|
42
|
-
#
|
43
|
-
# Run block for each state combination
|
44
|
-
#
|
45
|
-
# @param [Item State, Array<Item State>] from state to restrict trigger to
|
46
|
-
# @param [Item State, Array<Item State>] to state to restrict trigger to
|
47
|
-
#
|
48
|
-
# @yieldparam [Item State] from_state from state
|
49
|
-
# @yieldparam [Item State] to_state to state
|
50
42
|
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
43
|
+
# Creates changed triggers
|
44
|
+
#
|
45
|
+
class Changed < Trigger
|
46
|
+
#
|
47
|
+
# Run block for each state combination
|
48
|
+
#
|
49
|
+
# @param [Item State, Array<Item State>] from state to restrict trigger to
|
50
|
+
# @param [Item State, Array<Item State>] to state to restrict trigger to
|
51
|
+
#
|
52
|
+
# @yieldparam [Item State] from_state from state
|
53
|
+
# @yieldparam [Item State] to_state to state
|
54
|
+
#
|
55
|
+
# @return [Array] array of block return values
|
56
|
+
#
|
57
|
+
def self.each_state(from, to)
|
58
|
+
[to].flatten.each_with_object([]) do |to_state, agg|
|
59
|
+
[from].flatten.each do |from_state|
|
60
|
+
agg.push(yield(from_state, to_state))
|
61
|
+
end
|
57
62
|
end
|
58
63
|
end
|
59
|
-
end
|
60
64
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
65
|
+
#
|
66
|
+
# Create the trigger
|
67
|
+
#
|
68
|
+
# @param [Object] item item to create trigger for
|
69
|
+
# @param [Item State] from state to restrict trigger to
|
70
|
+
# @param [Item State] to state to restrict trigger to
|
71
|
+
# @param [OpenHAB::Core::Duration, nil] duration ruration to delay trigger until to state is met
|
72
|
+
# @param attach attachment
|
73
|
+
#
|
74
|
+
# @return [Trigger] OpenHAB triggers
|
75
|
+
#
|
76
|
+
def trigger(item:, from:, to:, duration:, attach:)
|
77
|
+
if duration
|
78
|
+
wait_trigger(item: item, from: from, to: to, duration: duration, attach: attach)
|
79
|
+
elsif [to, from].grep(Range).any?
|
80
|
+
range_trigger(item: item, from: from, to: to, attach: attach)
|
81
|
+
elsif [to, from].grep(Proc).any?
|
82
|
+
proc_trigger(item: item, from: from, to: to, attach: attach)
|
83
|
+
else
|
84
|
+
changed_trigger(item: item, from: from, to: to, attach: attach)
|
85
|
+
end
|
81
86
|
end
|
82
|
-
end
|
83
87
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
88
|
+
private
|
89
|
+
|
90
|
+
# @return [String] A thing status Change trigger
|
91
|
+
THING_CHANGE = 'core.ThingStatusChangeTrigger'
|
92
|
+
|
93
|
+
# @return [String] An item state change trigger
|
94
|
+
ITEM_STATE_CHANGE = 'core.ItemStateChangeTrigger'
|
95
|
+
|
96
|
+
# @return [String] A group state change trigger for items in the group
|
97
|
+
GROUP_STATE_CHANGE = 'core.GroupStateChangeTrigger'
|
98
|
+
|
99
|
+
#
|
100
|
+
# Create a TriggerDelay for for an item or group that is changed for a specific duration
|
101
|
+
#
|
102
|
+
# @param [Object] item to create trigger delay for
|
103
|
+
# @param [OpenHAB::Core::Duration] duration to delay trigger for until condition is met
|
104
|
+
# @param [Item State] to OpenHAB Item State item or group needs to change to
|
105
|
+
# @param [Item State] from OpenHAB Item State item or group needs to be coming from
|
106
|
+
# @param [Object] attach to trigger
|
107
|
+
#
|
108
|
+
# @return [Trigger] OpenHAB trigger
|
109
|
+
#
|
110
|
+
def wait_trigger(item:, duration:, to: nil, from: nil, attach: nil)
|
111
|
+
item_name = item.respond_to?(:name) ? item.name : item.to_s
|
112
|
+
logger.trace("Creating Changed Wait Change Trigger for Item(#{item_name}) Duration(#{duration}) "\
|
113
|
+
"To(#{to}) From(#{from}) Attach(#{attach})")
|
114
|
+
conditions = Conditions::Duration.new(to: to, from: from, duration: duration)
|
115
|
+
changed_trigger(item: item, to: nil, from: nil, attach: attach, conditions: conditions)
|
101
116
|
end
|
102
|
-
end
|
103
117
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
118
|
+
#
|
119
|
+
# Creates a trigger with a range condition on either 'from' or 'to' field
|
120
|
+
# @param [Object] item to create changed trigger on
|
121
|
+
# @param [Object] from state to restrict trigger to
|
122
|
+
# @param [Object] to state restrict trigger to
|
123
|
+
# @param [Object] attach to trigger
|
124
|
+
# @return [Trigger] OpenHAB trigger
|
125
|
+
#
|
126
|
+
def range_trigger(item:, from:, to:, attach:)
|
127
|
+
from, to = Conditions::Proc.range_procs(from, to)
|
128
|
+
proc_trigger(item: item, from: from, to: to, attach: attach)
|
129
|
+
end
|
116
130
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
131
|
+
#
|
132
|
+
# Creates a trigger with a proc condition on either 'from' or 'to' field
|
133
|
+
# @param [Object] item to create changed trigger on
|
134
|
+
# @param [Object] from state to restrict trigger to
|
135
|
+
# @param [Object] to state restrict trigger to
|
136
|
+
# @param [Object] attach to trigger
|
137
|
+
# @return [Trigger] OpenHAB trigger
|
138
|
+
#
|
139
|
+
def proc_trigger(item:, from:, to:, attach:)
|
140
|
+
# swap from/to w/ nil if from/to is a proc
|
141
|
+
# rubocop:disable Style/ParallelAssignment
|
142
|
+
from_proc, from = from, nil if from.is_a? Proc
|
143
|
+
to_proc, to = to, nil if to.is_a? Proc
|
144
|
+
# rubocop:enable Style/ParallelAssignment
|
145
|
+
conditions = Conditions::Proc.new(to: to_proc, from: from_proc)
|
146
|
+
changed_trigger(item: item, from: from, to: to, attach: attach, conditions: conditions)
|
147
|
+
end
|
135
148
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
149
|
+
#
|
150
|
+
# Create a changed trigger
|
151
|
+
#
|
152
|
+
# @param [Object] item to create changed trigger on
|
153
|
+
# @param [Object] from state to restrict trigger to
|
154
|
+
# @param [Object] to state restrict trigger to
|
155
|
+
#
|
156
|
+
#
|
157
|
+
def changed_trigger(item:, from:, to:, attach: nil, conditions: nil)
|
158
|
+
type, config = case item
|
159
|
+
when OpenHAB::DSL::Items::GroupItem::GroupMembers then group(group: item, from: from,
|
160
|
+
to: to)
|
161
|
+
when Thing then thing(thing: item, from: from, to: to)
|
162
|
+
else item(item: item, from: from, to: to)
|
163
|
+
end
|
164
|
+
append_trigger(type: type, config: config, attach: attach, conditions: conditions)
|
165
|
+
end
|
153
166
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
+
#
|
168
|
+
# Create a changed trigger for a thing
|
169
|
+
#
|
170
|
+
# @param [Thing] thing to detected changed states on
|
171
|
+
# @param [String] from state to restrict trigger to
|
172
|
+
# @param [String] to state to restrict trigger to
|
173
|
+
#
|
174
|
+
# @return [Array<Hash,String>] first element is a String specifying trigger type
|
175
|
+
# second element is a Hash configuring trigger
|
176
|
+
#
|
177
|
+
def thing(thing:, from:, to:)
|
178
|
+
trigger_for_thing(thing: thing, type: THING_CHANGE, to: to, from: from)
|
179
|
+
end
|
167
180
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
181
|
+
#
|
182
|
+
# Create a changed trigger for an item
|
183
|
+
#
|
184
|
+
# @param [Item] item to detected changed states on
|
185
|
+
# @param [String] from state to restrict trigger to
|
186
|
+
# @param [String] to to restrict trigger to
|
187
|
+
#
|
188
|
+
# @return [Array<Hash,String>] first element is a String specifying trigger type
|
189
|
+
# second element is a Hash configuring trigger
|
190
|
+
#
|
191
|
+
def item(item:, from:, to:)
|
192
|
+
config = { 'itemName' => item.name }
|
193
|
+
config['state'] = to.to_s if to
|
194
|
+
config['previousState'] = from.to_s if from
|
195
|
+
[ITEM_STATE_CHANGE, config]
|
196
|
+
end
|
185
197
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
198
|
+
#
|
199
|
+
# Create a changed trigger for group items
|
200
|
+
#
|
201
|
+
# @param [Group] group to detected changed states on
|
202
|
+
# @param [String] from state to restrict trigger to
|
203
|
+
# @param [String] to to restrict trigger to
|
204
|
+
#
|
205
|
+
# @return [Array<Hash,String>] first element is a String specifying trigger type
|
206
|
+
# second element is a Hash configuring trigger
|
207
|
+
#
|
208
|
+
def group(group:, from:, to:)
|
209
|
+
config = { 'groupName' => group.group.name }
|
210
|
+
config['state'] = to.to_s if to
|
211
|
+
config['previousState'] = from.to_s if from
|
212
|
+
[GROUP_STATE_CHANGE, config]
|
213
|
+
end
|
202
214
|
end
|
203
215
|
end
|
204
216
|
end
|