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) ⇒ Array

Build a RSMP command value list from a hash

Parameters:

  • command_code_id (Symbol)

    the command code identifier (e.g. :M0001)

  • command_name (Symbol)

    the command name (e.g. :setValue)

  • values (Hash)

    key-value pairs for command parameters

Returns:

  • (Array)

    formatted command list for RSMP



16
17
18
19
20
21
22
23
24
25
# File 'spec/support/command_helpers.rb', line 16

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



136
137
138
139
140
141
142
143
144
# File 'spec/support/command_helpers.rb', line 136

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



126
127
128
129
130
131
132
133
134
# File 'spec/support/command_helpers.rb', line 126

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



156
157
158
159
160
161
162
163
164
# File 'spec/support/command_helpers.rb', line 156

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



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'spec/support/command_helpers.rb', line 292

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



433
434
435
436
437
438
439
440
# File 'spec/support/command_helpers.rb', line 433

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



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

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



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'spec/support/command_helpers.rb', line 209

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



648
649
650
651
# File 'spec/support/command_helpers.rb', line 648

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

#require_security_codesObject

Check if security codes are configured, skip test if not available



364
365
366
367
368
# File 'spec/support/command_helpers.rb', line 364

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

#reset_clockObject



456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'spec/support/command_helpers.rb', line 456

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



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'spec/support/command_helpers.rb', line 620

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

Send an RSMP command and wait for confirmation response



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

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



442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'spec/support/command_helpers.rb', line 442

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(plan, cycle_time, description = "Set cycle time to #{cycle_time} for plan #{plan}") ⇒ Object



252
253
254
255
256
257
258
259
260
# File 'spec/support/command_helpers.rb', line 252

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

#set_day_table(status) ⇒ Object



243
244
245
246
247
248
249
250
# File 'spec/support/command_helpers.rb', line 243

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



199
200
201
202
203
204
205
206
207
# File 'spec/support/command_helpers.rb', line 199

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



118
119
120
121
122
123
124
# File 'spec/support/command_helpers.rb', line 118

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

#set_fixed_time(status) ⇒ Object



109
110
111
112
113
114
115
116
# File 'spec/support/command_helpers.rb', line 109

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



98
99
100
101
102
103
104
105
106
107
# File 'spec/support/command_helpers.rb', line 98

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



146
147
148
149
150
151
152
153
154
# File 'spec/support/command_helpers.rb', line 146

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



224
225
226
227
228
229
230
231
232
# File 'spec/support/command_helpers.rb', line 224

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



52
53
54
55
56
57
58
59
60
# File 'spec/support/command_helpers.rb', line 52

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



352
353
354
355
356
357
358
359
360
361
# File 'spec/support/command_helpers.rb', line 352

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



190
191
192
193
194
195
196
197
# File 'spec/support/command_helpers.rb', line 190

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



28
29
30
31
32
33
34
35
36
37
# File 'spec/support/command_helpers.rb', line 28

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_stopObject

Order a signal group to red



40
41
42
43
44
45
46
47
48
49
# File 'spec/support/command_helpers.rb', line 40

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



343
344
345
346
347
348
349
350
# File 'spec/support/command_helpers.rb', line 343

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



72
73
74
75
76
77
78
79
80
81
# File 'spec/support/command_helpers.rb', line 72

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



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

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



234
235
236
237
238
239
240
241
# File 'spec/support/command_helpers.rb', line 234

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



471
472
473
474
475
476
# File 'spec/support/command_helpers.rb', line 471

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



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

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



182
183
184
185
186
187
188
# File 'spec/support/command_helpers.rb', line 182

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



570
571
572
573
574
575
576
# File 'spec/support/command_helpers.rb', line 570

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



578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'spec/support/command_helpers.rb', line 578

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



565
566
567
568
# File 'spec/support/command_helpers.rb', line 565

def switch_normal_control
  set_functional_position 'NormalControl'
  wait_normal_control
end

#switch_plan(plan) ⇒ Object



166
167
168
169
170
171
172
# File 'spec/support/command_helpers.rb', line 166

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

Switch to traffic situation and wait for confirmation via status



63
64
65
66
67
68
69
# File 'spec/support/command_helpers.rb', line 63

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



174
175
176
177
178
179
180
# File 'spec/support/command_helpers.rb', line 174

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)



86
87
88
89
90
91
92
93
94
95
# File 'spec/support/command_helpers.rb', line 86

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 automatic traffic situation"
end

#verify_startup_sequence(&block) ⇒ Object



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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'spec/support/command_helpers.rb', line 512

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' => true) } 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



500
501
502
503
504
505
506
507
508
509
510
# File 'spec/support/command_helpers.rb', line 500

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 an 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.



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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'spec/support/command_helpers.rb', line 373

def with_alarm_activated task, site, alarm_code_id, initial_deactivation: true
  input_nr, component_id = find_alarm_programming(alarm_code_id)
  component_id ||= 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



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

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

#with_cycle_time_extended(site, extension = 5, &block) ⇒ Object



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

def with_cycle_time_extended site, extension=5, &block
  # read current plan
  plan = read_current_plan(site)

  # read initial cycle times
  times = read_cycle_times(site)
  time = times[plan]

  expect(time).to_not be_nil, "Site returned empty cycle times list"

  # change cycle tme
  time_extended = time + extension
  need_to_reset = true
  set_cycle_time plan, time_extended, "Extend cycle time to #{time_extended} for plan #{plan}"

  # read updated cycle times
  increase = 5
  times = read_cycle_times(site, "updated cycle times")
  time_extended_actual = times[plan]
  expect(time_extended_actual).to eq(time_extended)

  block.yield
ensure
  if need_to_reset
    log "Reset cycle time"
    set_cycle_time plan, time
  end
end

#wrong_security_codeObject



487
488
489
490
491
492
493
494
495
496
497
498
# File 'spec/support/command_helpers.rb', line 487

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