#!/usr/bin/env ruby # encoding: UTF-8 # # hued - Philips (friends of) hue policy daemon # # Hued is Copyright © 2011 Paul van Tilburg # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. require "hued" # Option parsing options = {} opt_parser = OptionParser.new do |opts| opts.banner = "Usage: hued [options]" opts.separator "" opts.on("--[no-]blink", "blink lights when discovered on startup") do |bl| options[:blink] = bl end opts.on("-c", "--config-dir [CONFDIR] ", "set an alternative configuration directory") do |cd| options[:config_dir] = cd end opts.on("-d", "--debug", "log debug output") do options[:debug] = true end opts.on("--hue-debug", "log hue bridge communication output") do options[:hue_debug] = true end opts.on_tail("-h", "--help", "show this help message") do puts opts exit end opts.on_tail("-v", "--version", "show version") do puts "Hued version #{Hued::VERSION}" exit end end begin opt_parser.parse! rescue OptionParser::InvalidOption => e warn e.message abort opt_parser.to_s end # Create the main engine Hued.configure(options) engine = Hued::Engine.new # Handle signals Signal.trap("INT") { EM.stop } Signal.trap("TERM") { EM.stop } # Write sync to stdout $stdout.sync = true # Trigger rule execution and light status refreshing periodically EM.run do EM.add_periodic_timer(10) { engine.reload; engine.execute } EM.add_periodic_timer(120) { engine.refresh! } end engine.shutdown