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.

80 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package main
  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/services"
  10. "git.aiterp.net/lucifer3/server/services/nanoleaf"
  11. "time"
  12. )
  13. func main() {
  14. bus := lucifer3.EventBus{}
  15. resolver := services.NewResolver()
  16. sceneMap := services.NewSceneMap(resolver)
  17. bus.JoinPrivileged(resolver)
  18. bus.JoinPrivileged(sceneMap)
  19. bus.Join(services.NewEffectEnforcer(resolver, sceneMap))
  20. bus.Join(nanoleaf.NewService())
  21. bus.JoinCallback(func(event lucifer3.Event) bool {
  22. switch event.(type) {
  23. case events.DevicesReady:
  24. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:2d0c", Alias: "lucifer:name:Hex 5"})
  25. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:542f", Alias: "lucifer:name:Hex 6"})
  26. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:e760", Alias: "lucifer:name:Hex 7"})
  27. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:207a", Alias: "lucifer:name:Hex 8"})
  28. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:df9a", Alias: "lucifer:name:Hex 9"})
  29. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:cdd5", Alias: "lucifer:name:Hex 4"})
  30. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:4597", Alias: "lucifer:name:Hex 3"})
  31. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:82cb", Alias: "lucifer:name:Hex 2"})
  32. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:09fd", Alias: "lucifer:name:Hex 1"})
  33. bus.RunCommand(commands.Assign{
  34. Match: "nanoleaf:10.80.1.14:*",
  35. Effect: effects.Pattern{
  36. States: []device.State{
  37. {Power: p(true), Intensity: p(0.3), Color: p(color.MustParse("xy:0.22,0.18"))},
  38. {Power: p(true), Intensity: p(0.4), Color: p(color.MustParse("xy:0.22,0.18"))},
  39. {Power: p(true), Intensity: p(0.5), Color: p(color.MustParse("xy:0.22,0.18"))},
  40. },
  41. AnimationMS: 200,
  42. },
  43. })
  44. time.Sleep(time.Second * 3)
  45. bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:*", Alias: "lucifer:tag:Magic Lamps"})
  46. bus.RunCommand(commands.Assign{
  47. Match: "lucifer:tag:Magic Lamps",
  48. Effect: effects.Gradient{
  49. States: []device.State{
  50. {Power: p(true), Intensity: p(0.5), Color: p(color.MustParse("xy:0.22,0.18"))},
  51. {Power: p(true), Intensity: p(0.8), Color: p(color.MustParse("xy:0.22,0.18"))},
  52. },
  53. Interpolate: true,
  54. AnimationMS: 500,
  55. },
  56. })
  57. return false
  58. }
  59. return true
  60. })
  61. bus.RunCommand(commands.ConnectDevice{
  62. ID: "nanoleaf:10.80.1.14",
  63. APIKey: "QRj5xcQxAQMQsjK4gvaprdhOwr1sCIcj",
  64. })
  65. time.Sleep(time.Hour)
  66. }
  67. func p[T any](v T) *T {
  68. return &v
  69. }