mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-07 20:07:13 -06:00
two things:
fix bug with newer HA versions by sending int id instead of string add warning to logs when receiving unsuccessful websocket response
This commit is contained in:
@@ -3,20 +3,23 @@ package websocket
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type BaseMessage struct {
|
||||
Type string `json:"type"`
|
||||
Id int64 `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Id int64 `json:"id"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type ChanMsg struct {
|
||||
Id int64
|
||||
Type string
|
||||
Raw []byte
|
||||
Id int64
|
||||
Type string
|
||||
Success bool
|
||||
Raw []byte
|
||||
}
|
||||
|
||||
func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) {
|
||||
@@ -29,12 +32,19 @@ func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg)
|
||||
break
|
||||
}
|
||||
|
||||
base := BaseMessage{}
|
||||
base := BaseMessage{
|
||||
// default to true for messages that don't include "success" at all
|
||||
Success: true,
|
||||
}
|
||||
json.Unmarshal(bytes, &base)
|
||||
if !base.Success {
|
||||
fmt.Println("WARNING: received unsuccessful response:", string(bytes))
|
||||
}
|
||||
chanMsg := ChanMsg{
|
||||
Type: base.Type,
|
||||
Id: base.Id,
|
||||
Raw: bytes,
|
||||
Type: base.Type,
|
||||
Id: base.Id,
|
||||
Success: base.Success,
|
||||
Raw: bytes,
|
||||
}
|
||||
|
||||
c <- chanMsg
|
||||
|
||||
Reference in New Issue
Block a user