mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
made package exportable
This commit is contained in:
parent
0feaa3822b
commit
d43b434884
@ -0,0 +1 @@
|
|||||||
|
{"Name":"191280A3-4A87-4669-96C6-064794876004","PublicKey":"oSLgMjcuMkZynqswmP9PSaNOkQvWgWvNKgOPWjLlVsw=","PrivateKey":null}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
{"Name":"94:a8:80:9b:72:3d","PublicKey":"57Z/hKa1lyMTMPPwxWbYf9nGH/tVmXGBnPfMcswvh5U=","PrivateKey":"OWViYzNiZTk1YjI4ZDkzYTA5YzlkNjZiZjQ0ZmMyOWHntn+EprWXIxMw8/DFZth/2cYf+1WZcYGc98xyzC+HlQ=="}
|
||||||
1
Personal Light Bulb/configHash
Normal file
1
Personal Light Bulb/configHash
Normal file
@ -0,0 +1 @@
|
|||||||
|
AŽèŠ<²ù¥‚çôè„
|
||||||
1
Personal Light Bulb/uuid
Normal file
1
Personal Light Bulb/uuid
Normal file
@ -0,0 +1 @@
|
|||||||
|
94:a8:80:9b:72:3d
|
||||||
1
Personal Light Bulb/version
Normal file
1
Personal Light Bulb/version
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
19
bridge.go
19
bridge.go
@ -1,4 +1,4 @@
|
|||||||
package main
|
package hue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -31,6 +31,23 @@ type BridgeUserConfig struct {
|
|||||||
ReplacesBridgeID string `json:"replacesbridgeid"`
|
ReplacesBridgeID string `json:"replacesbridgeid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BridgeResponse is the response object returned to a bridge command
|
||||||
|
type BridgeResponse struct {
|
||||||
|
Success map[string]interface{} `json:"success"`
|
||||||
|
Error *BridgeResponseError `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// BridgeResponseError provides info about a bridge api error
|
||||||
|
type BridgeResponseError struct {
|
||||||
|
Type uint `json:"type"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err *BridgeResponseError) String() string {
|
||||||
|
return fmt.Sprintf("Type=\"%d\" Addr=\"%s\" Desc=\"%s\" \n", err.Type, err.Address, err.Description)
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// Methods
|
// Methods
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package main
|
package hue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|||||||
21
lights.go
21
lights.go
@ -1,4 +1,4 @@
|
|||||||
package main
|
package hue
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
@ -24,18 +24,23 @@ type LightState struct {
|
|||||||
Reachable bool `json:"reachable,omitempty"`
|
Reachable bool `json:"reachable,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type cmdResponse struct {
|
// LightsEndpoint for the lights
|
||||||
}
|
|
||||||
|
|
||||||
const LightsEndpoint = "/lights"
|
const LightsEndpoint = "/lights"
|
||||||
|
|
||||||
func (l *Light) String() string {
|
func (l *Light) String() string {
|
||||||
return fmt.Sprintf("Name=\"%s\" Model=\"%s\" On=\"%x\" XY=\"%x\" \n", l.Name, l.ModelID, l.State.On, l.State.XY)
|
return fmt.Sprintf("Name=\"%s\" Model=\"%s\" On=\"%v\" XY=\"%x\" \n", l.Name, l.ModelID, l.State.On, l.State.XY)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) ToggleLight(id string, on bool) error {
|
// ToggleLight switches light on or off
|
||||||
cmd := &LightState{
|
func (b *Bridge) ToggleLight(id string, on bool) (resp *BridgeResponse, err error) {
|
||||||
|
state := &LightState{
|
||||||
On: on,
|
On: on,
|
||||||
}
|
}
|
||||||
return b.putToBridge(LightsEndpoint+"/"+id+"/state", cmd, nil)
|
return b.SetLightState(id, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
|
|||||||
43
main.go
43
main.go
@ -1,7 +1,10 @@
|
|||||||
package main
|
package hue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "0.1.2"
|
const VERSION = "0.1.2"
|
||||||
@ -19,10 +22,42 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println("Created bridge ", bridge)
|
fmt.Println("Created bridge ", bridge)
|
||||||
|
|
||||||
test := &BridgeState{}
|
// errCom := bridge.ToggleLight("2", false)
|
||||||
errCom := bridge.ToggleLight("2", false)
|
// if errCom != nil {
|
||||||
|
// fmt.Println("[ERROR]" + errCom.Error())
|
||||||
|
// }
|
||||||
|
//tickSwitch(bridge)
|
||||||
|
testLightBulb(bridge)
|
||||||
|
select {}
|
||||||
|
//fmt.Println(test)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func strobeLight(b *Bridge, id string) {
|
||||||
|
ticker := time.NewTicker(200 * time.Millisecond)
|
||||||
|
quit := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
state := false
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
resp, errCom := b.ToggleLight(id, state)
|
||||||
if errCom != nil {
|
if errCom != nil {
|
||||||
fmt.Println("[ERROR]" + errCom.Error())
|
fmt.Println("[ERROR]" + errCom.Error())
|
||||||
|
ticker.Stop()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
fmt.Println(test)
|
if resp.Error != nil {
|
||||||
|
fmt.Println("[ERROR]" + resp.Error.String())
|
||||||
|
ticker.Stop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
state = !state
|
||||||
|
// do stuff
|
||||||
|
case <-quit:
|
||||||
|
ticker.Stop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
3
state.go
3
state.go
@ -1,9 +1,10 @@
|
|||||||
package main
|
package hue
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// ~ Interfaces & Types
|
// ~ Interfaces & Types
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
|
// BridgeState provides all data for a bridge
|
||||||
type BridgeState struct {
|
type BridgeState struct {
|
||||||
Lights map[string]*Light `json:"lights"`
|
Lights map[string]*Light `json:"lights"`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user