module Sonos::Endpoint::Rendering

Constants

RENDERING_ENDPOINT
RENDERING_XMLNS

Public Instance Methods

bass() click to toggle source

Get the current bass EQ. @return [Fixnum] the base EQ from -10 to 10

# File lib/sonos/endpoint/rendering.rb, line 22
def bass
  response = send_rendering_message('GetBass')
  response.body[:get_bass_response][:current_bass].to_i
end
bass=(value) click to toggle source

Set the bass EQ from -10 to 10. @param [Fixnum] the desired bass EQ from -10 to 10

# File lib/sonos/endpoint/rendering.rb, line 29
def bass=(value)
  parse_response send_rendering_message('SetBass', value)
end
loudness() click to toggle source

Get the loudness compenstation setting @return [Boolean] true if the speaker has loudness on and false if it is not

# File lib/sonos/endpoint/rendering.rb, line 65
def loudness
  response = send_rendering_message('GetLoudness')
  response.body[:get_loudness_response][:current_loudness] == '1'
end
loudness=(value) click to toggle source

Set the loudness compenstation setting @param [Boolean] if the speaker has loudness on or not

# File lib/sonos/endpoint/rendering.rb, line 72
def loudness=(value)
  parse_response send_rendering_message('SetLoudness', value ? 1 : 0)
end
mute() click to toggle source

Mute the speaker

# File lib/sonos/endpoint/rendering.rb, line 47
def mute
  parse_response set_mute(true)
end
muted?() click to toggle source

Is the speaker muted? @return [Boolean] true if the speaker is muted and false if it is not

# File lib/sonos/endpoint/rendering.rb, line 58
def muted?
  response = send_rendering_message('GetMute')
  response.body[:get_mute_response][:current_mute] == '1'
end
treble() click to toggle source

Get the current treble EQ. @return [Fixnum] the treble EQ from -10 to 10

# File lib/sonos/endpoint/rendering.rb, line 35
def treble
  response = send_rendering_message('GetTreble')
  response.body[:get_treble_response][:current_treble].to_i
end
treble=(value) click to toggle source

Set the treble EQ from -10 to 10. @param [Fixnum] the desired treble EQ from -10 to 10

# File lib/sonos/endpoint/rendering.rb, line 42
def treble=(value)
  parse_response send_rendering_message('SetTreble', value)
end
unmute() click to toggle source

Unmute the speaker

# File lib/sonos/endpoint/rendering.rb, line 52
def unmute
  parse_response set_mute(false)
end
volume() click to toggle source

Get the current volume. Fixed volume speakers will always return 100. @return [Fixnum] the volume from 0 to 100

# File lib/sonos/endpoint/rendering.rb, line 8
def volume
  response = send_rendering_message('GetVolume')
  response.body[:get_volume_response][:current_volume].to_i
end
volume=(value) click to toggle source

Set the volume from 0 to 100. Trying to set the volume of a fixed volume speaker will fail. @param [Fixnum] the desired volume from 0 to 100

# File lib/sonos/endpoint/rendering.rb, line 16
def volume=(value)
  parse_response send_rendering_message('SetVolume', value)
end

Private Instance Methods

rendering_client() click to toggle source
# File lib/sonos/endpoint/rendering.rb, line 84
def rendering_client
  @rendering_client ||= Savon.client endpoint: "http://#{self.ip}:#{Sonos::PORT}#{RENDERING_ENDPOINT}", namespace: Sonos::NAMESPACE, log: Sonos.logging_enabled
end
send_rendering_message(name, value = nil) click to toggle source
# File lib/sonos/endpoint/rendering.rb, line 88
def send_rendering_message(name, value = nil)
  action = "#{RENDERING_XMLNS}##{name}"
  message = %Q{<u:#{name} xmlns:u="#{RENDERING_XMLNS}"><InstanceID>0</InstanceID><Channel>Master</Channel>}

  if value
    attribute = name.sub('Set', '')
    message += %Q{<Desired#{attribute}>#{value}</Desired#{attribute}></u:#{name}>}
  else
    message += %Q{</u:#{name}>}
  end

  rendering_client.call(name, soap_action: action, message: message)
end
set_mute(value) click to toggle source

Sets the speaker’s mute @param [Boolean] if the speaker is muted or not

# File lib/sonos/endpoint/rendering.rb, line 80
def set_mute(value)
  send_rendering_message('SetMute', value ? 1 : 0)
end