mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 03:15:14 -06:00
Added lots of services and fixed bug with ID for websocket calls
This commit is contained in:
40
internal/services/switch.go
Normal file
40
internal/services/switch.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
ws "github.com/saml-dev/gome-assistant/internal/websocket"
|
||||
"nhooyr.io/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
type Switch struct {
|
||||
conn *websocket.Conn
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
|
||||
func (s Switch) TurnOn(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "switch"
|
||||
req.Service = "turn_on"
|
||||
|
||||
ws.WriteMessage(req, s.conn, s.ctx)
|
||||
}
|
||||
|
||||
func (s Switch) Toggle(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "switch"
|
||||
req.Service = "toggle"
|
||||
|
||||
ws.WriteMessage(req, s.conn, s.ctx)
|
||||
}
|
||||
|
||||
func (s Switch) TurnOff(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "switch"
|
||||
req.Service = "turn_off"
|
||||
ws.WriteMessage(req, s.conn, s.ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user