Compare commits
5 Commits
2107a05864
...
master
Author | SHA1 | Date | |
---|---|---|---|
15145d1f58
|
|||
c6b538380c
|
|||
4c1678b62c
|
|||
f79ea1df5d
|
|||
41b730d33d
|
@ -237,7 +237,7 @@ func (c *Client) breathe(selector string, breathe Breathe) (*Response, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) setStates(selector string, states States) (*Response, error) {
|
||||
func (c *Client) setStates(states States) (*Response, error) {
|
||||
var (
|
||||
err error
|
||||
j []byte
|
||||
|
23
color.go
23
color.go
@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -164,6 +163,10 @@ func (c RGBColor) ColorString() string {
|
||||
return fmt.Sprintf("rgb:%d,%d,%d", c.R, c.G, c.B)
|
||||
}
|
||||
|
||||
func (c RGBColor) String() string {
|
||||
return c.ColorString()
|
||||
}
|
||||
|
||||
func (c RGBColor) Hex() string {
|
||||
return fmt.Sprintf("#%x%x%x", c.R, c.G, c.B)
|
||||
}
|
||||
@ -185,6 +188,10 @@ func (c HSBKColor) ColorString() string {
|
||||
return strings.Join(s, " ")
|
||||
}
|
||||
|
||||
func (c HSBKColor) String() string {
|
||||
return c.ColorString()
|
||||
}
|
||||
|
||||
func (c HSBKColor) MarshalText() ([]byte, error) {
|
||||
return []byte(c.ColorString()), nil
|
||||
}
|
||||
@ -197,11 +204,14 @@ func (c NamedColor) ColorString() string {
|
||||
return string(c)
|
||||
}
|
||||
|
||||
func (c NamedColor) String() string {
|
||||
return c.ColorString()
|
||||
}
|
||||
|
||||
func (c *Client) ValidateColor(color Color) (Color, error) {
|
||||
var (
|
||||
err error
|
||||
s *HSBKColor
|
||||
r *http.Response
|
||||
resp *Response
|
||||
)
|
||||
|
||||
@ -209,13 +219,12 @@ func (c *Client) ValidateColor(color Color) (Color, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err = NewResponse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.IsError() {
|
||||
return nil, resp.GetLifxError()
|
||||
}
|
||||
|
||||
if err = json.NewDecoder(resp.Body).Decode(&s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
30
lights.go
30
lights.go
@ -40,19 +40,19 @@ type (
|
||||
}
|
||||
|
||||
Light struct {
|
||||
Id string `json:"id"`
|
||||
UUID string `json:"uuid"`
|
||||
Label string `json:"label"`
|
||||
Connected bool `json:"connected"`
|
||||
Power string `json:"power"`
|
||||
Color HSBKColor `json:"color"`
|
||||
Brightness float64 `json:"brightness"`
|
||||
Effect string `json:"effect"`
|
||||
Group Selector `json:"group"`
|
||||
Location Selector `json:"location"`
|
||||
Product Product `json:"product"`
|
||||
LastSeen time.Time `json:"last_seen"`
|
||||
SecondsLastSeen float64 `json:"seconds_last_seen"`
|
||||
Id string `json:"id"`
|
||||
UUID string `json:"uuid"`
|
||||
Label string `json:"label"`
|
||||
Connected bool `json:"connected"`
|
||||
Power string `json:"power"`
|
||||
Color HSBKColor `json:"color"`
|
||||
Brightness float64 `json:"brightness"`
|
||||
Effect string `json:"effect"`
|
||||
Group Selector `json:"group"`
|
||||
Location Selector `json:"location"`
|
||||
Product Product `json:"product"`
|
||||
LastSeen *time.Time `json:"last_seen,omitempty"`
|
||||
SecondsLastSeen float64 `json:"seconds_last_seen"`
|
||||
}
|
||||
|
||||
State struct {
|
||||
@ -156,14 +156,14 @@ func (c *Client) FastSetState(selector string, state State) (*LifxResponse, erro
|
||||
return c.SetState(selector, state)
|
||||
}
|
||||
|
||||
func (c *Client) SetStates(selector string, states States) (*LifxResponse, error) {
|
||||
func (c *Client) SetStates(states States) (*LifxResponse, error) {
|
||||
var (
|
||||
err error
|
||||
s *LifxResponse
|
||||
resp *Response
|
||||
)
|
||||
|
||||
if resp, err = c.setStates(selector, states); err != nil {
|
||||
if resp, err = c.setStates(states); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
Reference in New Issue
Block a user