mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 05:15:15 -06:00
@@ -40,7 +40,11 @@ The general flow is
|
|||||||
import ga "saml.dev/gome-assistant"
|
import ga "saml.dev/gome-assistant"
|
||||||
|
|
||||||
// replace with IP and port of your Home Assistant installation
|
// 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)
|
// create automations here (see next sections)
|
||||||
|
|
||||||
|
|||||||
4
app.go
4
app.go
@@ -109,6 +109,10 @@ func NewApp(request NewAppRequest) (*App, error) {
|
|||||||
if port == "" {
|
if port == "" {
|
||||||
port = "8123"
|
port = "8123"
|
||||||
}
|
}
|
||||||
|
baseURL.Scheme = "http"
|
||||||
|
if request.Secure {
|
||||||
|
baseURL.Scheme = "https"
|
||||||
|
}
|
||||||
baseURL.Host = request.IpAddress + ":" + port
|
baseURL.Host = request.IpAddress + ":" + port
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type HttpClient struct {
|
|||||||
func NewHttpClient(url *url.URL, token string) *HttpClient {
|
func NewHttpClient(url *url.URL, token string) *HttpClient {
|
||||||
// Shallow copy the URL to avoid modifying the original
|
// Shallow copy the URL to avoid modifying the original
|
||||||
u := *url
|
u := *url
|
||||||
|
u.Path = "/api"
|
||||||
if u.Scheme == "ws" {
|
if u.Scheme == "ws" {
|
||||||
u.Scheme = "http"
|
u.Scheme = "http"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ func ConnectionFromUri(baseURL *url.URL, authToken string) (*websocket.Conn, con
|
|||||||
|
|
||||||
// Shallow copy the URL to avoid modifying the original
|
// Shallow copy the URL to avoid modifying the original
|
||||||
urlWebsockets := *baseURL
|
urlWebsockets := *baseURL
|
||||||
|
urlWebsockets.Path = "/api/websocket"
|
||||||
if baseURL.Scheme == "http" {
|
if baseURL.Scheme == "http" {
|
||||||
urlWebsockets.Scheme = "ws"
|
urlWebsockets.Scheme = "ws"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user