rsmp 0.41.0 → 0.42.1

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.
@@ -7,16 +7,12 @@ module RSMP
7
7
  # Fetch the current signal plan from the remote TLC.
8
8
  def fetch_signal_plan(options: {})
9
9
  validate_ready 'fetch signal plan'
10
-
11
- status_list = [{
12
- 'sCI' => 'S0014',
13
- 'n' => 'status'
14
- }, {
15
- 'sCI' => 'S0014',
16
- 'n' => 'source'
17
- }]
18
-
19
- request_status main.c_id, status_list, @timeouts.merge(options)
10
+ timeout = options[:timeout] || @timeouts['status_response']
11
+ collector = request_status_and_collect({ S0014: %i[status source] }, within: timeout)
12
+ collector.ok!
13
+ collector.messages.last.attributes['sS'].to_h do |item|
14
+ [item['n'], item['s']]
15
+ end
20
16
  end
21
17
 
22
18
  # Subscribe to one or more statuses and wait until they match the expected values.
@@ -39,10 +35,10 @@ module RSMP
39
35
  log "Wait for #{description}", level: :debug
40
36
 
41
37
  begin
42
- subscribe_to_status component_id, subscribe_list, collect!: { timeout: timeout }
38
+ subscribe_to_status_and_collect(subscribe_list, component: component_id, within: timeout).ok!
43
39
  ensure
44
40
  unsubscribe_list = status_list.map { |item| item.slice('sCI', 'n') }
45
- unsubscribe_to_status component_id, unsubscribe_list
41
+ unsubscribe_to_status unsubscribe_list, component: component_id
46
42
  end
47
43
  end
48
44
 
@@ -75,10 +71,9 @@ module RSMP
75
71
  def read_cycle_times(options: {})
76
72
  validate_ready 'read cycle times'
77
73
  timeout = options[:timeout] || @timeouts['status_response']
78
- result = request_status main.c_id,
79
- [{ 'sCI' => 'S0028', 'n' => 'status' }],
80
- collect!: { timeout: timeout }
81
- result[:collector].messages.first.attributes['sS'].first['s'].split(',').to_h do |item|
74
+ collector = request_status_and_collect({ S0028: [:status] }, within: timeout)
75
+ collector.ok!
76
+ collector.messages.first.attributes['sS'].first['s'].split(',').to_h do |item|
82
77
  item.split('-').map(&:to_i)
83
78
  end
84
79
  end
@@ -88,10 +83,9 @@ module RSMP
88
83
  def read_current_plan(options: {})
89
84
  validate_ready 'read current plan'
90
85
  timeout = options[:timeout] || @timeouts['status_response']
91
- result = request_status main.c_id,
92
- [{ 'sCI' => 'S0014', 'n' => 'status' }],
93
- collect!: { timeout: timeout }
94
- result[:collector].messages.first.attributes['sS'].first['s'].to_i
86
+ collector = request_status_and_collect({ S0014: [:status] }, within: timeout)
87
+ collector.ok!
88
+ collector.messages.first.attributes['sS'].first['s'].to_i
95
89
  end
96
90
 
97
91
  # Read the value of a single dynamic band for a given plan and band index via S0023.
@@ -99,16 +93,15 @@ module RSMP
99
93
  def read_dynamic_band(plan:, band:, options: {})
100
94
  validate_ready 'read dynamic band'
101
95
  timeout = options[:timeout] || @timeouts['status_response']
102
- result = request_status main.c_id,
103
- [{ 'sCI' => 'S0023', 'n' => 'status' }],
104
- collect!: { timeout: timeout }
105
- extract_band_value(result, plan, band)
96
+ collector = request_status_and_collect({ S0023: [:status] }, within: timeout)
97
+ collector.ok!
98
+ extract_band_value(collector, plan, band)
106
99
  end
107
100
 
108
101
  private
109
102
 
110
- def extract_band_value(result, plan, band)
111
- result[:collector].messages.first.attributes['sS'].first['s'].split(',').each do |item|
103
+ def extract_band_value(collector, plan, band)
104
+ collector.messages.first.attributes['sS'].first['s'].split(',').each do |item|
112
105
  some_plan, some_band, value = item.split('-')
113
106
  return value.to_i if some_plan.to_i == plan.to_i && some_band.to_i == band.to_i
114
107
  end
@@ -6,7 +6,7 @@ module RSMP
6
6
  module System
7
7
  # M0103 — Change security code for a given level.
8
8
  # Does not use security_code_for since the codes are passed explicitly.
9
- def set_security_code(level:, old_code:, new_code:, options: {})
9
+ def set_security_code(level:, old_code:, new_code:, within:)
10
10
  validate_ready 'set security code'
11
11
  raise 'TLC main component not found' unless main
12
12
 
@@ -26,16 +26,15 @@ module RSMP
26
26
  'n' => 'newSecurityCode',
27
27
  'v' => new_code.to_s
28
28
  }]
29
-
30
- send_command_with_confirm main.c_id, command_list, options, "security code level #{level}", nil
29
+ send_command_and_collect(command_list, within: within).ok!
31
30
  end
32
31
 
33
32
  # M0104 — Set the clock on the remote TLC. clock must respond to year/month/day/hour/min/sec.
