Add breathe effect
This commit is contained in:
		
							
								
								
									
										29
									
								
								client.go
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								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 | ||||
|   | ||||
| @@ -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)) | ||||
| 	} | ||||
| ) | ||||
|   | ||||
							
								
								
									
										33
									
								
								lights.go
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								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 | ||||
| } | ||||
		Reference in New Issue
	
	Block a user