Class: HackyHAL::DeviceControllers::YamahaAvReceiver

Inherits:
Base
  • Object
show all
Defined in:
lib/hacky_hal/device_controllers/yamaha_av_receiver.rb

Constant Summary collapse

CONTROL_PATH =
"/YamahaRemoteControl/ctrl"
CONTROL_PORT =
80

Instance Attribute Summary collapse

Attributes included from Options

#options

Instance Method Summary collapse

Methods inherited from Base

#log

Methods included from Options

#[]

Constructor Details

#initialize(options) ⇒ YamahaAvReceiver

Returns a new instance of YamahaAvReceiver.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 14

def initialize(options)
  super(options)
  ensure_option(:device_resolver)

  resolver = Util.object_from_hash(options[:device_resolver], DeviceResolvers)

  @host_uri = resolver.uri
  @host_uri.path = CONTROL_PATH
  @host_uri.port = CONTROL_PORT

  log("Host found at: #{@host_uri.to_s}", :debug)
end

Instance Attribute Details

#host_uriObject (readonly)

Returns the value of attribute host_uri.



12
13
14
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 12

def host_uri
  @host_uri
end

Instance Method Details

#basic_statusObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 27

def basic_status
  response = get_request('<Main_Zone><Basic_Status>GetParam</Basic_Status></Main_Zone>')

  basic_settings = response.elements["YAMAHA_AV/Main_Zone/Basic_Status"]
  power_settings = basic_settings.elements["Power_Control"]
  volume_settings = basic_settings.elements["Volume"]
  input_settings = basic_settings.elements["Input/Input_Sel_Item_Info"]
  sound_video_settings = basic_settings.elements["Sound_Video"]
  hdmi_settings = sound_video_settings.elements["HDMI"]
  tone_settings = sound_video_settings.elements["Tone"]
  dialog_adjust_settings = sound_video_settings.elements["Dialogue_Adjust"]
  surround_settings = basic_settings.elements["Surround/Program_Sel/Current"]

  hdmi_output_values = []
  hdmi_settings.elements.each("Output") do |output_element|
    if output_element.name =~ /^OUT_(\d)$/
      hdmi_output_values << {
        name: output_element.name,
        enabled: element_on?(output_element)
      }
    end
  end

  {
    power: element_on?(power_settings.elements["Power"]),
    sleep: element_on?(power_settings.elements["Sleep"]),
    mute: element_on?(volume_settings.elements["Mute"]),
    volume: element_volume_value(volume_settings.elements["Lvl/Val"]),
    subwoofer_trim: element_volume_value(volume_settings.elements["Subwoofer_Trim/Val"]),
    tone: {
      base: element_volume_value(tone_settings.elements["Bass/Val"]),
      treble: element_volume_value(tone_settings.elements["Treble/Val"])
    },
    input: {
      name: input_settings.elements["Param"].text,
      title: input_settings.elements["Title"].text
    },
    surround: {
      straight: element_on?(surround_settings.elements["Straight"]),
      enhancer: element_on?(surround_settings.elements["Enhancer"]),
      sound_program: surround_settings.elements["Sound_Program"].text,
      cinema_dsp_3d_mode: element_on?(basic_settings.elements["Surround/_3D_Cinema_DSP"])
    },
    hdmi: {
      standby_through: element_on?(hdmi_settings.elements["Standby_Through_Info"]),
      outputs: hdmi_output_values
    },
    party_mode: element_on?(basic_settings.elements["Party_Info"]),
    pure_direct_mode: element_on?(sound_video_settings.elements["Pure_Direct/Mode"]),
    adaptive_drc: element_on?(sound_video_settings.elements["Adaptive_DRC"]),
    dialog_adjust: {
      level: dialog_adjust_settings.elements["Dialogue_Lvl"].text.to_i,
      lift: dialog_adjust_settings.elements["Dialogue_Lift"].text.to_i
    }
  }
end

#hdmi_output(output_name) ⇒ Object



111
112
113
114
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 111

