Class: Bravtroller::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/bravtroller/remote.rb

Defined Under Namespace

Classes: IrccClientFactory

Constant Summary collapse

IRCC_URN =
'urn:schemas-sony-com:service:IRCC:1'
LIST_METHODS_PARAMS =
{
    method: 'getRemoteControllerInfo',
    params: [],
    id: 10,
    version: '1.0'
}

Instance Method Summary collapse

Constructor Details

#initialize(host, ircc_client_factory = IrccClientFactory.new(host)) ⇒ Remote

Returns a new instance of Remote.



47
48
49
50
# File 'lib/bravtroller/remote.rb', line 47

def initialize(host, ircc_client_factory = IrccClientFactory.new(host))
  @bravia_client = Bravtroller::Client.new(host)
  @ircc_client_factory  = ircc_client_factory
end

Instance Method Details

#buttonsObject



75
76
77
# File 'lib/bravtroller/remote.rb', line 75

def buttons
  ircc_codes.keys
end

#power_on(hw_addr = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bravtroller/remote.rb', line 52

def power_on(hw_addr = nil)
  hw_addr = @bravia_client.hw_addr if hw_addr.nil?

  if hw_addr.nil?
    raise RuntimeError.new "Couldn't determine hw_addr for TV host from ARP. " <<
      'Specify it manually in the call to power_on.'
  end

  addr = ['<broadcast>', 9]
  sock = UDPSocket.new
  sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
  packet_data = (([255] * 6) + (hw_addr.split(':').map(&:hex) * 16)).pack('C*')
  sock.send(packet_data, 0, addr[0], addr[1])

  true
end

#press_button(button_key) ⇒ Object



69
70
71
72
73
# File 'lib/bravtroller/remote.rb', line 69

def press_button(button_key)
  raise RuntimeError.new "Undefined button: #{button_key}" if ircc_codes[button_key].nil?

  @ircc_client_factory.create.X_SendIRCC IRCCCode: ircc_codes[button_key]
end