2020-03-28 18:18:30 +00:00
|
|
|
package lumecmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
|
2021-01-18 03:04:18 +00:00
|
|
|
lifx "git.kill0.net/chill9/lume"
|
2020-03-28 18:18:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-02-01 01:40:27 +00:00
|
|
|
RegisterCommand("set-white", Command{
|
|
|
|
Func: SetWhiteCmd,
|
|
|
|
Flags: func() *flag.FlagSet {
|
|
|
|
fs := flag.NewFlagSet("set-white", flag.ExitOnError)
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
selector := fs.String("selector", "all", "the selector")
|
|
|
|
fs.StringVar(selector, "s", "all", "the selector")
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
power := fs.String("power", defaultPower, "power state")
|
|
|
|
fs.StringVar(power, "p", defaultPower, "power state")
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
kelvin := fs.String("kelvin", defaultWhiteKelvin, "kelvin level")
|
|
|
|
fs.StringVar(kelvin, "k", defaultWhiteKelvin, "kelvin level")
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
name := fs.String("name", defaultWhiteName, "named white level")
|
|
|
|
fs.StringVar(name, "n", defaultWhiteName, "named white level")
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
brightness := fs.String("brightness", defaultBrightness, "brightness state")
|
|
|
|
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
duration := fs.Float64("duration", defaultDuration, "duration state")
|
|
|
|
fs.Float64Var(duration, "d", defaultDuration, "duration state")
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
infrared := fs.String("infrared", defaultInfrared, "infrared state")
|
|
|
|
fs.StringVar(infrared, "i", defaultInfrared, "infrared state")
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
fast := fs.Bool("fast", defaultFast, "fast state")
|
|
|
|
fs.BoolVar(fast, "f", defaultFast, "fast state")
|
2020-03-28 18:18:30 +00:00
|
|
|
|
2021-02-01 01:40:27 +00:00
|
|
|
return fs
|
|
|
|
}(),
|
2020-08-07 23:44:36 +00:00
|
|
|
Use: "[--selector <selector>] [--power (on|off)] [--kelvin <kelvin>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--infrared] [--fast]",
|
2020-08-08 03:09:40 +00:00
|
|
|
Short: "Set the white level",
|
2020-03-28 18:18:30 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-29 05:08:17 +00:00
|
|
|
func SetWhiteCmd(args CmdArgs) (int, error) {
|
2020-03-28 18:18:30 +00:00
|
|
|
c := args.Client
|
|
|
|
state := lifx.State{}
|
|
|
|
selector := args.Flags.String("selector")
|
|
|
|
|
|
|
|
power := args.Flags.String("power")
|
|
|
|
if power != "" {
|
|
|
|
state.Power = power
|
|
|
|
}
|
|
|
|
|
|
|
|
kelvinFlag := args.Flags.String("kelvin")
|
|
|
|
if kelvinFlag != "" {
|
|
|
|
kelvin := args.Flags.Int16("kelvin")
|
|
|
|
color, err := lifx.NewWhite(kelvin)
|
|
|
|
if err != nil {
|
2021-01-31 17:08:24 +00:00
|
|
|
return ExitFailure, err
|
2020-03-28 18:18:30 +00:00
|
|
|
}
|
|
|
|
state.Color = color
|
|
|
|
}
|
|
|
|
|
|
|
|
name := args.Flags.String("name")
|
|
|
|
if name != "" {
|
|
|
|
name := args.Flags.String("name")
|
|
|
|
color, err := lifx.NewWhiteString(name)
|
|
|
|
if err != nil {
|
2021-01-31 17:08:24 +00:00
|
|
|
return ExitFailure, err
|
2020-03-28 18:18:30 +00:00
|
|
|
}
|
|
|
|
state.Color = 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 18:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !fast {
|
|
|
|
PrintResults(r.Results)
|
|
|
|
}
|
|
|
|
|
2021-01-18 03:08:13 +00:00
|
|
|
return ExitSuccess, nil
|
2020-03-28 18:18:30 +00:00
|
|
|
}
|