openhab-scripting 4.30.3 → 4.30.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5916a1adf8f4162530b88e279d0d8a8cb5cdb7f0505572258e1170ed7841460f
4
- data.tar.gz: d3e9073dbde176abf8582e51eb6009a953befde6fd05b9a782fa3c3a09400ed3
3
+ metadata.gz: 5836c0c28481307c2e5b7e455f78e6a41db200d6d0479b6510ca920a6b4b1327
4
+ data.tar.gz: 3dae55830faebd93761bd1250c7d1a82c1fdb0e086fe152c9c7cb4b3791aa817
5
5
  SHA512:
6
- metadata.gz: f39b84e0831b3ec13c643cc65eea2a45f2d9971fbf8ac9dc0bb53a44ab7ad767b2ab75f88dfe0db96dd274c30f40eab4f9ab876603d2e9c001f107ecec2a6d15
7
- data.tar.gz: c9712062f693f5a4fd903ce8fbd06a441622850b94c240b6e5ade99a7a0754c1576ef78e69e518ec537728a7233ea8794090ace0016873628dccf5595067fb4e
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/triggers/trigger'
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::Triggers::Trigger.trigger(
155
- type: OpenHAB::DSL::Rules::Triggers::Trigger::ITEM_STATE_CHANGE,
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
- # Metrics disabled because only setters are called or defaults set.
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 'pp'
4
+ require 'forwardable'
5
5
  require_relative 'property'
6
- require_relative 'triggers/cron'
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
- # @return [Array] Of triggers
38
- attr_accessor :triggers
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
- @triggers = []
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
- separate_groups(items).map do |item|
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
- changed_trigger(item, from_state, to_state, wait_duration, attach)
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
- # @return [Array] array of block return values
52
- #
53
- def each_state(from, to)
54
- [to].flatten.each_with_object([]) do |to_state, agg|
55
- [from].flatten.each do |from_state|
56
- agg.push(yield(from_state, to_state))
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
- # Create the trigger
63
- #
64
- # @param [Object] item item to create trigger for
65
- # @param [Item State] from state to restrict trigger to
66
- # @param [Item State] to state to restrict trigger to
67
- # @param [OpenHAB::Core::Duration, nil] duration ruration to delay trigger until to state is met
68
- # @param attach attachment
69
- #
70
- # @return [Trigger] OpenHAB triggers
71
- #
72
- def changed_trigger(item, from, to, duration, attach)
73
- if duration
74
- changed_wait(item, from: from, to: to, duration: duration, attach: attach)
75
- elsif [to, from].grep(Range).any?
76
- create_changed_range_trigger(item, from: from, to: to, attach: attach)
77
- elsif [to, from].grep(Proc).any?
78
- create_changed_proc_trigger(item, from: from, to: to, attach: attach)
79
- else
80
- create_changed_trigger(item, from, to, attach)
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
- # Create a TriggerDelay for for an item or group that is changed for a specific duration
86
- #
87
- # @param [Object] item to create trigger delay for
88
- # @param [OpenHAB::Core::Duration] duration to delay trigger for until condition is met
89
- # @param [Item State] to OpenHAB Item State item or group needs to change to
90
- # @param [Item State] from OpenHAB Item State item or group needs to be coming from
91
- # @param [Object] attach to trigger
92
- #
93
- # @return [Trigger] OpenHAB trigger
94
- #
95
- def changed_wait(item, duration:, to: nil, from: nil, attach: nil)
96
- item_name = item.respond_to?(:name) ? item.name : item.to_s
97
- logger.trace("Creating Changed Wait Change Trigger for Item(#{item_name}) Duration(#{duration}) "\
98
- "To(#{to}) From(#{from}) Attach(#{attach})")
99
- create_changed_trigger(item, nil, nil, attach).tap do |trigger|
100
- @trigger_conditions[trigger.id] = Conditions::Duration.new(to: to, from: from, duration: duration)
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
- # Creates a trigger with a range condition on either 'from' or 'to' field
106
- # @param [Object] item to create changed trigger on
107
- # @param [Object] from state to restrict trigger to
108
- # @param [Object] to state restrict trigger to
109
- # @param [Object] attach to trigger
110
- # @return [Trigger] OpenHAB trigger
111
- #
112
- def create_changed_range_trigger(item, from:, to:, attach:)
113
- from, to = Conditions::Proc.range_procs(from, to)
114
- create_changed_proc_trigger(item, from: from, to: to, attach: attach)
115
- end
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
- # Creates a trigger with a proc condition on either 'from' or 'to' field
119
- # @param [Object] item to create changed trigger on
120
- # @param [Object] from state to restrict trigger to
121
- # @param [Object] to state restrict trigger to
122
- # @param [Object] attach to trigger
123
- # @return [Trigger] OpenHAB trigger
124
- #
125
- def create_changed_proc_trigger(item, from:, to:, attach:)
126
- # swap from/to w/ nil if from/to is a proc
127
- # rubocop:disable Style/ParallelAssignment
128
- from_proc, from = from, nil if from.is_a? Proc
129
- to_proc, to = to, nil if to.is_a? Proc
130
- # rubocop:enable Style/ParallelAssignment
131
- trigger = create_changed_trigger(item, from, to, attach)
132
- @trigger_conditions[trigger.id] = Conditions::Proc.new(to: to_proc, from: from_proc)
133
- trigger
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
- # Create a changed trigger
138
- #
139
- # @param [Object] item to create changed trigger on
140
- # @param [Object] from state to restrict trigger to
141
- # @param [Object] to state restrict trigger to
142
- #
143
- #
144
- def create_changed_trigger(item, from, to, attach)
145
- trigger, config = case item
146
- when OpenHAB::DSL::Items::GroupItem::GroupMembers
147
- create_group_changed_trigger(item, from, to)
148
- when Thing then create_thing_changed_trigger(item, from, to)
149
- else create_item_changed_trigger(item, from, to)
150
- end
151
- append_trigger(trigger, config, attach: attach)
152
- end
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
- # Create a changed trigger for a thing
156
- #
157
- # @param [Thing] thing to detected changed states on
158
- # @param [String] from state to restrict trigger to
159
- # @param [String] to state to restrict trigger to
160
- #
161
- # @return [Array<Hash,String>] first element is a String specifying trigger type
162
- # second element is a Hash configuring trigger
163
- #
164
- def create_thing_changed_trigger(thing, from, to)
165
- trigger_for_thing(thing, Trigger::THING_CHANGE, to, from)
166
- end
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
- # Create a changed trigger for an item
170
- #
171
- # @param [Item] item to detected changed states on
172
- # @param [String] from state to restrict trigger to
173
- # @param [String] to to restrict trigger to
174
- #
175
- # @return [Array<Hash,String>] first element is a String specifying trigger type
176
- # second element is a Hash configuring trigger
177
- #
178
- def create_item_changed_trigger(item, from, to)
179
- config = { 'itemName' => item.name }
180
- config['state'] = to.to_s if to
181
- config['previousState'] = from.to_s if from
182
- trigger = Trigger::ITEM_STATE_CHANGE
183
- [trigger, config]
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
- # Create a changed trigger for group items
188
- #
189
- # @param [Group] group to detected changed states on
190
- # @param [String] from state to restrict trigger to
191
- # @param [String] to to restrict trigger to
192
- #
193
- # @return [Array<Hash,String>] first element is a String specifying trigger type
194
- # second element is a Hash configuring trigger
195
- #
196
- def create_group_changed_trigger(group, from, to)
197
- config = { 'groupName' => group.group.name }
198
- config['state'] = to.to_s if to
199
- config['previousState'] = from.to_s if from
200
- trigger = Trigger::GROUP_STATE_CHANGE
201
- [trigger, config]
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