-
-
Save timoschilling/f6084de88b66e0ee423a7d6b60b6e3ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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