Store the configuration in an instance variable

This commit is contained in:
Paul van Tilburg 2014-11-29 17:37:42 +01:00
parent b676d6d3e6
commit cbb9258b39
1 changed files with 13 additions and 5 deletions

View File

@ -146,22 +146,30 @@ Groups
getgrp [name/ID] get the settings of the lights in a group getgrp [name/ID] get the settings of the lights in a group
setgrp [name/ID], [update] set the settings of the lights in a group setgrp [name/ID], [update] set the settings of the lights in a group
Events
events shows the list of all events
event [name/ID] execute an event
Scenes
scenes shows the list of all scenes
scenes [name/ID] activate an scene
EOT EOT
end end
# Option parsing # Option parsing
options = {:config_dir => "config"} @options = {:config_dir => "config"}
opt_parser = OptionParser.new do |opts| opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: huec [options]" opts.banner = "Usage: huec [options]"
opts.separator "" opts.separator ""
opts.on("-c", "--config-dir [CONFDIR] ", opts.on("-c", "--config-dir [CONFDIR] ",
"set an alternative configuration directory") do |cd| "set an alternative configuration directory") do |cd|
options[:config_dir] = cd @options[:config_dir] = cd
end end
opts.on("--hue-debug", "log hue bridge communication output") do opts.on("--hue-debug", "log hue bridge communication output") do
options[:hue_debug] = true @options[:hue_debug] = true
end end
opts.on_tail("-h", "--help", "show this help message") do opts.on_tail("-h", "--help", "show this help message") do
@ -183,12 +191,12 @@ rescue OptionParser::InvalidOption => e
end end
puts "Starting huec #{Hued::VERSION}..." puts "Starting huec #{Hued::VERSION}..."
bridge_cfg = YAML.load_file(File.join(options[:config_dir], "bridge.yml")) bridge_cfg = YAML.load_file(File.join(@options[:config_dir], "bridge.yml"))
Huey.configure do |cfg| Huey.configure do |cfg|
cfg.hue_ip = bridge_cfg["ip"] cfg.hue_ip = bridge_cfg["ip"]
cfg.uuid = bridge_cfg["user"] cfg.uuid = bridge_cfg["user"]
end end
Huey.logger.level = options[:hue_debug] ? Logger::DEBUG : Logger::FATAL Huey.logger.level = @options[:hue_debug] ? Logger::DEBUG : Logger::FATAL
puts "Configured bridge connection" puts "Configured bridge connection"
puts "Discovering lights..." puts "Discovering lights..."