From 1ef900c44c232d4b9d36fe1423dca62977b85a47 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Thu, 25 Mar 2021 09:46:58 -0500 Subject: [PATCH] Add breathe effect command --- cmd/breathe.go | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ cmd/main.go | 1 + 2 files changed, 107 insertions(+) create mode 100644 cmd/breathe.go diff --git a/cmd/breathe.go b/cmd/breathe.go new file mode 100644 index 0000000..5c7b1a7 --- /dev/null +++ b/cmd/breathe.go @@ -0,0 +1,106 @@ +package lumecmd + +import ( + "flag" + + "git.kill0.net/chill9/lifx-go" +) + +func NewCmdBreathe() Command { + return Command{ + Name: "breathe", + Func: BreatheCmd, + Flags: func() *flag.FlagSet { + fs := flag.NewFlagSet("breathe", flag.ExitOnError) + + selector := fs.String("selector", defaultSelector, "Set the selector") + fs.StringVar(selector, "s", defaultSelector, "Set the selector") + + fs.String("color", defaultColor, "The color to use for the breathe effect") + + fs.String("from-color", defaultColor, "The color to start the effect from") + + fs.Float64("period", lifx.DefaultBreathePeriod, "The time in seconds for one cycle of the effect") + + fs.Float64("cycles", lifx.DefaultBreatheCycles, "The number of times to repeat the effect") + + fs.Bool("persist", lifx.DefaultBreathePersist, "If false set the light back to its previous value when effect ends, if true leave the last effect color") + + fs.Bool("power-on", lifx.DefaultBreathePowerOn, "If true, turn the bulb on if it is not already on") + + fs.Float64("peak", lifx.DefaultBreathePeak, "Defines where in a period the target color is at its maximum (min: 0.0, max: 1.0)") + + fs.String("format", defaultOutputFormat, "Set the output format") + + return fs + }(), + Use: "[--selector ] --color [--from-color ] [--period ] [--cycles ] [--persist ] [--power-on] [--peak ]", + Short: "The breathe effect", + } +} + +func BreatheCmd(ctx Context) (int, error) { + var p Printer + + c := ctx.Client + breathe := lifx.NewBreathe() + selector := ctx.Flags.String("selector") + format := ctx.Flags.String("format") + + if format == "" && ctx.Config.OutputFormat != "" { + format = ctx.Config.OutputFormat + } + + color := ctx.Flags.String("color") + if color != "" { + breathe.Color = lifx.NamedColor(color) + } + + from_color := ctx.Flags.String("from-color") + if from_color != "" { + breathe.FromColor = lifx.NamedColor(from_color) + } + + periodFlag := ctx.Flags.String("period") + if periodFlag != "" { + period := ctx.Flags.Float64("period") + breathe.Period = period + } + + cyclesFlag := ctx.Flags.String("cycles") + if cyclesFlag != "" { + cycles := ctx.Flags.Float64("cycles") + breathe.Cycles = cycles + } + + persist := ctx.Flags.Bool("persist") + breathe.Persist = persist + + power_on := ctx.Flags.Bool("power-on") + breathe.PowerOn = power_on + + peakFlag := ctx.Flags.String("peak") + if peakFlag != "" { + peak := ctx.Flags.Float64("peak") + breathe.Peak = peak + } + + if color == "" { + printCmdHelp(ctx.Name) + return ExitFailure, nil + } + + if err := breathe.Valid(); err != nil { + return ExitFailure, err + } + + r, err := c.Breathe(selector, breathe) + if err != nil { + return ExitFailure, err + } + + p = NewPrinter(format) + p.Results(r.Results) + + return ExitSuccess, nil +} diff --git a/cmd/main.go b/cmd/main.go index 9668561..978453d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -19,6 +19,7 @@ func init() { RegisterCommand(NewCmdShow()) RegisterCommand(NewCmdToggle()) RegisterCommand(NewCmdVersion()) + RegisterCommand(NewCmdBreathe()) } var Version string