Compare commits
No commits in common. "dc4159550c8f3b30eae9da556182bf94433189fd" and "6a5e6d07531f75ec500dc18b05ea98d602aaee9e" have entirely different histories.
dc4159550c
...
6a5e6d0753
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
|||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
go build -o lume ./cmd
|
go build -o lifx ./cmd
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
45
cmd/lifx.go
Normal file
45
cmd/lifx.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"git.kill0.net/chill9/go-lifx"
|
||||||
|
"os"
|
||||||
|
//"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
accessToken := os.Getenv("LIFX_ACCESS_TOKEN")
|
||||||
|
if accessToken == "" {
|
||||||
|
fmt.Println("LIFX_ACCESS_TOKEN is undefined")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
color1 := lifx.RGBColor{R: 235, G: 191, B: 255}
|
||||||
|
color2 := lifx.NewHSBKColor()
|
||||||
|
color2.H = 27
|
||||||
|
color2.S = 1
|
||||||
|
color2.B = 0.39
|
||||||
|
fmt.Println(color1.Hex())
|
||||||
|
fmt.Println(color1.ColorString())
|
||||||
|
fmt.Println(color2.ColorString())
|
||||||
|
s := lifx.State{Power: "on", Color: color2}
|
||||||
|
c := lifx.NewClient(accessToken)
|
||||||
|
selector := "group:Office"
|
||||||
|
r, err := c.FastSetState(selector, s)
|
||||||
|
/*
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
s.Color = "white"
|
||||||
|
res, _ := c.SetState(selector, s)
|
||||||
|
fmt.Println(res)
|
||||||
|
//c.SetState("all", &lifx.State{Power: "on", Color: "green"})
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
c.FastPowerOff(selector)
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
c.FastPowerOn(selector)
|
||||||
|
//c.PowerOff("all")
|
||||||
|
*/
|
||||||
|
fmt.Println(err)
|
||||||
|
fmt.Println(r)
|
||||||
|
r, err = c.Toggle(selector, 10.0)
|
||||||
|
fmt.Println(err)
|
||||||
|
fmt.Println(r)
|
||||||
|
}
|
106
cmd/lume.go
106
cmd/lume.go
@ -1,106 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.kill0.net/chill9/go-lifx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Flags struct {
|
|
||||||
*flag.FlagSet
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Flags) String(name string) string {
|
|
||||||
return f.FlagSet.Lookup(name).Value.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Flags) Float64(name string) float64 {
|
|
||||||
val, _ := strconv.ParseFloat(f.String(name), 64)
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Flags) Bool(name string) bool {
|
|
||||||
val, _ := strconv.ParseBool(f.String(name))
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
var (
|
|
||||||
command string
|
|
||||||
selector *string
|
|
||||||
r *lifx.Response
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
accessToken := os.Getenv("LIFX_ACCESS_TOKEN")
|
|
||||||
if accessToken == "" {
|
|
||||||
fmt.Println("LIFX_ACCESS_TOKEN is undefined")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
selector = flag.String("selector", "all", "LIFX selector")
|
|
||||||
|
|
||||||
setStateCommand := flag.NewFlagSet("set-state", flag.ExitOnError)
|
|
||||||
setStateCommand.String("power", "", "Set the power state (on/off)")
|
|
||||||
setStateCommand.String("color", "", "Set the color (HSBK)")
|
|
||||||
setStateCommand.String("brightness", "", "Set the brightness")
|
|
||||||
setStateCommand.String("duration", "", "Set the duration")
|
|
||||||
setStateCommand.String("infrared", "", "Set the infrared brightness")
|
|
||||||
setStateCommand.Bool("fast", false, "Execute fast (no response)")
|
|
||||||
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
command = flag.Arg(0)
|
|
||||||
|
|
||||||
fmt.Println(command)
|
|
||||||
fmt.Println(*selector)
|
|
||||||
|
|
||||||
c := lifx.NewClient(accessToken)
|
|
||||||
|
|
||||||
switch command {
|
|
||||||
case "toggle":
|
|
||||||
r, err = c.Toggle(*selector, 1)
|
|
||||||
case "set-state":
|
|
||||||
setStateCommand.Parse(os.Args[4:])
|
|
||||||
|
|
||||||
fs := Flags{setStateCommand}
|
|
||||||
|
|
||||||
power := fs.String("power")
|
|
||||||
color := fs.String("color")
|
|
||||||
brightness := fs.String("brightness")
|
|
||||||
duration := fs.String("duration")
|
|
||||||
infrared := fs.String("infrared")
|
|
||||||
fast := fs.String("fast")
|
|
||||||
|
|
||||||
state := lifx.State{}
|
|
||||||
|
|
||||||
if power != "" {
|
|
||||||
state.Power = power
|
|
||||||
}
|
|
||||||
if color != "" {
|
|
||||||
state.Color = lifx.NamedColor(color)
|
|
||||||
}
|
|
||||||
if brightness != "" {
|
|
||||||
state.Brightness, err = strconv.ParseFloat(brightness, 64)
|
|
||||||
}
|
|
||||||
if duration != "" {
|
|
||||||
state.Duration, err = strconv.ParseFloat(duration, 64)
|
|
||||||
}
|
|
||||||
if infrared != "" {
|
|
||||||
state.Infrared, err = strconv.ParseFloat(infrared, 64)
|
|
||||||
}
|
|
||||||
if fast != "" {
|
|
||||||
state.Fast, err = strconv.ParseBool(fast)
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err = c.SetState(*selector, state)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(r)
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user