add SetDelta function
This commit is contained in:
parent
e39d81f6cc
commit
05566f480f
23
client.go
23
client.go
@ -185,3 +185,26 @@ func (c *Client) listLights(selector string) (*http.Response, error) {
|
|||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) stateDelta(selector string, delta StateDelta) (*http.Response, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
j []byte
|
||||||
|
req *http.Request
|
||||||
|
resp *http.Response
|
||||||
|
)
|
||||||
|
|
||||||
|
if j, err = json.Marshal(delta); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if req, err = c.NewRequest("POST", EndpointStateDelta(selector), bytes.NewBuffer(j)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp, err = c.Client.Do(req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
@ -17,6 +17,9 @@ var (
|
|||||||
EndpointState = func(selector string) string {
|
EndpointState = func(selector string) string {
|
||||||
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/state", selector))
|
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/state", selector))
|
||||||
}
|
}
|
||||||
|
EndpointStateDelta = func(selector string) string {
|
||||||
|
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/state/delta", selector))
|
||||||
|
}
|
||||||
EndpointListLights = func(selector string) string {
|
EndpointListLights = func(selector string) string {
|
||||||
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s", selector))
|
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s", selector))
|
||||||
}
|
}
|
||||||
|
29
lights.go
29
lights.go
@ -62,6 +62,16 @@ type (
|
|||||||
Fast bool `json:"fast,omitempty"`
|
Fast bool `json:"fast,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StateDelta struct {
|
||||||
|
Power *string `json:"power,omitempty"`
|
||||||
|
Duration *float64 `json:"duration,omitempty"`
|
||||||
|
Infrared *float64 `json:"infrared,omitempty"`
|
||||||
|
Hue *float64 `json:"hue,omitempty"`
|
||||||
|
Saturation *float64 `json:"saturation,omitempty"`
|
||||||
|
Brightness *float64 `json:"brightness,omitempty"`
|
||||||
|
Kelvin *int `json:"kelvin,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
StateWithSelector struct {
|
StateWithSelector struct {
|
||||||
State
|
State
|
||||||
Selector string `json:"selector"`
|
Selector string `json:"selector"`
|
||||||
@ -128,6 +138,25 @@ func (c *Client) SetStates(selector string, states States) (*Response, error) {
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) StateDelta(selector string, delta StateDelta) (*Response, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
s *Response
|
||||||
|
resp *http.Response
|
||||||
|
)
|
||||||
|
|
||||||
|
if resp, err = c.stateDelta(selector, delta); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if err = json.NewDecoder(resp.Body).Decode(&s); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) Toggle(selector string, duration float64) (*Response, error) {
|
func (c *Client) Toggle(selector string, duration float64) (*Response, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
Loading…
Reference in New Issue
Block a user