From 77738836880f185c129ce3e493d1db776da9bc04 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sun, 22 Mar 2020 14:06:14 -0500 Subject: [PATCH] add set-white subcommand --- cmd/lume.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/cmd/lume.go b/cmd/lume.go index 53eef41..6ed098c 100644 --- a/cmd/lume.go +++ b/cmd/lume.go @@ -35,6 +35,7 @@ func main() { selector *string r *lifx.Response err error + color lifx.HSBKColor ) accessToken := os.Getenv("LIFX_ACCESS_TOKEN") @@ -53,6 +54,13 @@ func main() { setStateCommand.String("infrared", "", "Set the infrared brightness") setStateCommand.Bool("fast", false, "Execute fast (no response)") + setWhiteCommand := flag.NewFlagSet("set-white", flag.ExitOnError) + setWhiteCommand.String("name", "", "Set the kelvin by name") + setWhiteCommand.String("kelvin", "", "Set the kelvin by value") + setWhiteCommand.String("brightness", "", "Set the brightness") + setWhiteCommand.String("duration", "", "Set the duration") + setWhiteCommand.Bool("fast", false, "Execute fast (no response)") + flag.Parse() command = flag.Arg(0) @@ -98,6 +106,43 @@ func main() { state.Fast, err = strconv.ParseBool(fast) } + r, err = c.SetState(*selector, state) + case "set-white": + setWhiteCommand.Parse(os.Args[4:]) + + fs := Flags{setWhiteCommand} + + name := fs.String("name") + kelvin := fs.String("kelvin") + brightness := fs.String("brightness") + duration := fs.String("duration") + fast := fs.String("fast") + + state := lifx.State{} + + if name != "" { + color, err := lifx.NewWhiteString(name) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + state.Color = color + } + if kelvin != "" { + k, _ := strconv.ParseInt(kelvin, 10, 16) + color, err = lifx.NewWhite(int16(k)) + state.Color = color + } + if brightness != "" { + state.Brightness, err = strconv.ParseFloat(brightness, 64) + } + if duration != "" { + state.Duration, err = strconv.ParseFloat(duration, 64) + } + if fast != "" { + state.Fast, err = strconv.ParseBool(fast) + } + r, err = c.SetState(*selector, state) }