Skip to content

Instantly share code, notes, and snippets.

@timoschilling
Forked from gerardbos/multiswitchtest.go
Created November 29, 2017 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timoschilling/f6084de88b66e0ee423a7d6b60b6e3ea to your computer and use it in GitHub Desktop.
Save timoschilling/f6084de88b66e0ee423a7d6b60b6e3ea to your computer and use it in GitHub Desktop.
package main
import (
"strconv"
"github.com/brutella/hc"
"github.com/brutella/hc/log"
"github.com/brutella/hc/accessory"
)
type Bridge struct {
*accessory.Accessory
}
func NewBridge(name string) *Bridge {
acc := Bridge{}
info := accessory.Info{
Name: name,
Manufacturer: "AVM",
Model: "Fritz!Box",
}
acc.Accessory = accessory.New(info, accessory.TypeBridge)
return &acc
}
func main(){
log.Debug.Enable()
accessory_cnt := 18
hc_config := hc.Config{Pin: "56781234", StoragePath: "./db"}
var switches[] *accessory.Accessory
for i := 0; i < accessory_cnt; i++ {
info_ := accessory.Info{
Name: strconv.Itoa(i),
SerialNumber: strconv.Itoa(i),
}
s := accessory.NewSwitch(info_);
switches = append(switches, s.Accessory)
}
t, err := hc.NewIPTransport(hc_config, NewBridge("Switch Bridge").Accessory, switches...)
if(err != nil){
log.Info.Fatal("Error starting Transport. Error: ", err)
}
hc.OnTermination(func(){
log.Info.Println("Stopping transport")
<-t.Stop()
})
t.Start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment