mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-09 12:07:25 -06:00
Fix panics due to concurrent websocket writes
This commit is contained in:
@@ -3,14 +3,13 @@ package services
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
ws "saml.dev/gome-assistant/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
type InputBoolean struct {
|
||||
conn *websocket.Conn
|
||||
conn *ws.WebsocketWriter
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
@@ -21,7 +20,7 @@ func (ib InputBoolean) TurnOn(entityId string) {
|
||||
req.Domain = "input_boolean"
|
||||
req.Service = "turn_on"
|
||||
|
||||
ws.WriteMessage(req, ib.conn, ib.ctx)
|
||||
ib.conn.WriteMessage(req, ib.ctx)
|
||||
}
|
||||
|
||||
func (ib InputBoolean) Toggle(entityId string) {
|
||||
@@ -29,19 +28,19 @@ func (ib InputBoolean) Toggle(entityId string) {
|
||||
req.Domain = "input_boolean"
|
||||
req.Service = "toggle"
|
||||
|
||||
ws.WriteMessage(req, ib.conn, ib.ctx)
|
||||
ib.conn.WriteMessage(req, ib.ctx)
|
||||
}
|
||||
|
||||
func (ib InputBoolean) TurnOff(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "input_boolean"
|
||||
req.Service = "turn_off"
|
||||
ws.WriteMessage(req, ib.conn, ib.ctx)
|
||||
ib.conn.WriteMessage(req, ib.ctx)
|
||||
}
|
||||
|
||||
func (ib InputBoolean) Reload() {
|
||||
req := NewBaseServiceRequest("")
|
||||
req.Domain = "input_boolean"
|
||||
req.Service = "reload"
|
||||
ws.WriteMessage(req, ib.conn, ib.ctx)
|
||||
ib.conn.WriteMessage(req, ib.ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user