mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-05 23:15:07 -06:00
Migrated rest of the obvious logs/prints to slog.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
|||||||
testing/
|
testing/
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package example
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ func main() {
|
|||||||
HomeZoneEntityId: "zone.home",
|
HomeZoneEntityId: "zone.home",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Error connecting to HASS:", err)
|
slog.Error("Error connecting to HASS:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer app.Cleanup()
|
defer app.Cleanup()
|
||||||
@@ -69,7 +69,7 @@ func onEvent(service *ga.Service, state ga.State, data ga.EventData) {
|
|||||||
// the eventTypes.go file :)
|
// the eventTypes.go file :)
|
||||||
ev := ga.EventZWaveJSValueNotification{}
|
ev := ga.EventZWaveJSValueNotification{}
|
||||||
json.Unmarshal(data.RawEventJSON, &ev)
|
json.Unmarshal(data.RawEventJSON, &ev)
|
||||||
log.Default().Println(ev)
|
slog.Info("On event invoked", "event", ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func lightsOut(service *ga.Service, state ga.State) {
|
func lightsOut(service *ga.Service, state ga.State) {
|
||||||
@@ -77,7 +77,7 @@ func lightsOut(service *ga.Service, state ga.State) {
|
|||||||
service.Light.TurnOff("light.outside_lights")
|
service.Light.TurnOff("light.outside_lights")
|
||||||
s, err := state.Get("binary_sensor.living_room_motion")
|
s, err := state.Get("binary_sensor.living_room_motion")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Default().Println("couldnt get living room motion state, doing nothing")
|
slog.Warn("couldnt get living room motion state, doing nothing")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ func setupLogging() {
|
|||||||
func (s *MySuite) SetupSuite() {
|
func (s *MySuite) SetupSuite() {
|
||||||
setupLogging()
|
setupLogging()
|
||||||
slog.Debug("Setting up test suite...")
|
slog.Debug("Setting up test suite...")
|
||||||
|
|
||||||
s.suiteCtx = make(map[string]any)
|
s.suiteCtx = make(map[string]any)
|
||||||
|
|
||||||
configFile, err := os.ReadFile("./config.yaml")
|
configFile, err := os.ReadFile("./config.yaml")
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ package websocket
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"log/slog"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
@@ -25,9 +24,8 @@ type ChanMsg struct {
|
|||||||
func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) {
|
func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) {
|
||||||
for {
|
for {
|
||||||
bytes, err := ReadMessage(conn, ctx)
|
bytes, err := ReadMessage(conn, ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Default().Println("Error reading from websocket:", err)
|
slog.Error("Error reading from websocket:", err)
|
||||||
close(c)
|
close(c)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -38,7 +36,7 @@ func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg)
|
|||||||
}
|
}
|
||||||
json.Unmarshal(bytes, &base)
|
json.Unmarshal(bytes, &base)
|
||||||
if !base.Success {
|
if !base.Success {
|
||||||
fmt.Println("WARNING: received unsuccessful response:", string(bytes))
|
slog.Warn("Received unsuccessful response", "response", string(bytes))
|
||||||
}
|
}
|
||||||
chanMsg := ChanMsg{
|
chanMsg := ChanMsg{
|
||||||
Type: base.Type,
|
Type: base.Type,
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ func runSchedules(a *App) {
|
|||||||
sched = popSchedule(a)
|
sched = popSchedule(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("Next schedule", "new run time", sched.nextRunTime)
|
slog.Info("Next schedule", "next run time", sched.nextRunTime)
|
||||||
time.Sleep(time.Until(sched.nextRunTime))
|
time.Sleep(time.Until(sched.nextRunTime))
|
||||||
sched.maybeRunCallback(a)
|
sched.maybeRunCallback(a)
|
||||||
requeueSchedule(a, sched)
|
requeueSchedule(a, sched)
|
||||||
|
|||||||
Reference in New Issue
Block a user