Compare commits

..

5 Commits

3 changed files with 31 additions and 7 deletions

View File

@ -21,6 +21,7 @@ type (
accessToken string
userAgent string
Client *http.Client
debug bool
}
Result struct {
@ -102,6 +103,12 @@ func WithUserAgent(userAgent string) func(*Client) {
}
}
func WithDebug(debug bool) func(*Client) {
return func(c *Client) {
c.debug = debug
}
}
func NewClientWithUserAgent(accessToken string, userAgent string) *Client {
tr := &http.Transport{
//TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),

View File

@ -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
}

View File

@ -3,6 +3,7 @@ package lifx
import (
//"crypto/tls"
"encoding/json"
"errors"
"net/http"
"time"
)
@ -116,6 +117,13 @@ func NewBreathe() Breathe {
return b
}
func (b *Breathe) Valid() error {
if b.Peak < 0 || b.Peak > 1 {
return errors.New("peak must be between 0.0 and 1.0")
}
return nil
}
func (c *Client) SetState(selector string, state State) (*LifxResponse, error) {
var (
err error