Compare commits
No commits in common. "becc1791848b18f743dc3a48ace3c78dbf2b8210" and "1c99d42224e04e0eba2fb3f99970f246937b2a3b" have entirely different histories.
becc179184
...
1c99d42224
17
client.go
17
client.go
@ -10,23 +10,6 @@ import (
|
|||||||
"net/http"
|
"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{
|
var errorMap = map[int]error{
|
||||||
http.StatusNotFound: errors.New("Selector did not match any lights"),
|
http.StatusNotFound: errors.New("Selector did not match any lights"),
|
||||||
http.StatusUnauthorized: errors.New("Bad access token"),
|
http.StatusUnauthorized: errors.New("Bad access token"),
|
||||||
|
47
cmd/lifx.go
47
cmd/lifx.go
@ -4,42 +4,23 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"git.kill0.net/chill9/go-lifx"
|
"git.kill0.net/chill9/go-lifx"
|
||||||
"os"
|
"os"
|
||||||
//"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
accessToken := os.Getenv("LIFX_ACCESS_TOKEN")
|
apiToken := os.Getenv("LIFX_API_TOKEN")
|
||||||
if accessToken == "" {
|
if apiToken == "" {
|
||||||
fmt.Println("LIFX_ACCESS_TOKEN is undefined")
|
fmt.Println("LIFX_API_TOKEN is undefined")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
color1 := lifx.RGBColor{R: 235, G: 191, B: 255}
|
s := &lifx.State{Power: "on", Color: "blue"}
|
||||||
color2 := lifx.NewHSBKColor()
|
c := lifx.NewSession(apiToken)
|
||||||
color2.H = 27
|
c.SetState("group:Office", s)
|
||||||
color2.S = 1
|
time.Sleep(10 * time.Second)
|
||||||
color2.B = 0.39
|
s.Color = "white"
|
||||||
fmt.Println(color1.Hex())
|
res, _ := c.SetState("group:Office", s)
|
||||||
fmt.Println(color1.ColorString())
|
fmt.Println(res)
|
||||||
fmt.Println(color2.ColorString())
|
//c.SetState("all", &lifx.State{Power: "on", Color: "green"})
|
||||||
s := lifx.State{Power: "on", Color: color2}
|
time.Sleep(10)
|
||||||
c := lifx.NewClient(accessToken)
|
//c.PowerOff("all")
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Status string
|
|
||||||
|
|
||||||
State struct {
|
State struct {
|
||||||
Power string `json:"power,omitempty"`
|
Power string `json:"power,omitempty"`
|
||||||
Color Color `json:"color,omitempty"`
|
Color Color `json:"color,omitempty"`
|
||||||
|
18
structs.go
18
structs.go
@ -2,6 +2,7 @@ package lifx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,6 +13,23 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
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 {
|
RGBColor struct {
|
||||||
R, G, B uint8
|
R, G, B uint8
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user