diff --git a/client.go b/client.go index 49743a2..e6878f5 100644 --- a/client.go +++ b/client.go @@ -201,6 +201,35 @@ func (c *Client) setState(selector string, state State) (*Response, error) { return resp, nil } +func (c *Client) breathe(selector string, breathe Breathe) (*Response, error) { + var ( + err error + j []byte + req *http.Request + r *http.Response + resp *Response + ) + + if j, err = json.Marshal(breathe); err != nil { + return nil, err + } + + if req, err = c.NewRequest("POST", EndpointBreathe(selector), bytes.NewBuffer(j)); err != nil { + return nil, err + } + + if r, err = c.Client.Do(req); err != nil { + return nil, err + } + + resp, err = NewResponse(r) + if err != nil { + return nil, err + } + + return resp, nil +} + func (c *Client) setStates(selector string, states States) (*Response, error) { var ( err error diff --git a/endpoints.go b/endpoints.go index 6db0c5b..55ecd51 100644 --- a/endpoints.go +++ b/endpoints.go @@ -32,4 +32,7 @@ var ( EndpointToggle = func(selector string) string { return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/toggle", selector)) } + EndpointBreathe = func(selector string) string { + return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/effect/breathe", selector)) + } ) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e020976 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.kill0.net/chill9/lifx-go + +go 1.16 diff --git a/lights.go b/lights.go index 6137cd2..bce546f 100644 --- a/lights.go +++ b/lights.go @@ -86,6 +86,16 @@ type ( Toggle struct { Duration float64 `json:"duration,omitempty"` } + + Breathe struct { + Color Color `json:"color,omitempty"` + FromColor Color `json:"from_color,omitempty"` + Period float32 `json:"period,omitempty"` + Cycles float32 `json:"cycles,omitempty"` + Persist bool `json:"persist,omitempty"` + PowerOn bool `json:"power_on,omitempty"` + Peak float32 `json:"peak,omitempty"` + } ) func (c *Client) SetState(selector string, state State) (*LifxResponse, error) { @@ -219,3 +229,26 @@ func (c *Client) PowerOn(selector string) (*LifxResponse, error) { func (c *Client) FastPowerOn(selector string) { c.SetState(selector, State{Power: "on", Fast: true}) } + +func (c *Client) Breathe(selector string, breathe Breathe) (*LifxResponse, error) { + var ( + err error + s *LifxResponse + resp *Response + ) + + if resp, err = c.breathe(selector, breathe); 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 + } + + return s, nil +} \ No newline at end of file