Class: Lightwavez::Controller

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

Overview

you will need to create one of these: c = Lightwavez::Controller.new

Instance Method Summary collapse

Constructor Details

#initialize(address = nil, port = 9760, mapping_file = "") ⇒ Controller

if addres is missing, it will use discover to find it if mapping_file is missing, it will load ‘mapping.yml’ from the running folder



13
14
15
16
17
18
19
20
21
22
# File 'lib/lightwavez.rb', line 13

def initialize(address = nil, port = 9760, mapping_file = "")
  @mapping = {}

  mapping_file = File.join(Dir.pwd, 'mapping.yml') if mapping_file == ""
  if File.exists? mapping_file
    @mapping = YAML.load_file(mapping_file)
  end

  @client = Lightwavez::Client.new(address, port)
end

Instance Method Details

#registerObject

registers the client with the link. The first time this runs the lights on the link will flash and the button needs to be pressed to authorise the client calling this again after initial registration will return the IP address of the link



27
28
29
# File 'lib/lightwavez.rb', line 27

def register
  @client.discover
end

#send(room, device, operation, params = {}) ⇒ Object

sends a command to the link. room is the name of the room based on mapping  device is the name of the device based on mapping. pass ” if the command doesn’t need it (all_off and mood) operation can be :on, :off, :all_off, :dim, :last_dim, :mood params is used for dim (1-32) and mood (mood name based on mapping)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lightwavez.rb', line 36

def send(room, device, operation, params = {})
  room_id = get_room(room)['id']
  device_id = get_device(room, device)

  puts "Room: #{room_id}, Device: #{device_id}"

  pa = nil
  if operation == :mood
    pa = get_mood(room, params)

    puts "Mood: #{params}"
  else
    pa = params
  end

  cmd = @client.get_command(room_id, device_id, operation, pa)

  puts "Sending command #{cmd}"

  @client.send(cmd)
end