rsmp 0.20.4 → 0.20.6

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: d4c2f0ad26f341d78dba43980b9f873a75bf06d2233ffa3f27b30b3f7d83e297
4
- data.tar.gz: 84187fc4d5c836233397ff20ffff5cdf236435069d3edb436999fe5f8de1436b
3
+ metadata.gz: 83d3f61fbf037ff67cf6cdec5eb9d043d75336f376ad5a9e2cf343631f962bd8
4
+ data.tar.gz: d185368c970e5174f66af74f95be3116793a19d7ce4a7a5496dd9c852c9a36fa
5
5
  SHA512:
6
- metadata.gz: 1950948c8087db84fbf12069e4fcee10160efa8e4031ba618dcbdf04c130104df5f6e8467f0cfdb647615ab5de3b96fcb7cc9cfeaf5ec458bc0471e9f09676e2
7
- data.tar.gz: c9999221cc2b49d5320d2769230e8ba7c9e54bf5a4f4e37c7efdef599b7745f8d85dbb29c2ed7fc01304604e591a5303422e813e9dee978286760e3897705aa2
6
+ metadata.gz: '094efccdc73a1da1b397e8b9c1b6fdea341d8499c27d2f4507334156bc89801474ef5d1646549ca79958b52787759317dcdcd4a742617c4ac957913d4cd7a36c'
7
+ data.tar.gz: 86fb74137d721a9dd74aeb3c9b8fd16418655e8dedfa1f3f19425abb1af045c59463a989639d17255777aa781f74c009639537a43bcd3c4f7f953baaaba084b1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.20.4)
4
+ rsmp (0.20.6)
5
5
  async (~> 2.6.2)
6
6
  async-io (~> 1.35.0)
7
7
  colorize (~> 0.8.1)
@@ -76,7 +76,7 @@ GEM
76
76
  multi_test (1.1.0)
77
77
  rake (13.0.6)
78
78
  regexp_parser (2.8.1)
79
- rsmp_schema (0.4.0)
79
+ rsmp_schema (0.4.5)
80
80
  json_schemer (~> 0.2.21)
81
81
  thor (~> 1.2.1)
82
82
  rspec (3.12.0)
@@ -39,22 +39,21 @@ module RSMP
39
39
  end
40
40
 
41
41
  def infer_component_type component_id
42
- Component
42
+ raise UnknownComponent.new("Component #{component_id} mising and cannot infer type")
43
43
  end
44
44
 
45
45
  def find_component component_id, build: true
46
46
  component = @components[component_id]
47
47
  return component if component
48
- if build && !component_id.empty?
49
- inferred = infer_component_type component_id
50
- component = inferred.new node: self, id: component_id
48
+ if build
49
+ inferred_type = infer_component_type component_id
50
+ component = inferred_type.new node: self, id: component_id
51
51
  @components[ component_id] = component
52
52
  class_name = component.class.name.split('::').last
53
53
  class_name << " component" unless (class_name == 'Component' || class_name == 'ComponentProxy')
54
- log "Adding component #{component_id} with the inferred type #{class_name}", level: :debug
54
+ log "Added component #{component_id} with the inferred type #{class_name}", level: :debug
55
55
  component
56
56
  else
57
- raise UnknownComponent.new("Component #{component_id} not found") unless component
58
57
  end
59
58
  end
60
59
 
data/lib/rsmp/proxy.rb CHANGED
@@ -403,8 +403,7 @@ module RSMP
403
403
  nil
404
404
  rescue SchemaError, RSMP::Schema::Error => e
405
405
  reason = "schema errors: #{e.message}"
406
- str = "Received invalid #{message.type}, #{reason}"
407
- log str, message: message, level: :warning
406
+ str = "Received invalid #{message.type}"
408
407
  notify_error e.exception(str), message: message
409
408
  dont_acknowledge message, str, reason
410
409
  message
@@ -67,8 +67,9 @@ module RSMP
67
67
  def connect_tcp
68
68
  @endpoint = Async::IO::Endpoint.tcp(@ip, @port)
69
69
 
70
+ error = nil
70
71
  # Async::IO::Endpoint#connect renames the current task. run in a subtask to avoid this see issue #22
