Skip to content

Commit 05131fa

Browse files
authored
Merge pull request #29 from saml-dev/fix-urls
URL fixes
2 parents c27e596 + 004e797 commit 05131fa

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ The general flow is
4040
import ga "saml.dev/gome-assistant"
4141

4242
// replace with IP and port of your Home Assistant installation
43-
app, err := ga.NewApp("0.0.0.0:8123")
43+
app, err := ga.NewApp(ga.NewAppRequest{
44+
URL: "http://192.168.1.123:8123",
45+
HAAuthToken: os.Getenv("HA_AUTH_TOKEN"),
46+
HomeZoneEntityId: "zone.home",
47+
})
4448

4549
// create automations here (see next sections)
4650

app.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func NewApp(request NewAppRequest) (*App, error) {
109109
if port == "" {
110110
port = "8123"
111111
}
112+
baseURL.Scheme = "http"
113+
if request.Secure {
114+
baseURL.Scheme = "https"
115+
}
112116
baseURL.Host = request.IpAddress + ":" + port
113117
}
114118

internal/http/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type HttpClient struct {
1818
func NewHttpClient(url *url.URL, token string) *HttpClient {
1919
// Shallow copy the URL to avoid modifying the original
2020
u := *url
21+
u.Path = "/api"
2122
if u.Scheme == "ws" {
2223
u.Scheme = "http"
2324
}

internal/websocket/websocket.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func ConnectionFromUri(baseURL *url.URL, authToken string) (*websocket.Conn, con
5151

5252
// Shallow copy the URL to avoid modifying the original
5353
urlWebsockets := *baseURL
54+
urlWebsockets.Path = "/api/websocket"
5455
if baseURL.Scheme == "http" {
5556
urlWebsockets.Scheme = "ws"
5657
}

0 commit comments

Comments
 (0)