add SetState method
This commit is contained in:
parent
cd04dd47b6
commit
2fbfe9cae8
14
client.go
14
client.go
@ -74,6 +74,20 @@ func (s *Client) SetState(selector string, state State) ([]Result, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *Client) SetStates(states States) ([]Result, error) {
|
||||
j, err := json.Marshal(states)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := s.Request("PUT", EndpointStates(), bytes.NewBuffer(j))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *Client) Toggle(selector string, duration float64) ([]Result, error) {
|
||||
j, err := json.Marshal(&Toggle{Duration: duration})
|
||||
if err != nil {
|
||||
|
@ -17,6 +17,9 @@ var (
|
||||
EndpointState = func(selector string) string {
|
||||
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/state", selector))
|
||||
}
|
||||
EndpointStates = func() string {
|
||||
return BuildURL(Endpoint, "/lights/states")
|
||||
}
|
||||
EndpointToggle = func(selector string) string {
|
||||
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/toggle", selector))
|
||||
}
|
||||
|
10
structs.go
10
structs.go
@ -18,6 +18,16 @@ type (
|
||||
Fast bool `json:"fast,omitempty"`
|
||||
}
|
||||
|
||||
StateWithSelector struct {
|
||||
State
|
||||
Selector string `json:"selector"`
|
||||
}
|
||||
|
||||
States struct {
|
||||
States []StateWithSelector `json:"states",omitempty`
|
||||
Defaults State `json:"defaults",omitempty`
|
||||
}
|
||||
|
||||
Client struct {
|
||||
token string
|
||||
Client *http.Client
|
||||
|
Loading…
Reference in New Issue
Block a user