mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
update to work with new hue bridge com api
This commit is contained in:
parent
1199c755c4
commit
36b85a3980
30
lights.go
30
lights.go
@ -1,6 +1,7 @@
|
||||
package hue
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@ -77,7 +78,7 @@ type LightState struct {
|
||||
TransitionTime uint16 `json:"transitiontime,omitempty"`
|
||||
ColorMode string `json:"colormode,omitempty"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
Reachable bool `json:"reachable"`
|
||||
Reachable bool `json:"reachable,omitempty"`
|
||||
}
|
||||
|
||||
// LightsEndpoint for the lights
|
||||
@ -96,14 +97,29 @@ func (b *Bridge) ToggleLight(id string, on bool) (resp *BridgeResponse, err erro
|
||||
}
|
||||
|
||||
// SetLightState updates the light state
|
||||
func (b *Bridge) SetLightState(id string, state *LightState) (resp *BridgeResponse, err error) {
|
||||
err = b.putToBridge(LightsEndpoint+"/"+id+"/state", state, resp)
|
||||
return resp, err
|
||||
func (b *Bridge) SetLightState(id string, state *LightState) (result *BridgeResponse, err error) {
|
||||
res, err := b.putToBridge(LightsEndpoint+"/"+id+"/state", state)
|
||||
|
||||
// Unmarshal data
|
||||
errDecode := json.NewDecoder(res.Body).Decode(result)
|
||||
if errDecode != nil {
|
||||
return nil, errDecode
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
// GetLights returns all the hue lights
|
||||
func (b *Bridge) GetLights() (map[string]*Light, error) {
|
||||
result := make(map[string]*Light)
|
||||
err := b.getFromBridge("/lights", &result)
|
||||
func (b *Bridge) GetLights() (result map[string]*Light, err error) {
|
||||
res, errCom := b.getFromBridge("/lights")
|
||||
if errCom != nil {
|
||||
return nil, errCom
|
||||
}
|
||||
// Unmarshal data
|
||||
errDecode := json.NewDecoder(res.Body).Decode(result)
|
||||
if errDecode != nil {
|
||||
return nil, errDecode
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
11
state.go
11
state.go
@ -1,5 +1,7 @@
|
||||
package hue
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// ~ Interfaces & Types
|
||||
// -------------------------------------------------------------
|
||||
@ -21,6 +23,13 @@ func (bs *BridgeState) String() string {
|
||||
// GetState returns the current hue state
|
||||
func (b *Bridge) GetState() (*BridgeState, error) {
|
||||
state := &BridgeState{}
|
||||
err := b.getFromBridge("", state)
|
||||
res, err := b.getFromBridge("")
|
||||
|
||||
// Unmarshal data
|
||||
errDecode := json.NewDecoder(res.Body).Decode(state)
|
||||
if errDecode != nil {
|
||||
return nil, errDecode
|
||||
}
|
||||
|
||||
return state, err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user