Module: Validator::CommandHelpers

Included in:
StatusHelpers::SignalPriorityRequestHelper
Defined in:
spec/support/command_helpers.rb

Instance Method Summary collapse

Instance Method Details

#build_command_list(command_code_id, command_name, values) ⇒ Object

Build a RSMP command value list from a hash



11
12
13
14
15
16
17
18
19
20
# File 'spec/support/command_helpers.rb', line 11

def build_command_list command_code_id, command_name, values
  values.compact.to_a.map do |n,v|
    {
      'cCI' => command_code_id.to_s,
      'cO' => command_name.to_s,
      'n' => n.to_s,
      'v' => v.to_s
    }
  end
end

#disable_emergency_route(route) ⇒ Object



139
140
141
142
143
144
145
146
147
# File 'spec/support/command_helpers.rb', line 139

def disable_emergency_route route
  require_security_codes
  command_list = build_command_list :M0005, :setEmergency, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: 'False',
    emergencyroute: route
  }
  send_command_and_confirm @task, command_list, "Disable emergency route #{route}"
end

#enable_emergency_route(route) ⇒ Object



129
130
131
132
133
134
135
136
137
# File 'spec/support/command_helpers.rb', line 129

def enable_emergency_route route
  require_security_codes
  command_list = build_command_list :M0005, :setEmergency, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: 'True',
    emergencyroute: route
  }
  send_command_and_confirm @task, command_list, "Enable emergency route #{route}"
end

#force_detector_logic(component, status: 'True', mode: 'True') ⇒ Object



159
160
161
162
163
164
165
166
167
# File 'spec/support/command_helpers.rb', line 159

def force_detector_logic component, status:'True', mode:'True'
  require_security_codes
  command_list = build_command_list :M0008, :setForceDetectorLogic, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status,
    mode: mode
  }
  send_command_and_confirm @task, command_list, "Force detector logic #{component} to #{mode}", component
end

#force_input(input:, status: 'True', value: 'True', validate: true) ⇒ Object



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
# File 'spec/support/command_helpers.rb', line 265

