Sha256: 433ce757f33a4a03b33586c52fe826493bcfcf14db50a147d5e4bf786f77854c

Contents?: true

Size: 836 Bytes

Versions: 6

Compression:

Stored size: 836 Bytes

Contents

module Sonos::Endpoint::Device
  DEVICE_ENDPOINT = '/DeviceProperties/Control'
  DEVICE_XMLNS = 'urn:schemas-upnp-org:service:DeviceProperties:1'

  # Turn the white status light on or off
  # @param [Boolean] True to turn on the light. False to turn off the light.
  def status_light_enabled=(enabled)
    send_device_message('SetLEDState', enabled ? 'On' : 'Off')
  end

private

  def device_client
    @device_client ||= Savon.client endpoint: "http://#{self.ip}:#{Sonos::PORT}#{DEVICE_ENDPOINT}", namespace: Sonos::NAMESPACE
  end

  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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sonos-0.3.3 lib/sonos/endpoint/device.rb
sonos-0.3.2 lib/sonos/endpoint/device.rb
sonos-0.3.1 lib/sonos/endpoint/device.rb
sonos-0.3.0 lib/sonos/endpoint/device.rb
sonos-0.2.1 lib/sonos/endpoint/device.rb
sonos-0.2.0 lib/sonos/endpoint/device.rb