2020-03-28 00:31:41 +00:00
|
|
|
package lumecmd
|
|
|
|
|
|
|
|
import (
|
2021-01-18 03:04:18 +00:00
|
|
|
lifx "git.kill0.net/chill9/lume"
|
2020-03-28 00:31:41 +00:00
|
|
|
)
|
|
|
|
|
2020-03-29 05:08:17 +00:00
|
|
|
func SetStateCmd(args CmdArgs) (int, error) {
|
2020-03-28 00:31:41 +00:00
|
|
|
c := args.Client
|
|
|
|
state := lifx.State{}
|
|
|
|
selector := args.Flags.String("selector")
|
|
|
|
|
|
|
|
power := args.Flags.String("power")
|
|
|
|
if power != "" {
|
|
|
|
state.Power = power
|
|
|
|
}
|
|
|
|
|
|
|
|
color := args.Flags.String("color")
|
|
|
|
if color != "" {
|
|
|
|
state.Color = lifx.NamedColor(color)
|
|
|
|
}
|
|
|
|
|
|
|
|
brightnessFlag := args.Flags.String("brightness")
|
|
|
|
if brightnessFlag != "" {
|
|
|
|
brightness := args.Flags.Float64("brightness")
|
|
|
|
state.Brightness = brightness
|
|
|
|
}
|
|
|
|
|
|
|
|
duration := args.Flags.Float64("duration")
|
|
|
|
state.Duration = duration
|
|
|
|
|
|
|
|
infraredFlag := args.Flags.String("infrared")
|
|
|
|
if infraredFlag != "" {
|
|
|
|
infrared := args.Flags.Float64("infrared")
|
|
|
|
state.Infrared = infrared
|
|
|
|
}
|
|
|
|
|
|
|
|
fast := args.Flags.Bool("fast")
|
|
|
|
state.Fast = fast
|
|
|
|
|
|
|
|
r, err := c.SetState(selector, state)
|
|
|
|
if err != nil {
|
2021-01-31 17:08:24 +00:00
|
|
|
return ExitFailure, err
|
2020-03-28 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !fast {
|
|
|
|
PrintResults(r.Results)
|
|
|
|
}
|
|
|
|
|
2021-01-18 03:08:13 +00:00
|
|
|
return ExitSuccess, nil
|
2020-03-28 00:31:41 +00:00
|
|
|
}
|