brutella / hc

hc is a lightweight framework to develop HomeKit accessories in Go.
Apache License 2.0
1.74k stars 189 forks source link

Why can't the first device under the bridge device be displayed after updating to 1.2.1? #168

Closed Gucan closed 4 years ago

Gucan commented 4 years ago

Why can't the first device under the bridge device be displayed after updating to 1.2.1?

Gucan commented 4 years ago

There is no such problem when not using container

Gucan commented 4 years ago

bridge := accessory.New(accessory.Info{Name:"Gucan-Bridge",Manufacturer:"Gucan",SerialNumber:"GCBRIDGE",Model:"BR"},accessory.TypeBridge) container := accessory.NewContainer()

NAME:=[]string{"Switch1","Switch2","Switch3"}

for i:=0;i<3;i++ { N:=NAME[i] acc := accessory.NewSwitch(accessory.Info{Name:N,Manufacturer:"Gucan",SerialNumber:"GCSWITCH",Model:"A"}) acc.Switch.On.OnValueRemoteUpdate(func(on bool) { if on == true { print("ON") } else { print("OFF") } }) container.AddAccessory(acc.Accessory) }

Such code Switch1 will be lost

brutella commented 4 years ago

There is no need to create an accessory container yourself.

You can add your switches to the bridge like this

hc.NewIPTransport(cfg, bridge, switches)
Gucan commented 4 years ago

In this way, you can't use the for loop. It's troublesome to add accessories

brutella commented 4 years ago

Why not? You can add the accessories to a slice in the for-loop.

brutella commented 4 years ago

Closed due to inactivity