onkyo_eiscp_ruby 2.1.4 → 2.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48590d7db6afad487744a9ba5d783b58c3af158c3ba73adb441c23d9f493ea3b
4
- data.tar.gz: d2c0e99074b3ae9dd9f5b32db926262236c4aea4f640f41fae01e2e13ad04c30
3
+ metadata.gz: d35b01beb072ac7058ef54920b734aff8d4d098ecc702eb9edd21ee818ad7ca0
4
+ data.tar.gz: f1112ac834d03f1dea2e50aeed301ac8f0e802b55b00b0f317d7802515ffa84e
5
5
  SHA512:
6
- metadata.gz: e218b06b48938a41c7ce8301c8a7d697a8bae0f04eb9ba6214324ebeb1e115e769516230b48a884c535ffa191e129553d169a22eebce9ec923a8c428efc5ab56
7
- data.tar.gz: 21113da05277c8e18dc6cfa64a4704f3495f606d6fed666f0100ed4ff457989baa09ac0252e96a403881cd0283d5cd8d919bc811c38a63ef019254fd55fdccc6
6
+ metadata.gz: f3a50446a0df21efd8dc6b2397daeb0cf791a997e7f0c27bb9d01c98b9e08fdc99cd68176b464882b29acc64a5f9cbe0748da690da51269f10f8f41f3d75dfc7
7
+ data.tar.gz: 65bafa48d392b8578435f006de9b27b8e58b9f16d7ccd7e2d527b38f23c0e2db187204c79f9c2dfe121021907735b51f73b82cef8fb82789ac362b5c3fec228f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.1.5
data/bin/mock_receiver.rb CHANGED
@@ -11,7 +11,8 @@ module EISCP
11
11
  #
12
12
  class MockReceiver
13
13
  DISCOVERY_IP = '255.255.255.255'
14
- ONKYO_DISCOVERY_RESPONSE = Message.new('ECN', "TX-NR609/60128/DX/14DAE9E967C8\x19\r\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
14
+ ONKYO_DISCOVERY_RESPONSE = Message.new('ECN',
15
+ "TX-NR609/60128/DX/14DAE9E967C8\x19\r\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
15
16
 
16
17
  # Create/start the server object.
17
18
 
data/bin/onkyo.rb CHANGED
@@ -115,8 +115,8 @@ class Options
115
115
  puts ' Value - Description>'
116
116
  puts "\n"
117
117
  command_hash[:values].each do |_value, attr_hash|
118
- puts " '#{EISCP::Dictionary.command_value_to_value_name(command, _value)}' - "\
119
- " #{attr_hash[:description]}"
118
+ puts " '#{EISCP::Dictionary.command_value_to_value_name(command, _value)}' - "\
119
+ " #{attr_hash[:description]}"
120
120
  end
121
121
  puts "\n"
122
122
  end
data/lib/eiscp.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Library for controlling Onkyo receivers over TCP/IP.
4
4
  #
5
5
  module EISCP
6
- VERSION = '2.1.4'
6
+ VERSION = '2.1.5'
7
7
  end
8
8
 
9
9
  require_relative './eiscp/receiver'
@@ -14,14 +14,12 @@ module EISCP
14
14
  extend DictionaryHelpers
15
15
 
16
16
  class << self
17
- attr_reader :zones
18
- attr_reader :modelsets
19
- attr_reader :commands
17
+ attr_reader :zones, :modelsets, :commands
20
18
  end
21
19
 
22
20
  DEFAULT_ZONE = 'main'
23
21
  @yaml_file_path = File.join(__dir__, '../../eiscp-commands.yaml')
24
- @commands = YAML.load(File.read(@yaml_file_path))
22
+ @commands = YAML.safe_load(File.read(@yaml_file_path), permitted_classes: [Symbol])
25
23
  @modelsets = @commands[:modelsets]
26
24
  @commands.delete(:modelsets)
27
25
  @zones = @commands.map { |k, _| k }
@@ -32,11 +30,12 @@ module EISCP
32
30
  command = command[0]
33
31
  @commands[zone][command][:values].each do |value|
34
32
  value = value[0]
35
- if value.is_a? Array
33
+ case value
34
+ when Array
36
35
  @additions << [zone, command, value, create_range_commands(zone, command, value)]
37
- elsif value.match(/^(B|T){xx}$/)
36
+ when /^(B|T){xx}$/
38
37
  @additions << [zone, command, value, create_treble_bass_commands(zone, command, value)]
39
- elsif value.match(/^{xx}$/)
38
+ when /^{xx}$/
40
39
  @additions << [zone, command, value, create_balance_commands(zone, command, value)]
41
40
  else
42
41
  next
@@ -37,8 +37,8 @@ module EISCP
37
37
  tmp.merge!((value[0] + v.to_s) =>
38
38
  {
39
39
  name: value[0].downcase + v,
40
- description: @commands[zone][command][:values][value[0] + '{xx}'][:description].gsub(/\(.*[\]|\)]$/, v),
41
- models: @commands[zone][command][:values][value[0] + '{xx}'][:models]
40
+ description: @commands[zone][command][:values]["#{value[0]}{xx}"][:description].gsub(/\(.*[\]|)]$/, v),
41
+ models: @commands[zone][command][:values]["#{value[0]}{xx}"][:models]
42
42
  })
43
43
  end
44
44
  tmp
@@ -52,7 +52,7 @@ module EISCP
52
52
  tmp.merge!(v.to_s =>
53
53
  {
54
54
  name: v.downcase,
55
- description: @commands[zone][command][:values]['{xx}'][:description].gsub(/\(.*[\]|\)]$/, v),
55
+ description: @commands[zone][command][:values]['{xx}'][:description].gsub(/\(.*[\]|)]$/, v),
56
56
  models: @commands[zone][command][:values]['{xx}'][:models]
57
57
  })
58
58
  end
@@ -52,9 +52,9 @@ module EISCP
52
52
  def command_value_to_value_name(command, value)
53
53
  zone = zone_from_command(command)
54
54
  command_value = @commands[zone][command][:values][value][:name]
55
- if command_value.class == String
55
+ if command_value.instance_of?(String)
56
56
  command_value
57
- elsif command_value.class == Array
57
+ elsif command_value.instance_of?(Array)
58
58
  command_value.first
59
59
  end
60
60
  rescue StandardError
@@ -65,13 +65,13 @@ module EISCP
65
65
  def command_value_name_to_value(command, value_name)
66
66
  zone = zone_from_command(command)
67
67
  @commands[zone][command][:values].each_pair do |k, v|
68
- if v[:name].class == String
68
+ if v[:name].instance_of?(String)
69
69
  return k if v[:name] == value_name.to_s
70
- elsif v[:name].class == Array
70
+ elsif v[:name].instance_of?(Array)
71
71
  return k if v[:name].first == value_name.to_s
72
72
  end
73
73
  end
74
- return nil
74
+ nil
75
75
  rescue StandardError
76
76
  nil
77
77
  end
data/lib/eiscp/message.rb CHANGED
@@ -15,6 +15,7 @@ module EISCP
15
15
  class Message
16
16
  # EISCP header
17
17
  attr_accessor :header
18
+
18
19
  # ISCP "magic" indicates the start of an eISCP message.
19
20
  MAGIC = 'ISCP'
20
21
  # eISCP header size, fixed length.
@@ -17,19 +17,24 @@ module EISCP
17
17
  unit_type: msg.unit_type,
18
18
  start: msg.start
19
19
  )
20
- packet.header = {
20
+ packet.header = create_header(array)
21
+ packet
22
+ end
23
+
24
+ def self.create_header(array)
25
+ {
21
26
  magic: array[0],
22
27
  header_size: array[1],
23
28
  data_size: array[2],
24
29
  version: array[3],
25
30
  reserved: array[4]
26
31
  }
27
- packet
28
32
  end
29
33
 
30
34
  def self.validate(packet)
31
35
  packet.header.header_size.size == packet.command.size
32
36
  end
37
+
33
38
  end
34
39
 
35
40
  class EISCPParserException < RuntimeError; end
@@ -6,7 +6,7 @@ module EISCP
6
6
  #
7
7
  module ISCPParser
8
8
  # Regexp for parsing ISCP messages
9
- REGEX = /(?<start>!)?(?<unit_type>(\d|x))?(?<command>[A-Z]{3})\s?(?<value>.*?)(?<terminator>[[:cntrl:]]*$)/.freeze
9
+ REGEX = /(?<start>!)?(?<unit_type>(?:\d|x))?(?<command>[A-Z]{3})\s?(?<value>.*?)(?<terminator>[[:cntrl:]]*$)/
10
10
  def self.parse(string)
11
11
  match = string.match(REGEX)
12
12
 
@@ -17,9 +17,7 @@ module EISCP
17
17
  hash.delete_if { |_, v| v.nil? || v == '' }
18
18
 
19
19
  # Convert keys to symbols
20
- hash = hash.each_with_object({}) do |(k, v), memo|
21
- memo[k.to_sym] = v
22
- end
20
+ hash = hash.transform_keys(&:to_sym)
23
21
 
24
22
  Message.new(**hash)
25
23
  end
@@ -133,12 +133,11 @@ module EISCP
133
133
  # Sends an EISCP::Message object or string on the network
134
134
  #
135
135
  def send(eiscp)
136
- if (@socket.nil? || @socket.closed?) then
137
- connect
138
- end
139
- if eiscp.is_a? EISCP::Message
136
+ connect if @socket.nil? || @socket.closed?
137
+ case eiscp
138
+ when EISCP::Message
140
139
  @socket.puts(eiscp.to_eiscp)
141
- elsif eiscp.is_a? String
140
+ when String
142
141
  @socket.puts eiscp
143
142
  end
144
143
  end
@@ -148,8 +147,7 @@ module EISCP
148
147
  def recv
149
148
  data = String.new
150
149
  data << @socket.gets until data.match(/\r\n$/)
151
- message = Parser.parse(data)
152
- message
150
+ Parser.parse(data)
153
151
  end
154
152
 
155
153
  # Sends an EISCP::Message object or string on the network and returns recieved data string.
@@ -190,13 +188,7 @@ module EISCP
190
188
  info[:values].each do |value, _|
191
189
  next unless value == 'QSTN'
192
190
 
193
- send(Parser.parse(command + 'QSTN'))
194
- # If we send any faster we risk making the stereo drop replies.
195
- # A dropped reply is not necessarily indicative of the
196
- # receiver's failure to receive the command and change state
197
- # accordingly. In this case, we're only making queries, so we do
198
- # want to capture every reply.
199
- sleep DEFAULT_TIMEOUT
191
+ send_recv(Parser.parse("#{command}QSTN"))
200
192
  end
201
193
  end
202
194
  end
@@ -16,7 +16,7 @@ module EISCP
16
16
  Dictionary.commands[zone].each do |command, _values|
17
17
  command_name = Dictionary.command_to_name(command).to_s.gsub(/-/, '_')
18
18
  define_method(command_name) do |v|
19
- instance_exec Parser.parse(command_name.gsub(/_/, '-') + ' ' + v), &block
19
+ instance_exec Parser.parse("#{command_name.gsub(/_/, '-')} #{v}"), &block
20
20
  end
21
21
  rescue StandardError => e
22
22
  puts e
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../lib/eiscp/dictionary.rb'
3
+ require_relative '../lib/eiscp/dictionary'
4
4
  require 'minitest/autorun'
5
5
 
6
6
  class TestDictionary < MiniTest::Test
data/test/tc_message.rb CHANGED
@@ -8,7 +8,10 @@ class TestMessage < MiniTest::Test
8
8
  DISCOVERY_STRING = DISCOVERY_PACKET.to_eiscp
9
9
 
10
10
  def test_create_discovery_iscp_message
11
- assert_equal(EISCP::Message.new(command: 'ECN', value: 'QSTN', terminator: "\r\n", unit_type: 'x', start: '!').to_iscp, '!xECNQSTN')
11
+ assert_equal(
12
+ EISCP::Message.new(command: 'ECN', value: 'QSTN', terminator: "\r\n", unit_type: 'x',
13
+ start: '!').to_iscp, '!xECNQSTN'
14
+ )
12
15
  end
13
16
 
14
17
  def test_create_messages
data/test/tc_parser.rb CHANGED
@@ -29,6 +29,6 @@ class TestParser < MiniTest::Test
29
29
  end
30
30
 
31
31
  def test_return_nil_for_fake_human_readable
32
- assert_equal(EISCP::Parser.parse('fake-command value'), nil)
32
+ assert_nil(EISCP::Parser.parse('fake-command value'))
33
33
  end
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onkyo_eiscp_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Rodrigues
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "\n Control Onkyo receivers over the network.Use the provided binary
14
14
  or\n require the library for use in your scripts.\n "