def force_input input:, status:'True', value: 'True', validate:true
  require_security_codes
  if status == 'True'
    str = "Force input #{input} to #{value}"
    wait_str = "input #{input} to be forced to #{value}"
  else
    str =  "Release input #{input}"
    wait_str = "input #{input} to be released"
  end
  command_list = build_command_list :M0019, :setInput, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status,
    input: input,
    inputValue: value
  }
  send_command_and_confirm @task, command_list, str

  if status == 'True'
    input_status_str = value == 'True' ? '1' : '0'
    wait_for_status(@task, wait_str, [
      {'sCI'=>'S0029','n'=>'status','s'=>/^.{#{input - 1}}1/},
      {'sCI'=>'S0003','n'=>'inputstatus','s'=>/^.{#{input - 1}}#{input_status_str}/}
    ])
  else
    wait_for_status(@task, wait_str, [
      {'sCI'=>'S0029','n'=>'status','s'=>/^.{#{input - 1}}0/}
    ])
  end

end

#force_input_and_confirm(input:, value:) ⇒ Object



408
409
410
411
412
413
414
415
# File 'spec/support/command_helpers.rb', line 408

def force_input_and_confirm(input:, value:)
  force_input status: 'True', input: input, value: value
  digit = (value == 'True' ? '1' : '0')
  wait_for_status(@task,
    "input #{input} to be #{value}",
    [{'sCI'=>'S0003','n'=>'inputstatus','s'=>/^.{#{input-1}}#{digit}/}] # index is 1-based, convert to 0-based fo regex
  )
end

#force_output(output:, status:, value: 'True', validate: true) ⇒ Object



296
297
298
299
300
301
302
303
304
305
# File 'spec/support/command_helpers.rb', line 296

def force_output output:, status:, value:'True', validate:true
  require_security_codes
  command_list = build_command_list :M0020, :setOutput, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status,
    output: output,
    outputValue: value
  }
  send_command_and_confirm @task, command_list, "Force output #{output} to #{value}"
end

#get_dynamic_bands(plan, band) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'spec/support/command_helpers.rb', line 212

def get_dynamic_bands plan, band
  Validator.log "Get dynamic bands", level: :test
  status_list = { S0023: [:status] }
  result = @site.request_status Validator.get_config('main_component'), convert_status_list(status_list), collect!: {
    timeout: Validator.get_config('timeouts','status_update', default: 0)
  }
  collector = result[:collector]
  collector.matchers.first.got['s'].split(',').each do |item|
    some_plan, some_band, value = *item.split('-')
    return value.to_i if some_plan.to_i == plan.to_i && some_band.to_i == band.to_i
  end
  nil
end

#prepare(task, site) ⇒ Object



623
624
625
626
# File 'spec/support/command_helpers.rb', line 623

def prepare task, site
  @task = task
  @site = site
end

#require_security_codesObject



336
337
338
339
340
# File 'spec/support/command_helpers.rb', line 336

def require_security_codes
  unless Validator.config.dig 'secrets', 'security_codes'
    skip "Security codes are not configured"
  end
end

#reset_clockObject



431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'spec/support/command_helpers.rb', line 431

def reset_clock
  require_security_codes
  now = Time.now.utc
  command_list = build_command_list :M0104, :setDate, {
    securityCode: Validator.get_config('secrets','security_codes',1),
    year: now.year,
    month: now.month,
    day: now.day,
    hour: now.hour,
    minute: now.min,
    second: now.sec
  }
  send_command_and_confirm @task, command_list, "Reset clock to #{now}"
end

#resume_alarm(site, task, cId:, aCId:, collect:) ⇒ Object



595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'spec/support/command_helpers.rb', line 595

def resume_alarm site, task, cId:, aCId:, collect:
  resume = RSMP::AlarmResume.new(
    'mId' => RSMP::Message.make_m_id,     # generate a message id, that can be used to listen for responses
    'cId' => cId,
    'aCId' => aCId
  )
  if collect
    collect_task = task.async do
      RSMP::AlarmCollector.new(site,
        m_id: resume.m_id,
        num: 1,
        matcher: {
          'cId' => cId,
          'aCI'=>aCId,
          'aSp'=>'Suspend',
          'sS'=>/^notSuspended/i
        },
        timeout: Validator.config['timeouts']['alarm']
      ).collect!
    end
    site.send_message resume
    return resume, collect_task.wait.first
  else
    site.send_message resume
    resume
  end
end

#send_command_and_confirm(parent_task, command_list, message, component = Validator.get_config('main_component')) ⇒ Object



2
3
4
5
6
7
8
# File 'spec/support/command_helpers.rb', line 2

def send_command_and_confirm parent_task, command_list, message, component=Validator.get_config('main_component')
  result = nil
  log message
  @site.send_command component, command_list, collect!: {
    timeout: Validator.get_config('timeouts','command_response')
  }
end

#set_clock(clock) ⇒ Object



417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'spec/support/command_helpers.rb', line 417

def set_clock clock
  require_security_codes
  command_list = build_command_list :M0104, :setDate, {
    securityCode: Validator.get_config('secrets','security_codes',1),
    year: clock.year,
    month: clock.month,
    day: clock.day,
    hour: clock.hour,
    minute: clock.min,
    second: clock.sec
  }
  send_command_and_confirm @task, command_list, "Set clock to #{clock}"
end

#set_cycle_time(status, plan) ⇒ Object



255
256
257
258
259
260
261
262
263
# File 'spec/support/command_helpers.rb', line 255

def set_cycle_time status, plan
  require_security_codes
  command_list = build_command_list :M0018, :setCycleTime, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status,
    plan: plan
  }
  send_command_and_confirm @task, command_list, "Set cycle time to #{plan}"
end

#set_day_table(status) ⇒ Object



246
247
248
249
250
251
252
253
# File 'spec/support/command_helpers.rb', line 246

def set_day_table status
  require_security_codes
  command_list = build_command_list :M0017, :setTimeTable, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status
  }
  send_command_and_confirm @task, command_list, "Set time table to #{status}"
end

#set_dynamic_bands(plan, status) ⇒ Object



202
203
204
205
206
207
208
209
210
# File 'spec/support/command_helpers.rb', line 202

def set_dynamic_bands plan, status
  require_security_codes
  command_list = build_command_list :M0014, :setCommands, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status,
    plan: plan
  }
  send_command_and_confirm @task, command_list, "Set dynamic bands to #{status} for plan #{plan}"
end

#set_emergency_route(route, state) ⇒ Object



121
122
123
124
125
126
127
# File 'spec/support/command_helpers.rb', line 121

def set_emergency_route route, state
  if state
    enable_emergency_route route
  else
    disable_emergency_route route
  end
end

#set_fixed_time(status) ⇒ Object



112
113
114
115
116
117
118
119
# File 'spec/support/command_helpers.rb', line 112

def set_fixed_time status
  require_security_codes
  command_list = build_command_list :M0007, :setFixedTime, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status
  }
  send_command_and_confirm @task, command_list, "Switch to fixed time #{status}"
end

#set_functional_position(status, timeout_minutes: 0) ⇒ Object

Set functional position



101
102
103
104
105
106
107
108
109
110
# File 'spec/support/command_helpers.rb', line 101

def set_functional_position status, timeout_minutes:0
  require_security_codes
  command_list = build_command_list :M0001, :setValue, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status,
    timeout: timeout_minutes,
    intersection: 0,
  }
  send_command_and_confirm @task, command_list, "Switch to functional position #{status}"
end

#set_input(status, input) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'spec/support/command_helpers.rb', line 149

def set_input status, input
  require_security_codes
  command_list = build_command_list :M0006, :setInput, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status,
    input: input
  }
  send_command_and_confirm @task, command_list, "Set input #{input} to #{status}"
end

#set_offset(status, plan) ⇒ Object



227
228
229
230
231
232
233
234
235
# File 'spec/support/command_helpers.rb', line 227

def set_offset status, plan
  require_security_codes
  command_list = build_command_list :M0015, :setOffset, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status,
    plan: plan
  }
  send_command_and_confirm @task, command_list, "Set offset for plan #{plan} to #{status}"
end

#set_plan(plan) ⇒ Object

Switch signal plan



56
57
58
59
60
61
62
63
64
# File 'spec/support/command_helpers.rb', line 56

def set_plan plan
  require_security_codes
  command_list = build_command_list :M0002, :setPlan, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: 'True',     # true = use plan nr in commone, false = use time table
    timeplan: plan
  }
  send_command_and_confirm @task, command_list, "Switch to plan #{plan}"
