diff --git a/internal/services/services.go b/internal/services/services.go index e9602ba..8275474 100644 --- a/internal/services/services.go +++ b/internal/services/services.go @@ -2,7 +2,6 @@ package services import ( "context" - "fmt" "saml.dev/gome-assistant/internal" ws "saml.dev/gome-assistant/internal/websocket" @@ -32,7 +31,7 @@ func BuildService[ } type BaseServiceRequest struct { - Id string `json:"id"` + Id int64 `json:"id"` RequestType string `json:"type"` // hardcoded "call_service" Domain string `json:"domain"` Service string `json:"service"` @@ -45,7 +44,7 @@ type BaseServiceRequest struct { func NewBaseServiceRequest(entityId string) BaseServiceRequest { id := internal.GetId() bsr := BaseServiceRequest{ - Id: fmt.Sprint(id), + Id: id, RequestType: "call_service", } if entityId != "" { diff --git a/internal/websocket/reader.go b/internal/websocket/reader.go index d58e15b..95977cb 100644 --- a/internal/websocket/reader.go +++ b/internal/websocket/reader.go @@ -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