some more stuffs.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"git.aiterp.net/lucifer3/server/internal/gentools"
|
||||
"git.aiterp.net/lucifer3/server/services/script"
|
||||
"github.com/google/uuid"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
@@ -22,7 +23,6 @@ func (d *Data) WithPatch(patches ...Patch) Data {
|
||||
if patch.Device != nil {
|
||||
pd := d.ensureDevice(patch.Device.ID)
|
||||
|
||||
gentools.ApplyUpdateSlice(&pd.Aliases, patch.Device.SetAliases)
|
||||
gentools.ApplyUpdate(&pd.Name, patch.Device.Name)
|
||||
gentools.ApplyUpdatePtr(&pd.HWState, patch.Device.HWState)
|
||||
gentools.ApplyUpdatePtr(&pd.HWMetadata, patch.Device.HWMetadata)
|
||||
@@ -32,18 +32,31 @@ func (d *Data) WithPatch(patches ...Patch) Data {
|
||||
gentools.ApplyUpdatePtr(&pd.DesiredColorRGB, patch.Device.DesiredColorRGB)
|
||||
|
||||
if patch.Device.AddAlias != nil {
|
||||
pd.Aliases = append(pd.Aliases[:0:0], pd.Aliases...)
|
||||
pd.Aliases = append(pd.Aliases, *patch.Device.AddAlias)
|
||||
ptr := device.Pointer{ID: "dummy", Aliases: pd.Aliases}
|
||||
ptr.AddAlias(*patch.Device.AddAlias)
|
||||
|
||||
if strings.HasPrefix(*patch.Device.AddAlias, "lucifer:name:") {
|
||||
pd.Name = (*patch.Device.AddAlias)[len("lucifer:name:"):]
|
||||
}
|
||||
if strings.HasPrefix(*patch.Device.AddAlias, "lucifer:icon:") {
|
||||
pd.Icon = (*patch.Device.AddAlias)[len("lucifer:icon:"):]
|
||||
}
|
||||
|
||||
pd.Aliases = ptr.Aliases
|
||||
}
|
||||
if patch.Device.RemoveAlias != nil {
|
||||
for i, alias := range pd.Aliases {
|
||||
if alias == *patch.Device.RemoveAlias {
|
||||
pd.Aliases = append(pd.Aliases[:0:0], pd.Aliases...)
|
||||
pd.Aliases = append(pd.Aliases[:i], pd.Aliases[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if patch.Device.HWMetadata != nil {
|
||||
if pd.Icon == "" {
|
||||
pd.Icon = patch.Device.HWMetadata.Icon
|
||||
}
|
||||
}
|
||||
if patch.Device.ClearAssignment {
|
||||
pd.Assignment = nil
|
||||
}
|
||||
@@ -136,6 +149,7 @@ type Device struct {
|
||||
Aliases []string `json:"aliases"`
|
||||
Assignment *uuid.UUID `json:"assignment"`
|
||||
Sensors DeviceSensors `json:"sensors"`
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
|
||||
type DeviceSensors struct {
|
||||
|
||||
@@ -32,9 +32,9 @@ func (e Patch) EventDescription() string {
|
||||
case e.Device.HWMetadata != nil:
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, hwMetadata)", e.Device.ID)
|
||||
case e.Device.AddAlias != nil:
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, addAlias=%s)", e.Device.ID, *e.Device.AddAlias)
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, addAlias)", e.Device.ID)
|
||||
case e.Device.RemoveAlias != nil:
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, removeAlias=%s)", e.Device.ID, *e.Device.RemoveAlias)
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, removeAlias)", e.Device.ID)
|
||||
case e.Device.ActiveColorRGB != nil:
|
||||
col := color.Color{RGB: e.Device.ActiveColorRGB}
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, activeColorRgb=%s)", e.Device.ID, col.String())
|
||||
@@ -59,7 +59,6 @@ type DevicePatch struct {
|
||||
HWMetadata *events.HardwareMetadata `json:"hwMetadata,omitempty"`
|
||||
HWState *events.HardwareState `json:"hwState,omitempty"`
|
||||
DesiredState *device.State `json:"desiredState,omitempty"`
|
||||
SetAliases []string `json:"setAliases,omitempty"`
|
||||
AddAlias *string `json:"addAlias,omitempty"`
|
||||
RemoveAlias *string `json:"removeAlias,omitempty"`
|
||||
Assignment *uuid.UUID `json:"assignment,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user