rsmp 0.20.3 → 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: c6bfc3fc8bfbd9542d526cf49c4a5590672722ad628e12482458631d373f2a01
4
- data.tar.gz: 147774083ce7575ceab9bf4e5727b5a6838700b4daf6aa60b793921c193d2ebc
3
+ metadata.gz: 83d3f61fbf037ff67cf6cdec5eb9d043d75336f376ad5a9e2cf343631f962bd8
4
+ data.tar.gz: d185368c970e5174f66af74f95be3116793a19d7ce4a7a5496dd9c852c9a36fa
5
5
  SHA512:
6
- metadata.gz: dd734f66d888a71b8add0446d48dbbff7e10370eea8e852ed93a5aaa3e02de56bbdf0bbb92de2657b07c97e4b86bfa032af47848a6e163a6ddf09d05fd348249
7
- data.tar.gz: 5de9e95d0348ad2adff26d3d3b27f7b601cf7780442143142cc22fa2a6f658fff7bf1c5bf03af0c37b772012eb90f1e2cbb2c74282fe0f56b8db253165da443b
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.3)
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
48
  if build
49
- inferred = infer_component_type component_id
50
- component = inferred.new node: self, id: component_id
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
@@ -261,19 +266,31 @@ module RSMP
261
266
  end
262
267
 
263
268
  def process_command_request message
264
- log "Received #{message.type}", message: message, level: :log
265
269
  component_id = message.attributes["cId"]
266
- component = @site.find_component component_id
267
- commands = simplify_command_requests message.attributes["arg"]
268
- commands.each_pair do |command_code,arg|
269
- component.handle_command command_code,arg
270
- end
271
270
 
272
271
  rvs = message.attributes["arg"].map do |item|
273
272
  item = item.dup.merge('age'=>'recent')
274
273
  item.delete 'cO'
275
274
  item
276
275
  end
276
+
277
+ begin
278
+ component = @site.find_component component_id
279
+ commands = simplify_command_requests message.attributes["arg"]
280
+ commands.each_pair do |command_code,arg|
281
+ component.handle_command command_code,arg
282
+ end
283
+ log "Received #{message.type}", message: message, level: :log
284
+ rescue UnknownComponent
285
+ log "Received #{message.type} with unknown component id '#{component_id}' and cannot infer type", message: message, level: :warning
286
+ # If the component is unknown, we must set age=undefined for all items,
287
+ # while still acknowledge the message.
288
+ # See https://github.com/rsmp-nordic/rsmp_validator/issues/271
289
+ rvs.map do |item|
290
+ item['age'] = 'undefined'
291
+ end
292
+ end
293
+
277
294
  response = CommandResponse.new({
278
295
  "cId"=>component_id,
279
296
  "cTS"=>clock.to_s,
@@ -290,19 +307,32 @@ module RSMP
290
307
  end
291
308
 
292
309
  def process_status_request message, options={}
293
- component_id = message.attributes["cId"]
294
- component = @site.find_component component_id
295
- log "Received #{message.type}", message: message, level: :log
296
- sS = message.attributes["sS"].map do |arg|
297
- value, quality = component.get_status arg['sCI'], arg['n'], {sxl_version: sxl_version}
298
- { "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
299
327
  end
328
+
300
329
  response = StatusResponse.new({
301
330
  "cId"=>component_id,
302
331
  "sTs"=>clock.to_s,
303
332
  "sS"=>sS,
304
333
  "mId" => options[:m_id]
305
334
  })
335
+
306
336
  set_nts_message_attributes response
307
337
  acknowledge message
308
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.3"
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.3
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-04 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