Class: Hue::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/hue/cli.rb

Instance Method Summary collapse

Instance Method Details

#add(thing) ⇒ Object


13
14
15
16
17
18
# File 'lib/hue/cli.rb', line 13

def add(thing)
  case thing
  when 'lights'
    client.add_lights
  end
end

#all(state = 'on') ⇒ Object


35
36
37
38
39
40
41
# File 'lib/hue/cli.rb', line 35

def all(state = 'on')
  body = options.dup
  body[:on] = state == 'on'
  client.lights.each do |light|
    puts light.set_state body
  end
end

#group(id, state = nil) ⇒ Object


86
87
88
89
90
91
92
93
# File 'lib/hue/cli.rb', line 86

def group(id, state = nil)
  group = client.group(id)
  puts group.name

  body = options.dup
  body[:on] = (state == 'on' || !(state == 'off'))
  puts group.set_state(body) if body.length > 0
end

#groupsObject


65
66
67
68
69
70
71
72
# File 'lib/hue/cli.rb', line 65

def groups
  client.groups.each do |group|
    puts group.id.to_s.ljust(6) + group.name
    group.lights.each do |light|
      puts " -> " + light.id.to_s.ljust(6) + light.name
    end
  end
end

#light(id, state = nil) ⇒ Object


55
56
57
58
59
60
61
62
# File 'lib/hue/cli.rb', line 55

def light(id, state = nil)
  light = client.light(id)
  puts light.name

  body = options.dup
  body[:on] = (state == 'on' || !(state == 'off'))
  puts light.set_state(body) if body.length > 0
end

#lightsObject


6
7
8
9
10
# File 'lib/hue/cli.rb', line 6

def lights
  client.lights.each do |light|
    puts light.id.to_s.ljust(6) + light.name
  end
end