diff --git a/bridge.go b/bridge.go index 1f8af6c..a3f5a9b 100644 --- a/bridge.go +++ b/bridge.go @@ -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 { diff --git a/cmd/hapz2m/main.go b/cmd/hapz2m/main.go index 0b39e2b..1cf2948 100644 --- a/cmd/hapz2m/main.go +++ b/cmd/hapz2m/main.go @@ -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...")