add script triggers.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"git.aiterp.net/lucifer3/server/events"
|
||||
"git.aiterp.net/lucifer3/server/services/script"
|
||||
"git.aiterp.net/lucifer3/server/services/uistate"
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"log"
|
||||
@@ -14,6 +15,13 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var zeroUUID = uuid.UUID{
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
}
|
||||
|
||||
func New(addr string) (lucifer3.Service, error) {
|
||||
svc := &service{}
|
||||
|
||||
@@ -67,6 +75,19 @@ func New(addr string) (lucifer3.Service, error) {
|
||||
bus.RunCommand(*input.UpdateScript)
|
||||
case input.ExecuteScript != nil:
|
||||
bus.RunCommand(*input.ExecuteScript)
|
||||
case input.UpdateTrigger != nil:
|
||||
if input.UpdateTrigger.ID == zeroUUID {
|
||||
input.UpdateTrigger.ID = uuid.New()
|
||||
}
|
||||
if input.UpdateTrigger.ScriptPre == nil {
|
||||
input.UpdateTrigger.ScriptPre = make([]script.Line, 0)
|
||||
}
|
||||
if input.UpdateTrigger.ScriptPost == nil {
|
||||
input.UpdateTrigger.ScriptPost = make([]script.Line, 0)
|
||||
}
|
||||
bus.RunCommand(*input.UpdateTrigger)
|
||||
case input.DeleteTrigger != nil:
|
||||
bus.RunCommand(*input.DeleteTrigger)
|
||||
default:
|
||||
return c.String(400, "No supported command found in input")
|
||||
}
|
||||
@@ -123,8 +144,10 @@ type commandInput struct {
|
||||
ConnectDevice *commands.ConnectDevice `json:"connectDevice,omitempty"`
|
||||
SearchDevices *commands.SearchDevices `json:"searchDevices,omitempty"`
|
||||
ForgetDevice *commands.ForgetDevice `json:"forgetDevice,omitempty"`
|
||||
UpdateScript *script.UpdateScript `json:"updateScript,omitempty"`
|
||||
ExecuteScript *script.ExecuteScript `json:"executeScript,omitempty"`
|
||||
UpdateScript *script.Update `json:"updateScript,omitempty"`
|
||||
ExecuteScript *script.Execute `json:"executeScript,omitempty"`
|
||||
UpdateTrigger *script.UpdateTrigger `json:"updateTrigger,omitempty"`
|
||||
DeleteTrigger *script.DeleteTrigger `json:"deleteTrigger,omitempty"`
|
||||
}
|
||||
|
||||
type assignInput struct {
|
||||
|
||||
Reference in New Issue
Block a user