end

#set_security_code(level) ⇒ Object



325
326
327
328
329
330
331
332
333
334
# File 'spec/support/command_helpers.rb', line 325

def set_security_code level
  require_security_codes
  status = "Level#{level}"
  command_list = build_command_list :M0103, :setSecurityCode, {
    oldSecurityCode: Validator.get_config('secrets','security_codes',level),
    newSecurityCode: Validator.get_config('secrets','security_codes',level),
    status: status
  }
  send_command_and_confirm @task, command_list, "Set security code for level #{level}"
end

#set_series_of_inputs(status) ⇒ Object



193
194
195
196
197
198
199
200
# File 'spec/support/command_helpers.rb', line 193

def set_series_of_inputs status
  require_security_codes
  command_list = build_command_list :M0013, :setInput, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status
  }
  send_command_and_confirm @task, command_list, "Set a series of inputs using #{status}"
end

#set_signal_startObject

Order a signal group to green



23
24
25
26
27
28
29
30
31
32
# File 'spec/support/command_helpers.rb', line 23

def set_signal_start
  require_security_codes
  command_list = build_command_list :M0010, :setStart, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: 'True'
  }
  indx = 0
  component = Validator.get_config('components','signal_group').keys[indx]
  send_command_and_confirm @task, command_list, "Order signal group #{indx} to green", component
end

#set_signal_start_or_stop(status) ⇒ Object

Request series of signal groups to start/stop



47
48
49
50
51
52
53
# File 'spec/support/command_helpers.rb', line 47

def set_signal_start_or_stop status
  command_list = build_command_list :M0012, :setStart, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status
  }
  send_command_and_confirm @task, command_list, "Request series of signal groups to #{status}"
end

#set_signal_stopObject

Order a signal group to red



35
36
37
38
39
40
41
42
43
44
# File 'spec/support/command_helpers.rb', line 35

