Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LUJUNQUAN opened this issue May 8, 2024 · 0 comments

Comments

@LUJUNQUAN
Copy link

LUJUNQUAN commented May 8, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant