Skip to content

Using a bridge causes the state of the device in the Apple home app to be out of sync #58

@LUJUNQUAN

Description

@LUJUNQUAN

Using the bridge, the device status in the Apple home app is no longer synchronized after the state changes several times, and it needs to be controlled before it will be synchronized。

func main() {

	a := accessory.NewBridge(accessory.Info{
		Name: "Bridge",
	})

	b := accessory.NewSwitch(accessory.Info{
		Name: "Lamp",
	})

	d := accessory.NewSwitch(accessory.Info{
		Name: "Lamp1",
	})

	s, err := hap.NewServer(hap.NewFsStore("./db"), a.A, b.A, d.A)
	if err != nil {
		log.Panic(err)
	}

	// Log to console when client (e.g. iOS app) changes the value of the on characteristic
	b.Switch.On.OnValueRemoteUpdate(func(on bool) {
		if on {
			log.Println("Client changed switch to on")
		} else {
			log.Println("Client changed switch to off")
		}
	})

	s.Pin = "34679023"

	// Periodically toggle the switch's on characteristic
	go func() {
		for {
			on := !b.Switch.On.Value()
			if on {
				log.Println("Switch is on")
			} else {
				log.Println("Switch is off")
			}
			b.Switch.On.SetValue(on)
			time.Sleep(5 * time.Second)
		}
	}()

	c := make(chan os.Signal)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)

	ctx, cancel := context.WithCancel(context.Background())
	go func() {
		<-c
		signal.Stop(c)
		cancel()
	}()

	s.ListenAndServe(ctx)
}

Remove the first bridge a, then the status in the Apple home app is synchronized no matter how the value is set

What causes this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions