Class: Sonos::Discovery
- Inherits:
-
Object
- Object
- Sonos::Discovery
- Defined in:
- lib/sonos/discovery.rb
Constant Summary collapse
- MULTICAST_ADDR =
'239.255.255.250'
- MULTICAST_PORT =
1900
- DEFAULT_TIMEOUT =
2
Instance Attribute Summary collapse
-
#default_ip ⇒ Object
readonly
Returns the value of attribute default_ip.
-
#first_device_ip ⇒ Object
readonly
Returns the value of attribute first_device_ip.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#discover ⇒ String
Look for Sonos devices on the network and return the first IP address found.
-
#initialize(timeout = DEFAULT_TIMEOUT, default_ip = nil) ⇒ Discovery
constructor
A new instance of Discovery.
-
#topology ⇒ Array
Find all of the Sonos devices on the network.
Constructor Details
#initialize(timeout = DEFAULT_TIMEOUT, default_ip = nil) ⇒ Discovery
Returns a new instance of Discovery.
25 26 27 28 29 |
# File 'lib/sonos/discovery.rb', line 25 def initialize(timeout = DEFAULT_TIMEOUT, default_ip = nil) @timeout = timeout @default_ip = default_ip initialize_socket end |
Instance Attribute Details
#default_ip ⇒ Object (readonly)
Returns the value of attribute default_ip.
23 24 25 |
# File 'lib/sonos/discovery.rb', line 23 def default_ip @default_ip end |
#first_device_ip ⇒ Object (readonly)
Returns the value of attribute first_device_ip.
22 23 24 |
# File 'lib/sonos/discovery.rb', line 22 def first_device_ip @first_device_ip end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
21 22 23 |
# File 'lib/sonos/discovery.rb', line 21 def timeout @timeout end |
Instance Method Details
#discover ⇒ String
Look for Sonos devices on the network and return the first IP address found
33 34 35 36 |
# File 'lib/sonos/discovery.rb', line 33 def discover @first_device_ip = listen_for_responses end |
#topology ⇒ Array
Find all of the Sonos devices on the network
40 41 42 43 44 45 46 47 48 |
# File 'lib/sonos/discovery.rb', line 40 def topology self.discover unless @first_device_ip return [] unless @first_device_ip doc = Nokogiri::XML(open("http://#{@first_device_ip}:#{Sonos::PORT}/status/topology")) doc.xpath('//ZonePlayers/ZonePlayer').map do |node| TopologyNode.new(node) end end |