Don't start HAP server without any devices

This ensures that when iOS reconnects, it doesn't find an empty server
and thinks all the devices have been removed, and removes them all
locally.
This commit is contained in:
Darell Tan
2024-11-22 04:01:07 +08:00
parent e678f2a31d
commit 4d51380873
2 changed files with 9 additions and 0 deletions

View File

@@ -212,6 +212,11 @@ func (br *Bridge) WaitConfigured() {
}
}
// Return number of devices added to the bridge.
func (br *Bridge) NumDevices() int {
return len(br.devices)
}
// Connects to the MQTT server.
// Blocks until the connection is established, then auto-reconnect logic takes over
func (br *Bridge) ConnectMQTT() error {

View File

@@ -123,6 +123,10 @@ func main() {
}()
br.WaitConfigured()
if br.NumDevices() == 0 {
log.Println("No devices added to bridge. Refusing to start.")
return
}
log.Println("hapz2m configured. starting HAP server...")