34
- def set_clock(clock, options: {})
33
+ def set_clock(clock, within:)
35
34
  validate_ready 'set clock'
36
35
  raise 'TLC main component not found' unless main
37
36
 
38
- send_command_with_confirm main.c_id, clock_command_list(clock), options, 'clock', nil
37
+ send_command_and_collect(clock_command_list(clock), within: within).ok!
39
38
  end
40
39
 
41
40
  private
@@ -35,7 +35,7 @@ module RSMP
35
35
  @timeouts = node.supervisor_settings.dig('default', 'timeouts') || {}
36
36
  end
37
37
 
38
- def subscribe_to_timeplan(options: {})
38
+ def subscribe_to_timeplan
39
39
  validate_ready 'subscribe to timeplan'
40
40
 
41
41
  status_list = [
@@ -44,11 +44,9 @@ module RSMP
44
44
  ]
45
45
  status_list.each { |item| item['sOc'] = true } if use_soc?
46
46
 
47
- merged_options = @timeouts.merge(options)
48
-
49
47
  raise 'TLC main component not found' unless main
50
48
 
51
- subscribe_to_status main.c_id, status_list, merged_options
49
+ subscribe_to_status status_list, component: main.c_id
52
50
  end
53
51
 
54
52
  # Override status update processing to automatically store cached status values.
@@ -94,33 +92,6 @@ module RSMP
94
92
  code
95
93
  end
96
94
 
97
- # Send a command and, if confirm: or confirm!: is present in options, wait for
98
- # confirming status updates afterwards.
99
- #
100
- # confirm_description - human-readable label used in log output
101
- # confirm_status_list - status items to wait for (passed to wait_for_status)
102
- # component_id - component to wait on (defaults to main)
103
- #
104
- # If options[:confirm] is set, timeout errors are silently swallowed.
105
- # If options[:confirm!] is set, timeout errors are raised.
106
- def send_command_with_confirm(component_id, command_list, options, confirm_description, confirm_status_list)
107
- result = send_command component_id, command_list, @timeouts.merge(options.except(:confirm, :confirm!))
108
-
109
- confirm_opts = options[:confirm] || options[:confirm!]
110
- return result unless confirm_opts
111
- return result if confirm_status_list.nil? || confirm_status_list.empty?
112
-
113
- timeout = confirm_opts.is_a?(Hash) ? confirm_opts[:timeout] : nil
114
- wait_kwargs = { timeout: timeout }.compact
115
- begin
116
- wait_for_status confirm_description, confirm_status_list, **wait_kwargs
117
- rescue RSMP::TimeoutError
118
- raise if options[:confirm!]
119
- end
120
-
121
- result
122
- end
123
-
124
95
  # Process a single status item and update the corresponding cached value.
125
96
  def cache_status_item(item)
126
97
  case item['sCI']
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = '0.41.0'.freeze
2
+ VERSION = '0.42.1'.freeze
3
3
  end
data/lib/rsmp.rb CHANGED
@@ -12,6 +12,8 @@ require 'json_schemer'
12
12
  require 'async/queue'
13
13
  require 'rsmp_schema'
14
14
 
15
+ require_relative 'rsmp/status_list'
16
+ require_relative 'rsmp/command_list'
15
17
  require_relative 'rsmp/helpers/clock'
16
18
  require_relative 'rsmp/helpers/deep_merge'
17
19
  require_relative 'rsmp/helpers/error'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.41.0
4
+ version: 0.42.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
@@ -118,8 +118,8 @@ files:
118
118
  - ".devcontainer/devcontainer.json"
119
119
  - ".github/copilot-instructions.md"
120
120
  - ".github/workflows/copilot-setup-steps.yml"
121
- - ".github/workflows/rspec.yaml"
122
121
  - ".github/workflows/rubocop.yaml"
122
+ - ".github/workflows/sus.yaml"
123
123
  - ".gitignore"
124
124
  - ".gitmodules"
125
125
  - ".rspec"
@@ -134,6 +134,7 @@ files:
134
134
  - bin/console
135
135
  - bin/setup
136
136
  - config/supervisor.yaml
137
+ - config/sus.rb
137
138
  - config/tlc.yaml
138
139
  - cucumber.yml
139
140
  - documentation/classes_and_modules.md
@@ -162,6 +163,7 @@ files:
162
163
  - lib/rsmp/collect/state_collector.rb
163
164
  - lib/rsmp/collect/status_collector.rb
164
165
  - lib/rsmp/collect/status_matcher.rb
166
+ - lib/rsmp/command_list.rb
165
167
  - lib/rsmp/component/alarm_state.rb
166
168
  - lib/rsmp/component/component.rb
167
169
  - lib/rsmp/component/component_base.rb
@@ -212,6 +214,7 @@ files:
212
214
  - lib/rsmp/proxy/supervisor/modules/commands.rb
213
215
  - lib/rsmp/proxy/supervisor/modules/status.rb
214
216
  - lib/rsmp/proxy/supervisor/supervisor_proxy.rb
217
+ - lib/rsmp/status_list.rb
215
218
  - lib/rsmp/tlc/detector_logic.rb
216
219
  - lib/rsmp/tlc/input_states.rb
217
220
  - lib/rsmp/tlc/modules/detector_logics.rb