def set_signal_stop
  require_security_codes
  command_list = build_command_list :M0011, :setStop, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: 'True'
  }
  indx = 0
  component = Validator.get_config('components','signal_group').keys[indx]
  send_command_and_confirm @task, command_list, "Order signal group #{indx} to red", component
end

#set_timeout_for_dynamic_bands(status) ⇒ Object



316
317
318
319
320
321
322
323
# File 'spec/support/command_helpers.rb', line 316

def set_timeout_for_dynamic_bands status
  require_security_codes
  command_list = build_command_list :M0023, :setTimeout, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status
  }
  send_command_and_confirm @task, command_list, "Set timeout for dynamic bands to #{status}"
end

#set_traffic_situation(ts) ⇒ Object

Set traffic situation



75
76
77
78
79
80
81
82
83
84
# File 'spec/support/command_helpers.rb', line 75

def set_traffic_situation ts
  require_security_codes
  command_list = build_command_list :M0003, :setTrafficSituation, {
    status: 'True',
    securityCode: Validator.get_config('secrets','security_codes',2),
    traficsituation: ts   # note: the spec misspells 'traficsituation'

  }
  send_command_and_confirm @task, command_list, "Switch to traffic situation #{ts}"
end

#set_trigger_level(status) ⇒ Object



307
308
309
310
311
312
313
314
# File 'spec/support/command_helpers.rb', line 307

def set_trigger_level status
  require_security_codes
  command_list = build_command_list :M0021, :setLevel, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status
  }
  send_command_and_confirm @task, command_list, "Set trigger level sensitivity for loop detector to #{status}"
end

#set_week_table(status) ⇒ Object



237
238
239
240
241
242
243
244
# File 'spec/support/command_helpers.rb', line 237

def set_week_table status
  require_security_codes
  command_list = build_command_list :M0016, :setWeekTable, {
    securityCode: Validator.get_config('secrets','security_codes',2),
    status: status
  }
  send_command_and_confirm @task, command_list, "Set week table to #{status}"
end

#stop_sending_watchdogs(site) ⇒ Object



446
447
448
449
450
451
# File 'spec/support/command_helpers.rb', line 446

def stop_sending_watchdogs(site)
  # monkey-patch the site object by redefining
  # the send_watchdog method to do nothing
  def site.send_watchdog now=nil
  end
end

#suspend_alarm(site, task, cId:, aCId:, collect:) ⇒ Object



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'spec/support/command_helpers.rb', line 567

def suspend_alarm site, task, cId:, aCId:, collect:
  suspend = RSMP::AlarmSuspend.new(
    'mId' => RSMP::Message.make_m_id,  # generate a message id, that can be used to listen for responses
    'cId' => cId,
    'aCId' => aCId
  )
  if collect
    collect_task = task.async do
      RSMP::AlarmCollector.new(site,
        m_id: suspend.m_id,
        num: 1,
        matcher: {
          'cId' => cId,
          'aCI' => aCId,
          'aSp' => 'Suspend',
          'sS' => /^Suspended/i
        },
        timeout: Validator.config['timeouts']['alarm']
      ).collect!
    end
    site.send_message suspend
    return suspend, collect_task.wait.first
  else
    site.send_message suspend
    suspend
  end
end

#switch_dark_modeObject



185
186
187
188
189
190
191
# File 'spec/support/command_helpers.rb', line 185

def switch_dark_mode
  set_functional_position 'Dark'
  wait_for_status(@task,
    "dark mode",
    [{'sCI'=>'S0007','n'=>'status','s'=>/^False(,False)*$/}]
  )
end

#switch_fixed_time(status) ⇒ Object



545
546
547
548
549
550
551
# File 'spec/support/command_helpers.rb', line 545

