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

  1. package services
  2. import (
  3. lucifer3 "git.aiterp.net/lucifer3/server"
  4. "git.aiterp.net/lucifer3/server/commands"
  5. "git.aiterp.net/lucifer3/server/device"
  6. "git.aiterp.net/lucifer3/server/effects"
  7. "git.aiterp.net/lucifer3/server/events"
  8. "git.aiterp.net/lucifer3/server/internal/color"
  9. "git.aiterp.net/lucifer3/server/internal/gentools"
  10. "git.aiterp.net/lucifer3/server/internal/testutils"
  11. "strconv"
  12. "testing"
  13. "time"
  14. )
  15. func TestEffectEnforcer(t *testing.T) {
  16. bus := lucifer3.EventBus{}
  17. resolver := NewResolver()
  18. sceneMap := NewSceneMap(resolver)
  19. logger := &testutils.TestEventLogger{}
  20. bus.JoinPrivileged(resolver)
  21. bus.JoinPrivileged(sceneMap)
  22. bus.Join(NewEffectEnforcer(resolver, sceneMap))
  23. bus.Join(logger)
  24. for i := 1; i <= 9; i += 1 {
  25. bus.RunEvents([]lucifer3.Event{
  26. events.HardwareState{
  27. ID: "test:" + strconv.Itoa(i),
  28. InternalName: "Test Device " + strconv.Itoa(i),
  29. SupportFlags: device.SFlagColor | device.SFlagIntensity | device.SFlagPower,
  30. ColorFlags: device.CFlagXY | device.CFlagHS | device.CFlagRGB | device.CFlagKelvin,
  31. ColorGamut: nil,
  32. ColorKelvinRange: nil,
  33. Buttons: nil,
  34. State: device.State{
  35. Power: gentools.Ptr(false),
  36. Intensity: gentools.Ptr(1.0),
  37. Color: &color.Color{K: gentools.Ptr(2900)},
  38. },
  39. BatteryPercentage: nil,
  40. Unreachable: false,
  41. },
  42. events.DeviceReady{ID: "test:" + strconv.Itoa(i)},
  43. })
  44. }
  45. bus.RunCommand(commands.Assign{
  46. Match: "test:*",
  47. Effect: effects.Pattern{
  48. States: []device.State{
  49. {Color: &color.Color{XY: &color.XY{X: 0.22, Y: 0.18}}},
  50. {Color: &color.Color{XY: &color.XY{X: 0.27, Y: 0.23}}},
  51. },
  52. },
  53. })
  54. time.Sleep(time.Millisecond * 100)
  55. logger.Sync(&bus)
  56. logger.AssertEvent(t, "DeviceReady(id:test:1)")
  57. logger.AssertEvent(t, "DeviceReady(id:test:9)")
  58. logger.AssertCommand(t, "Assign(test:*, Pattern(states:[(xy:0.2200,0.1800), (xy:0.2700,0.2300)], anim:0ms))")
  59. logger.AssertCommand(t, "SetStateBatch(9 devices)")
  60. }