You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.0 KiB
66 lines
2.0 KiB
package services
|
|
|
|
import (
|
|
lucifer3 "git.aiterp.net/lucifer3/server"
|
|
"git.aiterp.net/lucifer3/server/commands"
|
|
"git.aiterp.net/lucifer3/server/device"
|
|
"git.aiterp.net/lucifer3/server/effects"
|
|
"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/internal/testutils"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestEffectEnforcer(t *testing.T) {
|
|
bus := lucifer3.EventBus{}
|
|
resolver := NewResolver()
|
|
sceneMap := NewSceneMap(resolver)
|
|
logger := &testutils.TestEventLogger{}
|
|
|
|
bus.JoinPrivileged(resolver)
|
|
bus.JoinPrivileged(sceneMap)
|
|
bus.Join(NewEffectEnforcer(resolver, sceneMap))
|
|
bus.Join(logger)
|
|
|
|
for i := 1; i <= 9; i += 1 {
|
|
bus.RunEvents([]lucifer3.Event{
|
|
events.HardwareState{
|
|
ID: "test:" + strconv.Itoa(i),
|
|
InternalName: "Test Device " + strconv.Itoa(i),
|
|
SupportFlags: device.SFlagColor | device.SFlagIntensity | device.SFlagPower,
|
|
ColorFlags: device.CFlagXY | device.CFlagHS | device.CFlagRGB | device.CFlagKelvin,
|
|
ColorGamut: nil,
|
|
ColorKelvinRange: nil,
|
|
Buttons: nil,
|
|
State: device.State{
|
|
Power: gentools.Ptr(false),
|
|
Intensity: gentools.Ptr(1.0),
|
|
Color: &color.Color{K: gentools.Ptr(2900)},
|
|
},
|
|
BatteryPercentage: nil,
|
|
Unreachable: false,
|
|
},
|
|
events.DeviceReady{ID: "test:" + strconv.Itoa(i)},
|
|
})
|
|
}
|
|
|
|
bus.RunCommand(commands.Assign{
|
|
Match: "test:*",
|
|
Effect: effects.Pattern{
|
|
States: []device.State{
|
|
{Color: &color.Color{XY: &color.XY{X: 0.22, Y: 0.18}}},
|
|
{Color: &color.Color{XY: &color.XY{X: 0.27, Y: 0.23}}},
|
|
},
|
|
},
|
|
})
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
logger.Sync(&bus)
|
|
logger.AssertEvent(t, "DeviceReady(id:test:1)")
|
|
logger.AssertEvent(t, "DeviceReady(id:test:9)")
|
|
logger.AssertCommand(t, "Assign(test:*, Pattern(states:[(xy:0.2200,0.1800), (xy:0.2700,0.2300)], anim:0ms))")
|
|
logger.AssertCommand(t, "SetStateBatch(9 devices)")
|
|
}
|