71
- @task.async do |task|
72
+ result = @task.async do |task|
72
73
  task.annotate 'socket task'
73
74
  # this timeout is a workaround for connect hanging on windows if the other side is not present yet
74
75
  timeout = @site_settings.dig('timeouts','connect') || 1.1
@@ -77,7 +78,11 @@ module RSMP
77
78
  end
78
79
  delay = @site_settings.dig('intervals','after_connect')
79
80
  task.sleep delay if delay
81
+ rescue Errno::ECONNREFUSED => e # rescue to avoid log output
82
+ log "Connection refused", level: :warning
83
+ error = e
80
84
  end.wait
85
+ raise error if error # reraise any error outside task
81
86
 
82
87
  @stream = Async::IO::Stream.new(@socket)
83
88
  @protocol = Async::IO::Protocol::Line.new(@stream,WRAPPING_DELIMITER) # rsmp messages are json terminated with a form-feed
@@ -276,8 +281,8 @@ module RSMP
276
281
  component.handle_command command_code,arg
277
282
  end
278
283
  log "Received #{message.type}", message: message, level: :log
279
- rescue UnknownComponent => e
280
- log "Received #{message.type} with unknown component id '#{component_id}'", message: message, level: :warning
284
+ rescue UnknownComponent
285
+ log "Received #{message.type} with unknown component id '#{component_id}' and cannot infer type", message: message, level: :warning
281
286
  # If the component is unknown, we must set age=undefined for all items,
282
287
  # while still acknowledge the message.
283
288
  # See https://github.com/rsmp-nordic/rsmp_validator/issues/271
@@ -302,19 +307,32 @@ module RSMP
302
307
  end
303
308
 
304
309
  def process_status_request message, options={}
305
- component_id = message.attributes["cId"]
306
- component = @site.find_component component_id
307
- log "Received #{message.type}", message: message, level: :log
308
- sS = message.attributes["sS"].map do |arg|
309
- value, quality = component.get_status arg['sCI'], arg['n'], {sxl_version: sxl_version}
310
- { "s" => rsmpify_value(value), "q" => quality.to_s }.merge arg
310
+ sS = []
311
+ begin
312
+ component_id = message.attributes["cId"]
313
+ component = @site.find_component component_id
314
+ sS = message.attributes["sS"].map do |arg|
315
+ value, quality = component.get_status arg['sCI'], arg['n'], {sxl_version: sxl_version}
316
+ { "s" => rsmpify_value(value), "q" => quality.to_s }.merge arg
317
+ end
318
+ log "Received #{message.type}", message: message, level: :log
319
+
320
+ rescue UnknownComponent
321
+ log "Received #{message.type} with unknown component id '#{component_id}' and cannot infer type", message: message, level: :warning
322
+ # If the component is unknown, we must set q=undefined and s=nil for all items,
323
+ # while still acknowledge the message.
324
+ sS = message.attributes["sS"].map do |arg|
325
+ arg.dup.merge('q'=>'undefined','s'=>nil)
326
+ end
311
327
  end
328
+
312
329
  response = StatusResponse.new({
313
330
  "cId"=>component_id,
314
331
  "sTs"=>clock.to_s,
315
332
  "sS"=>sS,
316
333
  "mId" => options[:m_id]
317
334
  })
335
+
318
336
  set_nts_message_attributes response
319
337
  acknowledge message
320
338
  send_message response
@@ -538,7 +538,7 @@ module RSMP
538
538
 
539
539
  def switch_functional_position mode, timeout: nil, reverting: false, source:
540
540
  unless ['NormalControl','YellowFlash','Dark'].include? mode
541
- raise RSMP::MessageRejected.new "Invalid functional position '#{mode}', must be NormalControl, YellowFlash or Dark'"
541
+ raise RSMP::MessageRejected.new "Invalid functional position #{mode.inspect}, must be NormalControl, YellowFlash or Dark"
542
542
  end
543
543
  if reverting
544
544
  log "Reverting to functional position #{mode} after timeout", level: :info
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.20.4"
2
+ VERSION = "0.20.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.4
4
+ version: 0.20.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-10 00:00:00.000000000 Z
11
+ date: 2023-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async