mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 15:15:14 -06:00
Fix default golanglint-ci errors
These errors show up when simply running `golangci-lint run ./...` on the project.
This commit is contained in:
2
app.go
2
app.go
@@ -304,7 +304,7 @@ func (a *App) Start() {
|
|||||||
|
|
||||||
// entity listeners and event listeners
|
// entity listeners and event listeners
|
||||||
elChan := make(chan ws.ChanMsg)
|
elChan := make(chan ws.ChanMsg)
|
||||||
go ws.ListenWebsocket(a.conn, a.ctx, elChan)
|
go ws.ListenWebsocket(a.conn, elChan)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
msg, ok := <-elChan
|
msg, ok := <-elChan
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang-module/carbon"
|
"github.com/golang-module/carbon"
|
||||||
|
|
||||||
"saml.dev/gome-assistant/internal"
|
"saml.dev/gome-assistant/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -193,7 +194,7 @@ func (b elBuilder3) Build() EntityListener {
|
|||||||
/* Functions */
|
/* Functions */
|
||||||
func callEntityListeners(app *App, msgBytes []byte) {
|
func callEntityListeners(app *App, msgBytes []byte) {
|
||||||
msg := stateChangedMsg{}
|
msg := stateChangedMsg{}
|
||||||
json.Unmarshal(msgBytes, &msg)
|
_ = json.Unmarshal(msgBytes, &msg)
|
||||||
data := msg.Event.Data
|
data := msg.Event.Data
|
||||||
eid := data.EntityID
|
eid := data.EntityID
|
||||||
listeners, ok := app.entityListeners[eid]
|
listeners, ok := app.entityListeners[eid]
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang-module/carbon"
|
"github.com/golang-module/carbon"
|
||||||
|
|
||||||
"saml.dev/gome-assistant/internal"
|
"saml.dev/gome-assistant/internal"
|
||||||
ws "saml.dev/gome-assistant/internal/websocket"
|
ws "saml.dev/gome-assistant/internal/websocket"
|
||||||
)
|
)
|
||||||
@@ -141,7 +142,7 @@ type BaseEventMsg struct {
|
|||||||
/* Functions */
|
/* Functions */
|
||||||
func callEventListeners(app *App, msg ws.ChanMsg) {
|
func callEventListeners(app *App, msg ws.ChanMsg) {
|
||||||
baseEventMsg := BaseEventMsg{}
|
baseEventMsg := BaseEventMsg{}
|
||||||
json.Unmarshal(msg.Raw, &baseEventMsg)
|
_ = json.Unmarshal(msg.Raw, &baseEventMsg)
|
||||||
listeners, ok := app.eventListeners[baseEventMsg.Event.EventType]
|
listeners, ok := app.eventListeners[baseEventMsg.Event.EventType]
|
||||||
if !ok {
|
if !ok {
|
||||||
// no listeners registered for this event type
|
// no listeners registered for this event type
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ type ChanMsg struct {
|
|||||||
Raw []byte
|
Raw []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) {
|
func ListenWebsocket(conn *websocket.Conn, c chan ChanMsg) {
|
||||||
for {
|
for {
|
||||||
bytes, err := ReadMessage(conn)
|
bytes, err := ReadMessage(conn)
|
||||||
if err != nil {
|
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
|
// default to true for messages that don't include "success" at all
|
||||||
Success: true,
|
Success: true,
|
||||||
}
|
}
|
||||||
json.Unmarshal(bytes, &base)
|
_ = json.Unmarshal(bytes, &base)
|
||||||
if !base.Success {
|
if !base.Success {
|
||||||
slog.Warn("Received unsuccessful response", "response", string(bytes))
|
slog.Warn("Received unsuccessful response", "response", string(bytes))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,8 +114,10 @@ func VerifyAuthResponse(conn *websocket.Conn, ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var authResp authResponse
|
var authResp authResponse
|
||||||
json.Unmarshal(msg, &authResp)
|
err = json.Unmarshal(msg, &authResp)
|
||||||
// log.Println(authResp.MsgType)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if authResp.MsgType != "auth_ok" {
|
if authResp.MsgType != "auth_ok" {
|
||||||
return ErrInvalidToken
|
return ErrInvalidToken
|
||||||
}
|
}
|
||||||
|
|||||||
5
state.go
5
state.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang-module/carbon"
|
"github.com/golang-module/carbon"
|
||||||
|
|
||||||
"saml.dev/gome-assistant/internal/http"
|
"saml.dev/gome-assistant/internal/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -69,8 +70,8 @@ func (s *StateImpl) Get(entityId string) (EntityState, error) {
|
|||||||
return EntityState{}, err
|
return EntityState{}, err
|
||||||
}
|
}
|
||||||
es := EntityState{}
|
es := EntityState{}
|
||||||
json.Unmarshal(resp, &es)
|
err = json.Unmarshal(resp, &es)
|
||||||
return es, nil
|
return es, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateImpl) Equals(entityId string, expectedState string) (bool, error) {
|
func (s *StateImpl) Equals(entityId string, expectedState string) (bool, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user