From 56ccdfbdb2821ccf99dcf74b2094bc409bb66ff8 Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Sun, 19 Jan 2025 20:58:16 -0500 Subject: [PATCH 1/2] two url fixes: - default scheme for legacy connection params - set paths for http and websocket APIs --- app.go | 4 ++++ internal/http/http.go | 1 + internal/websocket/websocket.go | 1 + 3 files changed, 6 insertions(+) diff --git a/app.go b/app.go index 66cf94f..bd20a4f 100644 --- a/app.go +++ b/app.go @@ -109,6 +109,10 @@ func NewApp(request NewAppRequest) (*App, error) { if port == "" { port = "8123" } + baseURL.Scheme = "http" + if request.Secure { + baseURL.Scheme = "https" + } baseURL.Host = request.IpAddress + ":" + port } diff --git a/internal/http/http.go b/internal/http/http.go index 8fee706..8d9c9f7 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -18,6 +18,7 @@ type HttpClient struct { func NewHttpClient(url *url.URL, token string) *HttpClient { // Shallow copy the URL to avoid modifying the original u := *url + u.Path = "/api" if u.Scheme == "ws" { u.Scheme = "http" } diff --git a/internal/websocket/websocket.go b/internal/websocket/websocket.go index ad48b33..eab5030 100644 --- a/internal/websocket/websocket.go +++ b/internal/websocket/websocket.go @@ -51,6 +51,7 @@ func ConnectionFromUri(baseURL *url.URL, authToken string) (*websocket.Conn, con // Shallow copy the URL to avoid modifying the original urlWebsockets := *baseURL + urlWebsockets.Path = "/api/websocket" if baseURL.Scheme == "http" { urlWebsockets.Scheme = "ws" } From 004e79749a70cbe7a993119a2ba8f35d5c6ed75b Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Sun, 19 Jan 2025 21:18:21 -0500 Subject: [PATCH 2/2] update README --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 820459e..2cea3e3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,11 @@ The general flow is import ga "saml.dev/gome-assistant" // replace with IP and port of your Home Assistant installation -app, err := ga.NewApp("0.0.0.0:8123") +app, err := ga.NewApp(ga.NewAppRequest{ + URL: "http://192.168.1.123:8123", + HAAuthToken: os.Getenv("HA_AUTH_TOKEN"), + HomeZoneEntityId: "zone.home", +}) // create automations here (see next sections)