mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
add Script service
This commit is contained in:
52
internal/services/script.go
Normal file
52
internal/services/script.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
ws "saml.dev/gome-assistant/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
type Script struct {
|
||||
conn *ws.WebsocketWriter
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
|
||||
// Reload a script that was created in the HA UI.
|
||||
func (s Script) Reload(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "script"
|
||||
req.Service = "reload"
|
||||
|
||||
s.conn.WriteMessage(req, s.ctx)
|
||||
}
|
||||
|
||||
// Toggle a script that was created in the HA UI.
|
||||
func (s Script) Toggle(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "script"
|
||||
req.Service = "toggle"
|
||||
|
||||
s.conn.WriteMessage(req, s.ctx)
|
||||
}
|
||||
|
||||
// Turn off a script that was created in the HA UI.
|
||||
func (s Script) TurnOff() {
|
||||
req := NewBaseServiceRequest("")
|
||||
req.Domain = "script"
|
||||
req.Service = "turn_off"
|
||||
|
||||
s.conn.WriteMessage(req, s.ctx)
|
||||
}
|
||||
|
||||
// Turn on a script that was created in the HA UI.
|
||||
func (s Script) TurnOn(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "script"
|
||||
req.Service = "turn_on"
|
||||
|
||||
s.conn.WriteMessage(req, s.ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user