Class: TellStickR::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/tellstickr/device.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, protocol, model) ⇒ Device

Returns a new instance of Device.



7
8
9
10
11
12
# File 'lib/tellstickr/device.rb', line 7

def initialize(id, name, protocol, model)
  @id = id
  @name = name
  @protocol = protocol
  @model = model
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/tellstickr/device.rb', line 5

def id
  @id
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/tellstickr/device.rb', line 5

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/tellstickr/device.rb', line 5

def name
  @name
end

#protocolObject (readonly)

Returns the value of attribute protocol.



5
6
7
# File 'lib/tellstickr/device.rb', line 5

def protocol
  @protocol
end

Class Method Details

.discoverObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tellstickr/device.rb', line 38

def self.discover
  nr_of_devices = TellStickR::Core.tdGetNumberOfDevices
  i = 0
  devices = []
  while(i < nr_of_devices) do
    id = TellStickR::Core.tdGetDeviceId(i)
    name = TellStickR::Core.tdGetName(i)
    protocol = TellStickR::Core.tdGetProtocol(i)
    model = TellStickR::Core.tdGetModel(i)
    devices << Device.new(id, name, protocol, model)
    i += 1
  end
  devices
end

Instance Method Details

#bellObject

Raises:



32
33
34
35
36
# File 'lib/tellstickr/device.rb', line 32

def bell
  result = TellStickR::Core.tdBell(@id)
  return true if result == TellStickR::Core::TELLSTICK_SUCCESS
  raise TellStickR::Error.new(result)
end

#learnObject

Raises:



14
15
16
17
18
# File 'lib/tellstickr/device.rb', line 14

def learn
  result = TellStickR::Core.tdLearn(@id)
  return true if result == TellStickR::Core::TELLSTICK_SUCCESS
  raise TellStickR::Error.new(result)
end

#offObject

Raises:



26
27
28
29
30
# File 'lib/tellstickr/device.rb', line 26

def off
  result = TellStickR::Core.tdTurnOff(@id)
  return true if result == TellStickR::Core::TELLSTICK_SUCCESS
  raise TellStickR::Error.new(result)
end

#onObject

Raises:



20
21
22
23
24
# File 'lib/tellstickr/device.rb', line 20

def on
  result = TellStickR::Core.tdTurnOn(@id)
  return true if result == TellStickR::Core::TELLSTICK_SUCCESS
  raise TellStickR::Error.new(result)
end