Compare commits

..

No commits in common. "7d8e5f8b92344a313a587317677f9c63b64cfcfd" and "fe40294f52c87200e8935f6b1fd7c48ee5d9a7f8" have entirely different histories.

3 changed files with 12 additions and 105 deletions

View File

@ -5,9 +5,6 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"time"
fc "github.com/fatih/color"
) )
import ( import (
@ -36,7 +33,7 @@ func main() {
var ( var (
command string command string
selector *string selector *string
//r *lifx.Response r *lifx.Response
err error err error
color lifx.HSBKColor color lifx.HSBKColor
) )
@ -68,29 +65,14 @@ func main() {
command = flag.Arg(0) command = flag.Arg(0)
fmt.Println(command)
fmt.Println(*selector)
c := lifx.NewClient(accessToken) c := lifx.NewClient(accessToken)
switch command { switch command {
case "toggle": case "toggle":
_, err = c.Toggle(*selector, 1) r, err = c.Toggle(*selector, 1)
case "ls":
lights, err := c.ListLights(*selector)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("total %d\n", len(lights))
for _, l := range lights {
fmt.Printf(
"%*s %*s %*s %*s %*s %-*s\n",
IdLen(lights), l.Id,
LocationLen(lights), l.Location.Name,
GroupLen(lights), l.Group.Name,
LabelLen(lights), l.Label,
LastSeenLen(lights), l.LastSeen.Local().Format(time.RFC3339),
PowerLen(lights), PowerColor(l.Power),
)
}
case "set-state": case "set-state":
setStateCommand.Parse(os.Args[4:]) setStateCommand.Parse(os.Args[4:])
@ -124,7 +106,7 @@ func main() {
state.Fast, err = strconv.ParseBool(fast) state.Fast, err = strconv.ParseBool(fast)
} }
_, err = c.SetState(*selector, state) r, err = c.SetState(*selector, state)
case "set-white": case "set-white":
setWhiteCommand.Parse(os.Args[4:]) setWhiteCommand.Parse(os.Args[4:])
@ -161,79 +143,9 @@ func main() {
state.Fast, err = strconv.ParseBool(fast) state.Fast, err = strconv.ParseBool(fast)
} }
_, err = c.SetState(*selector, state) r, err = c.SetState(*selector, state)
if err != nil { }
fmt.Println(r)
fmt.Println(err) fmt.Println(err)
os.Exit(1)
}
}
}
func IdLen(lights []lifx.Light) int {
var length int
for _, l := range lights {
if len(l.Id) > length {
length = len(l.Id)
}
}
return length
}
func LocationLen(lights []lifx.Light) int {
var length int
for _, l := range lights {
if len(l.Location.Name) > length {
length = len(l.Location.Name)
}
}
return length
}
func GroupLen(lights []lifx.Light) int {
var length int
for _, l := range lights {
if len(l.Group.Name) > length {
length = len(l.Group.Name)
}
}
return length
}
func LabelLen(lights []lifx.Light) int {
var length int
for _, l := range lights {
if len(l.Label) > length {
length = len(l.Label)
}
}
return length
}
func LastSeenLen(lights []lifx.Light) int {
var length int
for _, l := range lights {
if len(l.LastSeen.Local().Format(time.RFC3339)) > length {
length = len(l.LastSeen.Local().Format(time.RFC3339))
}
}
return length
}
func PowerLen(lights []lifx.Light) int {
var length int
for _, l := range lights {
if len(l.Power) > length {
length = len(l.Power)
}
}
return length
}
func PowerColor(s string) string {
color := fc.New(fc.FgRed).SprintFunc()
if s == "on" {
color = fc.New(fc.FgGreen).SprintFunc()
}
return color(s)
} }

View File

@ -78,10 +78,6 @@ var (
) )
func NewRGBColor(r, g, b uint8) (*RGBColor, error) { func NewRGBColor(r, g, b uint8) (*RGBColor, error) {
if (r < 0 || r > 255) && (g < 0 || r > 255) && (b < 0 || b > 255) {
return nil, errors.New("values must be between 0-255")
}
return &RGBColor{R: r, G: g, B: b}, nil return &RGBColor{R: r, G: g, B: b}, nil
} }

View File

@ -4,7 +4,6 @@ import (
//"crypto/tls" //"crypto/tls"
"encoding/json" "encoding/json"
"net/http" "net/http"
"time"
) )
const ( const (
@ -50,7 +49,7 @@ type (
Group Selector `json:"group"` Group Selector `json:"group"`
Location Selector `json:"location"` Location Selector `json:"location"`
Product Product `json:"product"` Product Product `json:"product"`
LastSeen time.Time `json:"last_seen"` LastSeen string `json:"last_seen"`
SecondsLastSeen float64 `json:"seconds_last_seen"` SecondsLastSeen float64 `json:"seconds_last_seen"`
} }