Merge pull request #29 from saml-dev/fix-urls

URL fixes
This commit is contained in:
saml-dev
2025-01-19 21:26:12 -05:00
committed by GitHub
4 changed files with 11 additions and 1 deletions

View File

@@ -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)

4
app.go
View File

@@ -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
}

View File

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

View File

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