Module: Huebot::CLI::Runner

Defined in:
lib/huebot/cli/runner.rb

Class Method Summary collapse

Class Method Details

.check(bridge, sources, opts) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/huebot/cli/runner.rb', line 29

def self.check(bridge, sources, opts)
  device_mapper = Huebot::DeviceMapper.new(bridge, opts.inputs)
  programs = sources.map { |src|
    Huebot::Compiler.build src
  }
  found_errors, found_warnings, missing_devices = Helpers.check! programs, device_mapper, $stdout
  return (found_errors || found_warnings || missing_devices) ? 1 : 0
rescue ::Huebot::Error => e
  $stderr.puts "#{e.class.name}: #{e.message}"
  return 1
end

.clear_ipObject



59
60
61
62
63
64
65
66
# File 'lib/huebot/cli/runner.rb', line 59

def self.clear_ip
  config = Huebot::Config.new
  config["ip"] = nil
  0
rescue ::Huebot::Error => e
  $stderr.puts "#{e.class.name}: #{e.message}"
  return 1
end

.get_state(bridge, inputs) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/huebot/cli/runner.rb', line 41

def self.get_state(bridge, inputs)
  device_mapper = Huebot::DeviceMapper.new(bridge, inputs)
  device_mapper.each do |device|
    puts device.name
    puts "  #{device.get_state}"
  end
  0
end

.ls(bridge) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/huebot/cli/runner.rb', line 4

def self.ls(bridge)
  puts "Lights\n" + bridge.lights.map { |l| "  #{l.id}: #{l.name}" }.join("\n") + \
    "\nGroups\n" + bridge.groups.map { |g| "  #{g.id}: #{g.name}" }.join("\n")
  return 0
rescue ::Huebot::Error => e
  $stderr.puts "#{e.class.name}: #{e.message}"
  return 1
end

.run(bridge, sources, opts) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/huebot/cli/runner.rb', line 13

def self.run(bridge, sources, opts)
  device_mapper = Huebot::DeviceMapper.new(bridge, opts.inputs)
  programs = sources.map { |src|
    Huebot::Compiler.build src
  }
  found_errors, _found_warnings, missing_devices = Helpers.check! programs, device_mapper, $stderr
  return 1 if found_errors || missing_devices

  bot = Huebot::Bot.new(device_mapper)
  programs.each { |prog| bot.execute prog }
  return 0
rescue ::Huebot::Error => e
  $stderr.puts "#{e.class.name}: #{e.message}"
  return 1
end

.set_ipObject



50
51
52
53
54
55
56
57
# File 'lib/huebot/cli/runner.rb', line 50

def self.set_ip
  config = Huebot::Config.new
  config["ip"] = ip
  0
rescue ::Huebot::Error => e
  $stderr.puts "#{e.class.name}: #{e.message}"
  return 1
end

.unregisterObject



68
69
70
71
72
73
74
75
# File 'lib/huebot/cli/runner.rb', line 68

def self.unregister
  config = Huebot::Config.new
  config.clear
  0
rescue ::Huebot::Error => e
  $stderr.puts "#{e.class.name}: #{e.message}"
  return 1
end