add set-white subcommand

This commit is contained in:
Ryan Cavicchioni 2020-03-22 14:06:14 -05:00
parent 7c27d173f4
commit 7773883688
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -35,6 +35,7 @@ func main() {
selector *string selector *string
r *lifx.Response r *lifx.Response
err error err error
color lifx.HSBKColor
) )
accessToken := os.Getenv("LIFX_ACCESS_TOKEN") accessToken := os.Getenv("LIFX_ACCESS_TOKEN")
@ -53,6 +54,13 @@ func main() {
setStateCommand.String("infrared", "", "Set the infrared brightness") setStateCommand.String("infrared", "", "Set the infrared brightness")
setStateCommand.Bool("fast", false, "Execute fast (no response)") 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() flag.Parse()
command = flag.Arg(0) command = flag.Arg(0)
@ -98,6 +106,43 @@ func main() {
state.Fast, err = strconv.ParseBool(fast) 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) r, err = c.SetState(*selector, state)
} }