Compare commits

...

2 Commits

Author SHA1 Message Date
becc179184
move light struct 2020-02-29 15:58:20 -06:00
37d3179662
move client structs 2020-02-29 15:57:32 -06:00
4 changed files with 52 additions and 32 deletions

View File

@ -10,6 +10,23 @@ import (
"net/http"
)
type (
Client struct {
accessToken string
Client *http.Client
}
Results struct {
Results []Result `json:results`
}
Result struct {
ID string `json:"id"`
Label string `json:"label"`
Status Status `json:"status"`
}
)
var errorMap = map[int]error{
http.StatusNotFound: errors.New("Selector did not match any lights"),
http.StatusUnauthorized: errors.New("Bad access token"),

View File

@ -4,23 +4,42 @@ import (
"fmt"
"git.kill0.net/chill9/go-lifx"
"os"
"time"
//"time"
)
func main() {
apiToken := os.Getenv("LIFX_API_TOKEN")
if apiToken == "" {
fmt.Println("LIFX_API_TOKEN is undefined")
accessToken := os.Getenv("LIFX_ACCESS_TOKEN")
if accessToken == "" {
fmt.Println("LIFX_ACCESS_TOKEN is undefined")
os.Exit(1)
}
s := &lifx.State{Power: "on", Color: "blue"}
c := lifx.NewSession(apiToken)
c.SetState("group:Office", s)
time.Sleep(10 * time.Second)
s.Color = "white"
res, _ := c.SetState("group:Office", s)
fmt.Println(res)
//c.SetState("all", &lifx.State{Power: "on", Color: "green"})
time.Sleep(10)
//c.PowerOff("all")
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)
}

View File

@ -8,6 +8,8 @@ import (
)
type (
Status string
State struct {
Power string `json:"power,omitempty"`
Color Color `json:"color,omitempty"`

View File

@ -2,7 +2,6 @@ package lifx
import (
"fmt"
"net/http"
"strings"
)
@ -13,23 +12,6 @@ type (
)
type (
Status string
Client struct {
accessToken string
Client *http.Client
}
Results struct {
Results []Result `json:results`
}
Result struct {
ID string `json:"id"`
Label string `json:"label"`
Status Status `json:"status"`
}
RGBColor struct {
R, G, B uint8
}