From 46546f5494190ca1d4c26aec55a7fe16d874b2c1 Mon Sep 17 00:00:00 2001 From: chrizg <22716298+chrizg@users.noreply.github.com> Date: Sat, 16 May 2026 23:47:20 +0200 Subject: [PATCH] feat(soundtouch-web): add --host flag for manual device IP --- cmd/soundtouch-web/main.go | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/cmd/soundtouch-web/main.go b/cmd/soundtouch-web/main.go index d22a74b..e40f618 100644 --- a/cmd/soundtouch-web/main.go +++ b/cmd/soundtouch-web/main.go @@ -46,6 +46,11 @@ func main() { Usage: "Network interface name (e.g. eth0) for mDNS and UPnP device discovery. Defaults to the --bind interface name when one was given; leave empty otherwise to auto-pick", EnvVars: []string{"DISCOVERY_INTERFACE"}, }, + &cli.StringFlag{ + Name: "host", + Usage: "SoundTouch device IP address to add manually", + EnvVars: []string{"SOUNDTOUCH_HOST"}, + }, }, Action: func(c *cli.Context) error { port := c.String("port") @@ -61,6 +66,7 @@ func main() { } rawIface := c.String("interface") + manualHost := c.String("host") ifaceName := defaultDiscoveryInterface(rawIface, rawBind, bindAddr) if rawIface == "" && ifaceName != "" { @@ -99,12 +105,14 @@ func main() { webApp.BroadcastDiscoveryStatus("starting", len(webApp.Devices)) + if manualHost != "" { + addManualDevice(webApp, manualHost, 8090) + } discoverDevices(ctx, webApp, discoveryService) webApp.BroadcastDiscoveryStatus("completed", len(webApp.Devices)) webApp.BroadcastDeviceList() }() - r := setupRoutes(webApp, discoveryService) log.Printf("SoundTouch Web UI starting on http://%s", addr) @@ -200,6 +208,38 @@ func resolveBindAddr(bindAddr string) (string, error) { } } +func addManualDevice(app *handlers.WebApp, host string, port int) { + clientConfig := &client.Config{ + Host: host, + Port: port, + Timeout: 10 * time.Second, + } + + soundTouchClient := client.NewClient(clientConfig) + + deviceInfo, err := soundTouchClient.GetDeviceInfo() + if err != nil { + log.Printf("Failed to get device info for manual host %s: %v", host, err) + return + } + + conn := &webtypes.DeviceConnection{ + Client: soundTouchClient, + DeviceInfo: deviceInfo, + LastSeen: time.Now(), + Status: webtypes.DeviceStatus{ + IsConnected: false, + LastActivity: time.Now(), + }, + } + + go app.UpdateDeviceStatus(host, conn) + + app.Devices[host] = conn + + log.Printf("Added manual device: %s (%s) at %s:%d", deviceInfo.Name, deviceInfo.Type, host, port) +} + func setupRoutes(app *handlers.WebApp, discoveryService *discovery.UnifiedDiscoveryService) *chi.Mux { r := chi.NewRouter()