diff --git a/app.go b/app.go index ba8ef7c..66cf94f 100644 --- a/app.go +++ b/app.go @@ -302,7 +302,7 @@ func (a *App) Start() { // entity listeners and event listeners elChan := make(chan ws.ChanMsg) - go ws.ListenWebsocket(a.conn, a.ctx, elChan) + go ws.ListenWebsocket(a.conn, elChan) for { msg, ok := <-elChan diff --git a/entitylistener.go b/entitylistener.go index 2dd3a3a..e727539 100644 --- a/entitylistener.go +++ b/entitylistener.go @@ -6,6 +6,7 @@ import ( "time" "github.com/golang-module/carbon" + "saml.dev/gome-assistant/internal" ) @@ -193,7 +194,7 @@ func (b elBuilder3) Build() EntityListener { /* Functions */ func callEntityListeners(app *App, msgBytes []byte) { msg := stateChangedMsg{} - json.Unmarshal(msgBytes, &msg) + _ = json.Unmarshal(msgBytes, &msg) data := msg.Event.Data eid := data.EntityID listeners, ok := app.entityListeners[eid] diff --git a/eventListener.go b/eventListener.go index 37fe98a..ca96cee 100644 --- a/eventListener.go +++ b/eventListener.go @@ -6,6 +6,7 @@ import ( "time" "github.com/golang-module/carbon" + "saml.dev/gome-assistant/internal" ws "saml.dev/gome-assistant/internal/websocket" ) @@ -141,7 +142,7 @@ type BaseEventMsg struct { /* Functions */ func callEventListeners(app *App, msg ws.ChanMsg) { baseEventMsg := BaseEventMsg{} - json.Unmarshal(msg.Raw, &baseEventMsg) + _ = json.Unmarshal(msg.Raw, &baseEventMsg) listeners, ok := app.eventListeners[baseEventMsg.Event.EventType] if !ok { // no listeners registered for this event type diff --git a/internal/websocket/reader.go b/internal/websocket/reader.go index 93cbe86..9685b32 100644 --- a/internal/websocket/reader.go +++ b/internal/websocket/reader.go @@ -1,7 +1,6 @@ package websocket import ( - "context" "encoding/json" "log/slog" @@ -21,7 +20,7 @@ type ChanMsg struct { Raw []byte } -func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) { +func ListenWebsocket(conn *websocket.Conn, c chan ChanMsg) { for { bytes, err := ReadMessage(conn) if err != nil { @@ -34,7 +33,7 @@ func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) // default to true for messages that don't include "success" at all Success: true, } - json.Unmarshal(bytes, &base) + _ = json.Unmarshal(bytes, &base) if !base.Success { slog.Warn("Received unsuccessful response", "response", string(bytes)) } diff --git a/internal/websocket/websocket.go b/internal/websocket/websocket.go index 5e25cc1..ad48b33 100644 --- a/internal/websocket/websocket.go +++ b/internal/websocket/websocket.go @@ -114,8 +114,10 @@ func VerifyAuthResponse(conn *websocket.Conn, ctx context.Context) error { } var authResp authResponse - json.Unmarshal(msg, &authResp) - // log.Println(authResp.MsgType) + err = json.Unmarshal(msg, &authResp) + if err != nil { + return err + } if authResp.MsgType != "auth_ok" { return ErrInvalidToken } diff --git a/state.go b/state.go index 0f365dd..2f1e700 100644 --- a/state.go +++ b/state.go @@ -70,8 +70,8 @@ func (s *StateImpl) Get(entityId string) (EntityState, error) { return EntityState{}, err } es := EntityState{} - json.Unmarshal(resp, &es) - return es, nil + err = json.Unmarshal(resp, &es) + return es, err } func (s *StateImpl) Equals(entityId string, expectedState string) (bool, error) {