scripting system, hue fixes and such

This commit is contained in:
2023-08-29 00:06:57 +02:00
parent da8fd03e8a
commit 8776ed6df3
48 changed files with 1128 additions and 72 deletions
+7
View File
@@ -6,12 +6,14 @@ import (
"git.aiterp.net/lucifer3/server/events"
"git.aiterp.net/lucifer3/server/internal/color"
"git.aiterp.net/lucifer3/server/internal/gentools"
"git.aiterp.net/lucifer3/server/services/script"
"github.com/google/uuid"
)
type Data struct {
Devices map[string]Device `json:"devices"`
Assignments map[uuid.UUID]Assignment `json:"assignments"`
Scripts map[string][]script.Line `json:"scripts"`
}
func (d *Data) WithPatch(patches ...Patch) Data {
@@ -89,6 +91,10 @@ func (d *Data) WithPatch(patches ...Patch) Data {
newData.Assignments[pa.ID] = pa
}
}
if patch.Script != nil {
newData.Scripts[patch.Script.Name] = patch.Script.Lines
}
}
return newData
@@ -98,6 +104,7 @@ func (d *Data) Copy() Data {
return Data{
Devices: gentools.CopyMap(d.Devices),
Assignments: gentools.CopyMap(d.Assignments),
Scripts: gentools.CopyMap(d.Scripts),
}
}
+9
View File
@@ -6,12 +6,14 @@ import (
"git.aiterp.net/lucifer3/server/effects"
"git.aiterp.net/lucifer3/server/events"
"git.aiterp.net/lucifer3/server/internal/color"
"git.aiterp.net/lucifer3/server/services/script"
"github.com/google/uuid"
)
type Patch struct {
Assignment *AssignmentPatch `json:"assignment,omitempty"`
Device *DevicePatch `json:"device,omitempty"`
Script *ScriptPatch `json:"script,omitempty"`
}
func (e Patch) VerboseKey() string {
@@ -41,6 +43,8 @@ func (e Patch) EventDescription() string {
}
} else if e.Assignment != nil {
return fmt.Sprintf("uistate.Patch(assignment=%s)", e.Assignment.ID)
} else if e.Script != nil {
return fmt.Sprintf("uistate.Patch(script=%s)", e.Script.Name)
} else {
return "uistate.Patch"
}
@@ -71,3 +75,8 @@ type AssignmentPatch struct {
Variables map[string]float64 `json:"variables,omitempty"`
Delete bool `json:"delete,omitempty"`
}
type ScriptPatch struct {
Name string
Lines []script.Line
}
+13 -1
View File
@@ -6,11 +6,19 @@ import (
"git.aiterp.net/lucifer3/server/effects"
"git.aiterp.net/lucifer3/server/events"
"git.aiterp.net/lucifer3/server/internal/gentools"
"git.aiterp.net/lucifer3/server/services/script"
"github.com/google/uuid"
"sync"
)
func NewService() lucifer3.ActiveService {
return &service{}
return &service{
data: Data{
Devices: map[string]Device{},
Assignments: map[uuid.UUID]Assignment{},
Scripts: map[string][]script.Line{},
},
}
}
type service struct {
@@ -35,6 +43,10 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command
Device: &DevicePatch{ID: id, DesiredState: gentools.ShallowCopy(&state)},
})
}
case script.UpdateScript:
patches = append(patches, Patch{
Script: &ScriptPatch{Name: command.Name, Lines: command.Lines},
})
}
if len(patches) > 0 {