mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 15:15:14 -06:00
Merge pull request #26 from metalmatze/golanglint-ci-fixes
Fix default golanglint-ci errors
This commit is contained in:
2
app.go
2
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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
4
state.go
4
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) {
|
||||
|
||||
Reference in New Issue
Block a user