lume/cmd/show.go

94 lines
2.7 KiB
Go
Raw Normal View History

2021-02-15 05:06:12 +00:00
package lumecmd
2021-02-17 02:20:18 +00:00
import (
2021-02-17 05:24:32 +00:00
"flag"
2021-02-17 02:20:18 +00:00
"fmt"
)
const Tabstop int = 2
2021-02-15 05:06:12 +00:00
2021-02-17 05:24:32 +00:00
func NewCmdShow() Command {
return Command{
Name: "show",
Func: ShowCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("show", flag.ExitOnError)
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
return fs
}(),
Use: "[--selector=<selector>]",
Short: "Show details about the lights",
}
}
2021-03-17 00:23:50 +00:00
func ShowCmd(ctx Context) (int, error) {
2021-02-17 02:20:18 +00:00
var indent int
2021-03-17 00:23:50 +00:00
c := ctx.Client
selector := ctx.Flags.String("selector")
2021-02-15 05:06:12 +00:00
lights, err := c.ListLights(selector)
if err != nil {
return ExitFailure, err
}
sortLights(lights)
for i, l := range lights {
2021-02-17 02:20:18 +00:00
indent = 0
2021-02-15 05:06:12 +00:00
fmt.Printf(
2021-04-04 23:34:52 +00:00
"%s Light ID: %s, %s, Power: %s\n",
ColorizeIndicator(l.Power),
2021-02-15 05:06:12 +00:00
l.Id,
connected(l.Connected),
2021-03-07 16:28:21 +00:00
ColorizePower(l.Power),
2021-02-15 05:06:12 +00:00
)
2021-04-04 23:34:52 +00:00
indent += Tabstop + 2
2021-02-17 02:20:18 +00:00
PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id)
PrintfWithIndent(indent, "UUID: %s\n", l.UUID)
PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id)
PrintfWithIndent(indent, "Group: %s, ID: %s\n", l.Group.Name, l.Group.Id)
PrintfWithIndent(indent, "Color: Hue: %.1f, Saturation: %.1f%%, Kelvin: %d\n",
2021-02-15 05:06:12 +00:00
*l.Color.H, *l.Color.S, *l.Color.K)
2021-02-17 02:20:18 +00:00
PrintfWithIndent(indent, "Brightness: %.1f%%\n", l.Brightness*100)
2021-02-15 05:06:12 +00:00
if l.Effect != "" {
2021-02-17 02:20:18 +00:00
PrintfWithIndent(indent, "Effect: %s\n", l.Effect)
2021-02-15 05:06:12 +00:00
}
2021-02-17 02:20:18 +00:00
PrintfWithIndent(indent, "Product: %s\n", l.Product.Name)
PrintfWithIndent(indent, "Capabilities: ")
2021-02-15 05:06:12 +00:00
fmt.Printf("Color: %s, ", YesNo(l.Product.Capabilities.HasColor))
fmt.Printf("Variable Color Temp: %s, ", YesNo(l.Product.Capabilities.HasVariableColorTemp))
fmt.Printf("IR: %s, ", YesNo(l.Product.Capabilities.HasIR))
fmt.Printf("Chain: %s, ", YesNo(l.Product.Capabilities.HasChain))
fmt.Printf("Multizone: %s, ", YesNo(l.Product.Capabilities.HasMultizone))
fmt.Printf("Min Kelvin: %.1f, ", l.Product.Capabilities.MinKelvin)
fmt.Printf("Max Kelvin: %.1f ", l.Product.Capabilities.MaxKelvin)
fmt.Println()
// List applicable selectors (most to least specific)
2021-02-17 02:20:18 +00:00
PrintfWithIndent(indent, "Selectors:\n")
indent += Tabstop
PrintfWithIndent(indent, "id:%s\n", l.Id)
PrintfWithIndent(indent, "label:%s\n", l.Label)
PrintfWithIndent(indent, "group_id:%s\n", l.Group.Id)
PrintfWithIndent(indent, "group:%s\n", l.Group.Name)
PrintfWithIndent(indent, "location_id:%s\n", l.Location.Id)
PrintfWithIndent(indent, "location:%s\n", l.Location.Name)
indent -= Tabstop
PrintfWithIndent(indent, "Last Seen: %s (%.1fs ago)\n", l.LastSeen, l.SecondsLastSeen)
if i < len(lights)-1 {
fmt.Println()
}
2021-02-15 05:06:12 +00:00
}
return ExitSuccess, nil
}
func connected(c bool) string {
if c {
return "Connected"
}
return "Disconnected"
}