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.

67 lines
2.0 KiB

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