def hdmi_output(output_name)
  response = get_request(%|<System><Sound_Video><HDMI><Output><#{output_name}>GetParam</#{output_name}></Output></HDMI></Sound_Video></System>|)
  element_on?(response.elements["YAMAHA_AV/System/Sound_Video/HDMI/Output/#{output_name}"])
end

#inputObject



102
103
104
105
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 102

def input
  response = get_request('<Main_Zone><Input><Input_Sel>GetParam</Input_Sel></Input></Main_Zone>')
  response.elements["YAMAHA_AV/Main_Zone/Input/Input_Sel"].text
end

#inputsObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 84

def inputs
  response = get_request('<Main_Zone><Input><Input_Sel_Item>GetParam</Input_Sel_Item></Input></Main_Zone>')

  inputs = []
  response.elements["YAMAHA_AV/Main_Zone/Input/Input_Sel_Item"].each do |input_element|
    if input_element.name =~ /^Item_\d+$/
      inputs << {
        name: input_element.elements["Param"].text,
        title: input_element.elements["Title"].text,
        source_name: input_element.elements["Src_Name"].text,
        source_number: input_element.elements["Src_Number"].text.to_i,
      }
    end
  end

  inputs
end

#muteObject



141
142
143
144
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 141

def mute
  response = get_request("<Main_Zone><Volume><Mute>GetParam</Mute></Volume></Main_Zone>")
  element_on?(response.elements["YAMAHA_AV/Main_Zone/Volume/Mute"])
end

#powerObject



121
122
123
124
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 121

def power
  response = get_request("<Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone>")
  response.elements["YAMAHA_AV/Main_Zone/Power_Control/Power"].text == "On"
end

#set_hdmi_output(output_name, enabled) ⇒ Object



116
117
118
119
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 116

def set_hdmi_output(output_name, enabled)
  value = enabled ? "On" : "Off"
  put_request(%|<System><Sound_Video><HDMI><Output><#{output_name}>#{value}</#{output_name}></Output></HDMI></Sound_Video></System>|)
end

#set_input(input_name) ⇒ Object



107
108
109
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 107

def set_input(input_name)
  put_request(%|<Main_Zone><Input><Input_Sel>#{input_name}</Input_Sel></Input></Main_Zone>|)
end

#set_mute(value) ⇒ Object



146
147
148
149
150
151
152
153
154
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 146

def set_mute(value)
  value = case value
          when true then "On"
          when false then "Off"
          else value
          end

  put_request("<Main_Zone><Volume><Mute>#{value}</Mute></Volume></Main_Zone>")
end

#set_power(value) ⇒ Object



126
127
128
129
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 126

def set_power(value)
  value = value ? "On" : "Standby"
  put_request("<Main_Zone><Power_Control><Power>#{value}</Power></Power_Control></Main_Zone>")
end

#set_sound_program(program_name) ⇒ Object



161
162
163
164
165
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 161

def set_sound_program(program_name)
  response = put_request("<Main_Zone><Surround><Program_Sel><Current><Sound_Program>#{program_name}</Sound_Program></Current></Program_Sel></Surround></Main_Zone>")
  puts response
  # response.elements["YAMAHA_AV/Main_Zone/Surround/Program_Sel/Current/Sound_Program"].text
end

#set_volume(value) ⇒ Object



136
137
138
139
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 136

def set_volume(value)
  value = (value * 10.0).to_i.to_s
  response = put_request("<Main_Zone><Volume><Lvl><Val>#{value}</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></Main_Zone>")
end

#sound_programObject



156
157
158
159
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 156

def sound_program
  response = get_request("<Main_Zone><Surround><Program_Sel><Current>GetParam</Current></Program_Sel></Surround></Main_Zone>")
  response.elements["YAMAHA_AV/Main_Zone/Surround/Program_Sel/Current/Sound_Program"].text
end

#volumeObject



131
132
133
134
# File 'lib/hacky_hal/device_controllers/yamaha_av_receiver.rb', line 131

def volume
  response = get_request("<Main_Zone><Volume><Lvl>GetParam</Lvl></Volume></Main_Zone>")
  element_volume_value(response.elements["YAMAHA_AV/Main_Zone/Volume/Lvl/Val"])
end