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) 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" }