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.

77 lines
2.4 KiB

  1. package main
  2. import (
  3. lucifer3 "git.aiterp.net/lucifer3/server"
  4. "git.aiterp.net/lucifer3/server/device"
  5. "git.aiterp.net/lucifer3/server/events"
  6. "git.aiterp.net/lucifer3/server/internal/color"
  7. "git.aiterp.net/lucifer3/server/internal/gentools"
  8. "log"
  9. "time"
  10. )
  11. func main() {
  12. bus := lucifer3.EventBus{}
  13. bus.JoinCallback(func(event lucifer3.Event, sender lucifer3.ServiceID) bool {
  14. switch event := event.(type) {
  15. case events.HubConnected:
  16. log.Println("Callback got connect event")
  17. case events.DeviceAssignment:
  18. log.Println("Callback can see", len(event.IDs), "devices are being assigned")
  19. case events.DeviceRegister:
  20. log.Println("Callback should not see that", event.InternalID, "has got a new ID")
  21. case events.DeviceDesiredStateChange:
  22. log.Println("Callback saw", event.ID, "got a new state.")
  23. }
  24. return true
  25. })
  26. c := color.RGB{Red: 1, Green: 0.7, Blue: 0.25}.ToXY()
  27. bus.Send(events.HubConnected{}, lucifer3.ServiceID{Kind: lucifer3.SKDeviceHub, ID: 1}, nil)
  28. bus.Send(events.DeviceAssignment{
  29. IDs: []int64{1, 2, 3, 4, 5, 6, 7, 8, 9},
  30. Version: 1,
  31. State: &device.State{
  32. Power: gentools.Ptr(true),
  33. Temperature: nil,
  34. Intensity: nil,
  35. Color: &color.Color{XY: &c},
  36. },
  37. }, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, nil)
  38. bus.Send(events.DeviceAssignment{
  39. IDs: []int64{44, 45, 46, 47, 48, 49, 50, 51, 52, 53},
  40. Version: 2,
  41. Effect: gentools.Ptr[int64](1044),
  42. }, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, nil)
  43. time.Sleep(time.Second / 2)
  44. bus.Send(events.DeviceHardwareStateChange{
  45. InternalID: "c68b310c-7fd6-47a4-ae11-d60d701769da",
  46. DeviceFlags: device.SFlagPower | device.SFlagIntensity,
  47. ColorFlags: 0,
  48. State: device.State{
  49. Power: gentools.Ptr(true),
  50. Intensity: gentools.Ptr(0.75),
  51. },
  52. }, lucifer3.ServiceID{Kind: lucifer3.SKDeviceHub, ID: 1}, nil)
  53. time.Sleep(time.Second / 4)
  54. bus.Send(events.DeviceRegister{
  55. InternalID: "c68b310c-7fd6-47a4-ae11-d60d701769da",
  56. ID: 10,
  57. }, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, &lucifer3.ServiceID{Kind: lucifer3.SKDeviceHub, ID: 1})
  58. bus.Send(events.DeviceDesiredStateChange{
  59. ID: 10,
  60. NewState: device.State{
  61. Power: gentools.Ptr(true),
  62. Intensity: gentools.Ptr(0.75),
  63. },
  64. }, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, nil)
  65. time.Sleep(time.Second * 4)
  66. }