mirror of
https://github.com/Xevion/go-ha.git
synced 2026-01-31 00:24:22 -06:00
Parse URL and pass it to clients
Right now, this SDK only works with IP:Port. I'm however running on https://home.example.com and need https or wss and an implicit port 443. Using net/url should be the best option.
This commit is contained in:
+3
-3
@@ -1,4 +1,4 @@
|
||||
package example
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -11,12 +11,12 @@ import (
|
||||
|
||||
func main() {
|
||||
app, err := ga.NewApp(ga.NewAppRequest{
|
||||
IpAddress: "192.168.86.67", // Replace with your Home Assistant IP Address
|
||||
URL: "http://192.168.86.67:8123", // Replace with your Home Assistant IP Address
|
||||
HAAuthToken: os.Getenv("HA_AUTH_TOKEN"),
|
||||
HomeZoneEntityId: "zone.home",
|
||||
})
|
||||
if err != nil {
|
||||
slog.Error("Error connecting to HASS:", err)
|
||||
slog.Error("Error connecting to HASS:", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package example
|
||||
package main
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
ga "saml.dev/gome-assistant"
|
||||
)
|
||||
|
||||
@@ -52,13 +53,13 @@ func (s *MySuite) SetupSuite() {
|
||||
|
||||
configFile, err := os.ReadFile("./config.yaml")
|
||||
if err != nil {
|
||||
slog.Error("Error reading config file", err)
|
||||
slog.Error("Error reading config file", "error", err)
|
||||
}
|
||||
s.config = &Config{}
|
||||
// either env var or config file can be used to set HA auth. token
|
||||
s.config.Hass.HAAuthToken = os.Getenv("HA_AUTH_TOKEN")
|
||||
if err := yaml.Unmarshal(configFile, s.config); err != nil {
|
||||
slog.Error("Error unmarshalling config file", err)
|
||||
slog.Error("Error unmarshalling config file", "error", err)
|
||||
}
|
||||
|
||||
s.app, err = ga.NewApp(ga.NewAppRequest{
|
||||
@@ -67,7 +68,7 @@ func (s *MySuite) SetupSuite() {
|
||||
HomeZoneEntityId: s.config.Hass.HomeZoneEntityId,
|
||||
})
|
||||
if err != nil {
|
||||
slog.Error("Failed to createw new app", err)
|
||||
slog.Error("Failed to create new app", "error", err)
|
||||
s.T().FailNow()
|
||||
}
|
||||
|
||||
@@ -135,7 +136,7 @@ func (s *MySuite) dailyScheduleCallback(se *ga.Service, st ga.State) {
|
||||
func getEntityState(s *MySuite, entityId string) string {
|
||||
state, err := s.app.GetState().Get(entityId)
|
||||
if err != nil {
|
||||
slog.Error("Error getting entity state", err)
|
||||
slog.Error("Error getting entity state", "error", err)
|
||||
s.T().FailNow()
|
||||
}
|
||||
slog.Info("State of entity", "state", state.State)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
module example
|
||||
|
||||
go 1.21
|
||||
go 1.23
|
||||
|
||||
require (
|
||||
github.com/golang-cz/devslog v0.0.8
|
||||
|
||||
Reference in New Issue
Block a user