This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
changed.feature
314 lines (290 loc) · 11.9 KB
/
changed.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
Feature: changed
Rule languages supports item changed trigger
Background:
Given Clean OpenHAB with latest Ruby Libraries
Scenario: Item changed to matching item state
Given items:
| type | name | label |
| Number | Alarm_Mode | Alarm Mode |
And a rule
"""
rule 'Execute rule when item is changed to specific number' do
changed Alarm_Mode, to: 14
run { logger.info("Alarm Mode Updated")}
end
"""
When I deploy the rule
And item "Alarm_Mode" state is changed to "14"
Then It should log 'Alarm Mode Updated' within 5 seconds
Scenario: Item changed to one of many matching item states
Given items:
| type | name | label |
| Number | Alarm_Mode | Alarm Mode |
And a rule
"""
rule 'Execute rule when item is changed to specific number' do
changed Alarm_Mode, to: [10,14]
run { logger.info("Alarm Mode Updated")}
end
"""
When I deploy the rule
And item "Alarm_Mode" state is changed to "10"
Then It should log 'Alarm Mode Updated' within 5 seconds
Scenario: Item changed to state not in set of matching states
Given items:
| type | name | label |
| Number | Alarm_Mode | Alarm Mode |
And a rule
"""
rule 'Execute rule when item is changed to specific number' do
changed Alarm_Mode, to: [10,14]
run { logger.info("Alarm Mode Updated")}
end
"""
When I deploy the rule
And item "Alarm_Mode" state is changed to "7"
Then It should not log 'Alarm Mode Updated' within 5 seconds
Scenario: Item changed to any State
Given items:
| type | name | label |
| Number | Alarm_Mode | Alarm Mode |
And a rule
"""
rule 'Execute rule when item is changed to any state' do
changed Alarm_Mode
run { logger.info("Alarm Mode Updated")}
end
"""
When I deploy the rule
And item "Alarm_Mode" state is changed to "7"
Then It should log 'Alarm Mode Updated' within 5 seconds
Scenario: Changed works with groups
Given groups:
| type | name | function | params |
| Switch | Switches | OR | ON,OFF |
And items:
| type | name | label | state | group |
| Switch | Switch1 | Switch Number One | OFF | Switches |
And a deployed rule:
"""
rule 'Execute rule when item is changed to any state' do
changed Switches
triggered { |item| logger.info("Group #{item.id} changed")}
end
"""
When item "Switch1" state is changed to "ON"
Then It should log 'Group Switches changed' within 5 seconds
Scenario: Changed works with group members
Given group "Switches"
And items:
| type | name | label | state | group |
| Switch | Switch1 | Switch Number One | OFF | Switches |
And a deployed rule:
"""
rule 'Execute rule when item is changed to any state' do
changed Switches.members
triggered { |item| logger.info("Switch #{item.id} changed")}
end
"""
When item "Switch1" state is changed to "ON"
Then It should log 'Switch Switch Number One changed' within 5 seconds
Scenario: Changed trigger operates newly added items in groups
Given group "Switches"
And items:
| type | name | label | state | group |
| Switch | Switch1 | Switch Number One | OFF | Switches |
And a deployed rule:
"""
rule 'Execute rule when item is changed to any state' do
changed Switches.members
triggered { |item| logger.info("Switch #{item.id} changed")}
end
"""
When I add items:
| type | name | label | state | group |
| Switch | Switch2 | Switch Number Two | OFF | Switches |
And item "Switch2" state is changed to "ON"
Then It should log 'Switch Switch Number Two changed' within 5 seconds
Scenario Outline: Item changed fires for appropriate state changes
Given items:
| type | name | state |
| Switch | TestSwitch | <initial_state> |
And a rule
"""
rule 'Execute rule when item is changed from one state to another' do
changed TestSwitch
run { logger.info("Switch Changed")}
end
"""
When I deploy the rule
And item "TestSwitch" state is changed to "<state>"
Then It <should> log 'Switch Changed' within 5 seconds
Examples: Checks various initial and final states
| initial_state | state | should |
| OFF | OFF | should not |
| OFF | ON | should |
| ON | ON | should not |
| ON | OFF | should |
Scenario Outline: Changed trigger for multiple items
Given items:
| type | name | label |
| Number | Alarm_Mode1 | Alarm Mode 1 |
| Number | Alarm_Mode2 | Alarm Mode 2 |
And a rule
"""
rule 'Execute rule when either item is changed to any state' do
changed Alarm_Mode1, Alarm_Mode2
triggered { |item| logger.info("Multi item rule: #{item.name} changed to <state>")}
end
"""
When I deploy the rule
And item "<item>" state is changed to "<state>"
Then It should log 'Multi item rule: <item> changed to <state>' within 5 seconds
Examples: Change items
| item | state |
| Alarm_Mode1 | 3 |
| Alarm_Mode2 | 4 |
Scenario Outline: Changed trigger for multiple items in an array
Given items:
| type | name | label |
| Number | Alarm_Mode1 | Alarm Mode 1 |
| Number | Alarm_Mode2 | Alarm Mode 2 |
And a rule
"""
rule 'Execute rule when either item is changed to any state' do
changed [Alarm_Mode1, Alarm_Mode2]
triggered { |item| logger.info("Multi item rule: #{item.name} changed to <state>")}
end
"""
When I deploy the rule
And item "<item>" state is changed to "<state>"
Then It should log 'Multi item rule: <item> changed to <state>' within 5 seconds
Examples: Change items
| item | state |
| Alarm_Mode1 | 3 |
| Alarm_Mode2 | 4 |
Scenario: GroupMembers are separated from items in triggers
Given groups:
| type | name |
| Switch | Switches |
| Contact | Contacts |
And items:
| type | name | group |
| Switch | Switch1 | Switches |
| Switch | Switch2 | Switches |
| Switch | Switch3 | |
| Contact | Contact1 | Contacts |
| Contact | Contact2 | Contacts |
And a deployed rule:
"""
rule 'Nested groups' do
changed Switches.members, [[Contacts.members], Switch3]
triggered { |item| logger.info("#{item.id} triggered the rule") }
end
"""
When I add items:
| type | name | group |
| Contact | Contact3 | Contacts |
And item "<item>" state is changed to "<state>"
Then It should log "<item> triggered the rule" within 2 seconds
Examples:
| item | state |
| Switch1 | ON |
| Switch3 | ON |
| Contact3 | OPEN |
Scenario Outline: Item changed from one of many matching item states
Given items:
| type | name | state |
| Number | Alarm_Mode | <from_state> |
And a rule
"""
rule 'Execute rule when item is changed to specific number' do
changed Alarm_Mode, from: [10,14]
run { logger.info("Alarm Mode: Updated from <from_state> to <to_state>")}
end
"""
When I deploy the rule
And item "Alarm_Mode" state is changed to "<to_state>"
Then It <should> log 'Alarm Mode: Updated from <from_state> to <to_state>' within 5 seconds
Examples:
| from_state | to_state | should |
| 10 | 11 | should |
| 11 | 12 | should not |
| 14 | 15 | should |
Scenario Outline: Changed support ranges
Given items:
| type | name | state |
| Number | Alarm_Mode | <initial> |
And a deployed rule:
"""
rule 'Execute rule with range conditions' do
changed Alarm_Mode, <conditions>
run { |event| logger.info("Alarm Mode: Changed from #{event.was} to #{event.state}") }
end
"""
When item "Alarm_Mode" state is changed to "<change>"
Then It <should> log 'Alarm Mode: Changed from <initial> to <change>' within 5 seconds
Examples: From range
| initial | conditions | change | should |
| 10 | from: 8..10 | 14 | should |
| 15 | from: 4..12 | 14 | should not |
Examples: To range
| initial | conditions | change | should |
| 4 | to: 8..10 | 9 | should |
| 11 | to: 4..12 | 14 | should not |
Examples: From/To range
| initial | conditions | change | should |
| 4 | from: 2..5, to: 8..10 | 9 | should |
| 4 | from: 5..6, to: 8..10 | 9 | should not |
| 4 | from: 2..5, to: 8..12 | 14 | should not |
Examples: Endless ranges
| initial | conditions | change | should |
| 4 | to: (8..) | 9 | should |
| 11 | to: (15..) | 14 | should not |
Scenario Outline: Changed supports procs
Given items:
| type | name | state |
| Number | Alarm_Mode | <initial> |
And a deployed rule:
"""
rule 'Execute rule with proc conditions' do
changed Alarm_Mode, <conditions>
run { |event| logger.info("Alarm Mode: Changed from #{event.was} to #{event.state}") }
end
"""
When item "Alarm_Mode" state is changed to "<change>"
Then It <should> log 'Alarm Mode: Changed from <initial> to <change>' within 5 seconds
Examples: From with lambda
| initial | conditions | change | should |
| 10 | from: ->from {from == 10} | 14 | should |
| 15 | from: ->from {from == 10} | 14 | should not |
Examples: From with proc
| initial | conditions | change | should |
| 10 | from: proc { \|from \|from == 10} | 14 | should |
| 15 | from: proc { \|from \|from == 10} | 14 | should not |
Examples: To with lambda
| initial | conditions | change | should |
| 4 | to: ->to { to == 9 } | 9 | should |
| 11 | to: ->to { to == 9 } | 14 | should not |
Examples: To with proc
| initial | conditions | change | should |
| 4 | to: proc {\|to\|to == 9 } | 9 | should |
| 11 | to: proc {\|to\|to == 9 } | 14 | should not |
Examples: From/To with lambdas
| initial | conditions | change | should |
| 4 | from: ->f {true}, to: ->t {true} | 9 | should |
| 4 | from: ->f {false}, to: ->t {true} | 9 | should not |
| 4 | from: ->f {true}, to: ->t {false} | 9 | should not |
| 4 | from: ->f {false}, to: ->t {false} | 9 | should not |
Examples: From/To with procs
| initial | conditions | change | should |
| 4 | from: proc {true}, to: proc {true} | 9 | should |
| 4 | from: proc {false}, to: proc {true} | 9 | should not |
| 4 | from: proc {true}, to: proc {false} | 9 | should not |
| 4 | from: proc {false}, to: proc {false} | 9 | should not |
Examples: Mix procs with non-procs
| initial | conditions | change | should |
| 4 | from: proc {true}, to: 8..10 | 9 | should |
| 4 | from: proc {true}, to: 8..10 | 14 | should not |
| 4 | from: 4..10, to: proc {true} | 9 | should |
| 4 | from: 4, to: proc {true} | 9 | should |