def switch_fixed_time status
  set_fixed_time status
  wait_for_status(@task,
    "fixed time to be #{status}",
    [{'sCI'=>'S0009','n'=>'status','s'=>/^#{status}(,#{status})*$/}]
  )
end

#switch_input(indx) ⇒ Object



553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'spec/support/command_helpers.rb', line 553

def switch_input indx
  set_input 'True',indx.to_s
  wait_for_status(@task,
    "input #{indx} to be True",
    [{'sCI'=>'S0003','n'=>'inputstatus','s'=>/^.{#{indx-1}}1/}] # index is 1-based, convert to 0-based fo regex
  )

  set_input 'False',indx.to_s
  wait_for_status(@task,
    "input #{indx} to be False",
    [{'sCI'=>'S0003','n'=>'inputstatus','s'=>/^.{#{indx-1}}0/}]
  )
end

#switch_normal_controlObject



540
541
542
543
# File 'spec/support/command_helpers.rb', line 540

def switch_normal_control
  set_functional_position 'NormalControl'
  wait_normal_control
end

#switch_plan(plan) ⇒ Object



169
170
171
172
173
174
175
# File 'spec/support/command_helpers.rb', line 169

def switch_plan plan
  set_plan plan.to_s
  wait_for_status(@task,
    "plan #{plan} to be active",
    [{'sCI'=>'S0014','n'=>'status','s'=>plan.to_s}]
  )
end

#switch_traffic_situation(ts) ⇒ Object



66
67
68
69
70
71
72
# File 'spec/support/command_helpers.rb', line 66

def switch_traffic_situation ts
  set_traffic_situation ts
  wait_for_status(@task,
    "traffic situation #{ts}",
    [{'sCI'=>'S0015','n'=>'status','s'=>ts}]
  )
end

#switch_yellow_flash(timeout_minutes: 0) ⇒ Object



177
178
179
180
181
182
183
# File 'spec/support/command_helpers.rb', line 177

def switch_yellow_flash timeout_minutes: 0
  set_functional_position 'YellowFlash', timeout_minutes: timeout_minutes
  wait_for_status(@task,
    "yellow flash",
    [{'sCI'=>'S0011','n'=>'status','s'=>/^True(,True)*$/}]
  )
end

#unset_traffic_situationObject

Unset traffic situation (switch to automatic) The spec does not state what traficsituation to use when unsetting, here we’re using 1. (Allowed range is 1-255)



89
90
91
92
93
94
95
96
97
98
# File 'spec/support/command_helpers.rb', line 89

def unset_traffic_situation
  require_security_codes
  command_list = build_command_list :M0003, :setTrafficSituation, {
    status: 'False',
    securityCode: Validator.get_config('secrets','security_codes',2),
    traficsituation: '1'   # note: the spec misspells 'traficsituation'

  }
  send_command_and_confirm @task, command_list, "Switch to automaatic traffic situation"
end

#verify_startup_sequence(&block) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'spec/support/command_helpers.rb', line 487

def verify_startup_sequence &block
   status_list = [{'sCI'=>'S0001','n'=>'signalgroupstatus'}]
   subscribe_list = convert_status_list(status_list).map { |item| item.merge 'uRt'=>0.to_s }
   subscribe_list.map! { |item| item.merge!('sOc' => false) } if use_sOc?(@site)

   unsubscribe_list = convert_status_list(status_list)
   component = Validator.get_config('main_component')
   timeout = Validator.get_config('timeouts','startup_sequence')
   collector = RSMP::StatusCollector.new @site, status_list, timeout: timeout
   sequencer = Validator::StatusHelpers::SignalGroupSequenceHelper.new Validator.get_config('startup_sequence')
   states = nil

   collector_task = @task.async do
     log "Verifying startup sequence"
     collector.collect do |message,item|   # listen for status messages
       next unless item
       states = item['s']
       #p states
       status  = sequencer.check states      # check sequences
       if status == :ok
         log "Startup sequence #{states}: OK"
         if sequencer.done?             # if all groups reached end?
           collector.complete           # then end collection
         else
           false                        # reject item, ie. continue collecting
         end
       else
         log "Startup sequence #{states}: Fail"
         collector.cancel status        # if sequence was incorrect then cancel collection
       end
     end
   end

   # let block take other actions, like activating yellow flash, change control mode, etc.
   yield

   # subscribe, so we start getting status udates
   @site.subscribe_to_status component, subscribe_list

   case collector_task.wait  # wait for the collector to complete
   when :ok
     log "Startup sequence verified"
   when :timeout
     raise "Startup sequence '#{sequencer.sequence}' didn't complete in #{timeout}s, reached #{sequencer.latest}, #{sequencer.num_started} started, #{sequencer.num_done} done"
   when :cancelled
     raise "Startup sequence '#{sequencer.sequence}' not followed: #{collector.error}"
   end

   wait_for_status(@task,"control mode to be startup", [{'sCI'=>'S0020','n'=>'controlmode','s'=>'control'}])
 ensure
   @site.unsubscribe_to_status component, unsubscribe_list  # unsubscribe
end

#wait_normal_control(timeout: Validator.get_config('timeouts','startup_sequence')) ⇒ Object



475
476
477
478
479
480
481
482
483
484
485
# File 'spec/support/command_helpers.rb', line 475

def wait_normal_control timeout: Validator.get_config('timeouts','startup_sequence')
  wait_for_status(@task,
    "normal control on, yellow flash off, startup mode off",
    [
      {'sCI'=>'S0007','n'=>'status','s'=>/^True(,True)*$/},     # normal control on (=dark mode off)
      {'sCI'=>'S0011','n'=>'status','s'=>/^False(,False)*$/},   # yellow flash off
      {'sCI'=>'S0005','n'=>'status','s'=>'False'}               # startup mode off
    ],
    timeout: timeout
  )
end

#with_alarm_activated(task, site, alarm_code_id, initial_deactivation: true) ⇒ Object

Run a block with ana alarm acticated, then deactive the alarm The device must be programmed to activate an alarm when a specific input is acticated, and the mapping must be configured in the test config.



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'spec/support/command_helpers.rb', line 345

def with_alarm_activated task, site, alarm_code_id, initial_deactivation: true
  action = Validator.config.dig('alarms', alarm_code_id)
  skip "alarm #{alarm_code_id} is not configured" unless action
  input_nr = action['activation_input']
  skip "alarm #{alarm_code_id} has no activation input configured" unless input_nr
  component_id = action['component'] || Validator.get_config('main_component')
  if initial_deactivation
    force_input_and_confirm input: input_nr, value: 'False'
  end
  state = false
  begin
    if RSMP::Proxy.version_meets_requirement? site.core_version, '>=3.2'
      # from core 3.2 all enum matching must be match exactly
      alarm_specialization = /Issue/
      alarm_active = /Active/
      alarm_inactive = /inActive/
    else
      # before 3.2 match is done case-insensitively
      alarm_specialization = /issue/i
      alarm_active = /active/i
      alarm_inactive = /inactive/i
    end

    collect_task = task.async do  # run the collector in an async task
      collector = RSMP::AlarmCollector.new( site,
        num: 1,
        matcher: { 
          'cId' => component_id,
          'aCId' =>  alarm_code_id,
          'aSp' =>  alarm_specialization,
          'aS' => alarm_active
        },
        timeout: Validator.get_config('timeouts','alarm')
      )
      collector.collect!
      collector.messages.first
    end
    force_input_and_confirm input: input_nr, value: 'True'
    state = true
    yield collect_task.wait, component_id

    collect_task = task.async do  # run the collector in an async task
      collector = RSMP::AlarmCollector.new( site,
        num: 1,
        matcher: {
          'cId' => component_id,
          'aCId' =>  alarm_code_id,
          'aSp' =>  /Issue/i,
          'aS' => alarm_inactive
        },
        timeout: Validator.get_config('timeouts','alarm')
      )
      collector.collect!
      collector.messages.first
    end
    force_input_and_confirm input: input_nr, value: 'False'
    state = false
    return collect_task.wait, component_id
  ensure
    force_input_and_confirm input: input_nr, value: 'False' if state == true
  end
end

#with_clock_set(site, clock, &block) ⇒ Object



453
454
455
456
457
458
459
# File 'spec/support/command_helpers.rb', line 453

def with_clock_set site, clock, &block
  result = set_clock clock
  site.clear_alarm_timestamps
  yield result
ensure
  reset_clock
end

#wrong_security_codeObject



462
463
464
465
466
467
468
469
470
471
472
473
# File 'spec/support/command_helpers.rb', line 462

def wrong_security_code
  log "Try to force detector logic with wrong security code"
  command_list = build_command_list :M0008, :setForceDetectorLogic, {
    securityCode: '1111',
    status: 'True',
    mode: 'True'
  }
  component = Validator.get_config('components','detector_logic').keys[0]
  result = @site.send_command component, command_list, collect!: {
    timeout: Validator.get_config('timeouts','command_response')
  }
end