module Sonos::Endpoint::Device

Constants

DEVICE_ENDPOINT
DEVICE_XMLNS

Public Instance Methods

create_pair_with(right) click to toggle source

Create a stereo pair of two speakers. This does not take into account which type of players support bonding. Currently only S1/S3 (play:1/play:3) support this but future players may gain this abbility too. The speaker on which this method is called is assumed to be the left speaker of the pair. @param right [Sonos::Device::Speaker] Right speaker

# File lib/sonos/endpoint/device.rb, line 25
def create_pair_with(right)
  left = self.uid.sub!('uuid:', '')
  right = right.uid.sub!('uuid:', '')
  parse_response = send_bonding_message('AddBondedZones', "#{left}:LF,LF;#{right}:RF,RF")
end
separate_pair() click to toggle source
# File lib/sonos/endpoint/device.rb, line 31
def separate_pair
  parse_response = send_bonding_message('RemoveBondedZones', '')
end
status_light_enabled=(enabled) click to toggle source

Turn the white status light on or off @param [Boolean] True to turn on the light. False to turn off the light.

# File lib/sonos/endpoint/device.rb, line 15
def status_light_enabled=(enabled)
  parse_response send_device_message('SetLEDState', enabled ? 'On' : 'Off')
end
status_light_enabled?() click to toggle source

Retrieve the status light state; true if on, false otherwise.

# File lib/sonos/endpoint/device.rb, line 6
def status_light_enabled?
  response = send_device_message('GetLEDState', '')
  body = response.body[:get_led_state_response]

  body[:current_led_state] == 'On' ? true : false
end

Private Instance Methods

device_client() click to toggle source
# File lib/sonos/endpoint/device.rb, line 37
def device_client
  @device_client ||= Savon.client endpoint: "http://#{self.ip}:#{Sonos::PORT}#{DEVICE_ENDPOINT}", namespace: Sonos::NAMESPACE, log: Sonos.logging_enabled
end
send_bonding_message(name, value) click to toggle source
# File lib/sonos/endpoint/device.rb, line 48
def send_bonding_message(name, value)
  action = "#{DEVICE_XMLNS}##{name}"
  message = %Q{<u:#{name} xmlns:u="#{DEVICE_XMLNS}"><ChannelMapSet>#{value}</ChannelMapSet></u:#{name}>}
  device_client.call(name, soap_action: action, message: message)
end
send_device_message(name, value) click to toggle source
# File lib/sonos/endpoint/device.rb, line 41
def send_device_message(name, value)
  action = "#{DEVICE_XMLNS}##{name}"
  attribute = name.sub('Set', '')
  message = %Q{<u:#{name} xmlns:u="#{DEVICE_XMLNS}"><Desired#{attribute}>#{value}</Desired#{attribute}>}
  device_client.call(name, soap_action: action, message: message)
end