Ejemplo n.º 1
0
// Connect establishes a LIFX client and performs device discovery
func startDiscovery() (err error) {
	logger := log.New()

	if debug {
		logger.Level = log.DebugLevel
	}
	golifx.SetLogger(logger)

	if err := initClient(); err != nil {
		tick := time.Tick(2 * time.Second)
		done := make(chan bool)
		select {
		case <-done:
		case <-tick:
			err = initClient()
			if err == nil {
				done <- true
			}
		}
	}

	client.SetDiscoveryInterval(30 * time.Second)

	if timeout > 0 {
		client.SetTimeout(time.Duration(timeout))
	}

	log.Info(`Initiated LIFX client`)

	return nil
}
Ejemplo n.º 2
0
// Connect establishes a LIFX client and performs device discovery
func Connect(cfg *config.Config) {
	logger := log.New()

	if cfg.Debug != nil && *cfg.Debug {
		logger.Level = log.DebugLevel
	}
	golifx.SetLogger(logger)

	if err := initClient(); err != nil {
		tick := time.Tick(2 * time.Second)
		done := make(closer)
		select {
		case <-done:
		case <-tick:
			err = initClient()
			if err == nil {
				close(done)
			}
		}
	}

	if err := client.SetDiscoveryInterval(30 * time.Second); err != nil {
		log.WithField(`error`, err).Fatal(`Failed setting lifx discovery interval`)
	}
	if cfg.LIFX.Timeout != nil && *cfg.LIFX.Timeout > 0 {
		client.SetTimeout(time.Duration(*cfg.LIFX.Timeout))
	}
	log.Info(`Initiated LIFX client`)
}
Ejemplo n.º 3
0
// Connect establishes a LIFX client and performs device discovery
func Connect(cfg config.Config) {
	logger := log.New()

	if cfg.Debug != nil && *cfg.Debug {
		logger.Level = log.DebugLevel
	}
	golifx.SetLogger(logger)

	if err := initClient(); err != nil {
		tick := time.Tick(2 * time.Second)
		done := make(chan bool)
		select {
		case <-done:
		case <-tick:
			err = initClient()
			if err == nil {
				done <- true
			}
		}
	}

	client.SetDiscoveryInterval(30 * time.Second)
	if cfg.LIFX.Timeout != nil && *cfg.LIFX.Timeout > 0 {
		client.SetTimeout(time.Duration(*cfg.LIFX.Timeout))
	}
	log.Info(`Initiated LIFX client`)
}
Ejemplo n.º 4
0
func init() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	golifx.SetLogger(logger)

	app.PersistentFlags().DurationVarP(&flagTimeout, `timeout`, `t`, common.DefaultTimeout, `timeout for all operations`)
	app.PersistentFlags().StringVarP(&flagLogLevel, `log-level`, `L`, `info`, `log level, one of: [debug,info,warn,error]`)

	app.AddCommand(cmdLight)
	app.AddCommand(cmdGroup)
	app.AddCommand(cmdGenerateBashComp)
	app.AddCommand(cmdGenerateDocs)
	app.AddCommand(cmdVersion)
	app.AddCommand(cmdWatch)
}