class DenonAvr::Receiver

Constants

ALBUM_COVERS_URL
APPCOMMAND_URL

General URLs

COMMAND_FAV_SRC_URL
COMMAND_FAV_SRC_Z2_URL
COMMAND_FAV_SRC_Z3_URL
COMMAND_MUTE_OFF_URL
COMMAND_MUTE_OFF_Z2_URL
COMMAND_MUTE_OFF_Z3_URL
COMMAND_MUTE_ON_URL
COMMAND_MUTE_ON_Z2_URL
COMMAND_MUTE_ON_Z3_URL
COMMAND_NETAUDIO_POST_URL
COMMAND_PAUSE
COMMAND_PLAY
COMMAND_POWER_ON_URL
COMMAND_POWER_ON_Z2_URL
COMMAND_POWER_ON_Z3_URL
COMMAND_POWER_STANDBY_URL
COMMAND_POWER_STANDBY_Z2_URL
COMMAND_POWER_STANDBY_Z3_URL
COMMAND_SEL_SM_URL
COMMAND_SEL_SRC_URL
COMMAND_SEL_SRC_Z2_URL
COMMAND_SEL_SRC_Z3_URL
COMMAND_SET_VOLUME_URL
COMMAND_SET_VOLUME_Z2_URL
COMMAND_SET_VOLUME_Z3_URL
COMMAND_SET_ZST_URL
COMMAND_VOLUME_DOWN_URL
COMMAND_VOLUME_DOWN_Z2_URL
COMMAND_VOLUME_DOWN_Z3_URL
COMMAND_VOLUME_UP_URL
COMMAND_VOLUME_UP_Z2_URL
COMMAND_VOLUME_UP_Z3_URL
DEVICEINFO_URL
HDTUNERSTATUS_URL
MAINZONE_URL
MAINZONE_Z2_URL
MAINZONE_Z3_URL
MAIN_URLS
NETAUDIOSTATUS_URL
NO_ZONES
POWER_OFF
POWER_ON
POWER_STANDBY
ReceiverURLs
SOURCE_MAPPING
STATE_OFF
STATE_ON
STATE_PAUSED
STATE_PLAYING
STATIC_ALBUM_URL

Image URLs

STATUS_LITE_URL
STATUS_LITE_Z2_URL
STATUS_LITE_Z3_URL
STATUS_URL

Main Zone URLs

STATUS_Z2_URL

Zone 2 URLs

STATUS_Z3_URL

Zone 3 URLs

TUNERSTATUS_URL
ZONE2
ZONE2_URLS
ZONE2_ZONE3
ZONE3
ZONE3_URLS

Attributes

host[R]
main_zone[R]
source_list[R]
zone2[R]
zone3[R]
zones[R]

Public Class Methods

app_command(host:, commands: []) click to toggle source
# File lib/denon_avr/receiver.rb, line 27
def self.app_command(host:, commands: [])
  payload = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |xml|
    xml.tx do
      commands.each_with_index do |command, index|
        xml.cmd(command, id: index+1)
      end
    end
  end

  send_command(host: host, path: APPCOMMAND_URL, body: payload.to_xml, method: :post)
end
new(host:, name: nil, show_all_inputs: false, timeout: 2.0, add_zones: NO_ZONES) click to toggle source
# File lib/denon_avr/receiver.rb, line 39
def initialize(host:, name: nil, show_all_inputs: false, timeout: 2.0, add_zones: NO_ZONES)
  @host = host
  get_source_mapping
  setup_zones(add_zones: add_zones)
end
send_command(host:, path:, body: nil, method: :get) click to toggle source
# File lib/denon_avr/receiver.rb, line 14
def self.send_command(host:, path:, body: nil, method: :get)
  return false unless [:get, :post].include?(method)

  uri = URI("http://#{host}:8080#{path}")

  res = HTTParty.send(method, uri, {
    body: body,
    headers: {
      'Content-Type': 'application/xml'
    }
  })
end

Public Instance Methods

all_off() click to toggle source
# File lib/denon_avr/receiver.rb, line 45
def all_off
  @zones.each do |zone|
    zone.power_off
  end
end
app_command(commands = []) click to toggle source
# File lib/denon_avr/receiver.rb, line 55
def app_command(commands = [])
  commands = [commands] if commands.is_a? String
  self.class.app_command(host: @host, commands: commands)
end
inspect() click to toggle source
# File lib/denon_avr/receiver.rb, line 60
def inspect
  instance_variables_to_list = [:@host, :@zones]
  instance_vars_string = instance_variables_to_list.map { |v|
    "#{v.to_s}=#{instance_variable_get(v).inspect}"
  }.join(', ')
  "\#<#{self.class}:#{self.object_id.to_s(16).rjust(2, '0')} #{instance_vars_string}>"
end
send_command(path:, body: nil, method: :get) click to toggle source
# File lib/denon_avr/receiver.rb, line 51
def send_command(path:, body: nil, method: :get)
  self.class.send_command(host: @host, path: path, body: body, method: method)
end

Private Instance Methods

get_source_mapping() click to toggle source
# File lib/denon_avr/receiver.rb, line 70
def get_source_mapping
  res = app_command('GetRenameSource')
  raw_source_list = res.parsed_response&.fetch('rx', nil)&.fetch('cmd', nil)
    &.fetch('functionrename', nil)&.fetch('list', nil)
  # This consolidates the results into a hash that can actually be used
  # for source lookups, using the internal source name where applicable.
  @source_list = Hash[raw_source_list.map { |source|
    key = SOURCE_MAPPING[source['name']] || source['name']
    [key, source['rename'].strip]
  }].invert
end
setup_zones(add_zones: NO_ZONES) click to toggle source
# File lib/denon_avr/receiver.rb, line 82
def setup_zones(add_zones: NO_ZONES)
  @main_zone = Zone.new(receiver: self)
  @zones = [@main_zone]
  add_zones.each do |zone_name|
    zone_added = Zone.new(receiver: self, name: zone_name)
    @zone2 = zone_added if zone_name == 'Zone2'
    @zone3 = zone_added if zone_name == 'Zone3'
    @zones << zone_added
  end
end