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.

98 lines
2.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package main
  2. import (
  3. "fmt"
  4. lucifer3 "git.aiterp.net/lucifer3/server"
  5. "git.aiterp.net/lucifer3/server/commands"
  6. "git.aiterp.net/lucifer3/server/device"
  7. "git.aiterp.net/lucifer3/server/effects"
  8. "git.aiterp.net/lucifer3/server/events"
  9. "git.aiterp.net/lucifer3/server/internal/color"
  10. "git.aiterp.net/lucifer3/server/internal/gentools"
  11. "git.aiterp.net/lucifer3/server/services"
  12. "log"
  13. "time"
  14. )
  15. func main() {
  16. bus := lucifer3.EventBus{}
  17. resolver := services.NewResolver()
  18. sceneMap := services.NewSceneMap(resolver)
  19. bus.JoinPrivileged(resolver)
  20. bus.JoinPrivileged(sceneMap)
  21. bus.Join(services.NewEffectEnforcer(resolver, sceneMap))
  22. bus.RunEvent(events.Connected{Prefix: "nanoleaf:10.80.1.11"})
  23. numbers := []int{5, 2, 3, 1, 4}
  24. for i, id := range []string{"e28c", "67db", "f744", "d057", "73c1"} {
  25. bus.RunEvent(events.HardwareState{
  26. ID: "nanoleaf:10.80.1.11:" + id,
  27. InternalName: fmt.Sprintf("Hexagon %d", numbers[i]),
  28. SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity,
  29. ColorFlags: device.CFlagRGB,
  30. State: device.State{},
  31. })
  32. }
  33. bus.RunCommand(commands.ReplaceScene{
  34. Match: "lucifer:name:Hex*",
  35. SceneName: "Evening",
  36. })
  37. bus.RunCommand(commands.AddAlias{
  38. Match: "nanoleaf:10.80.1.{11,7,16,5}:*",
  39. Alias: "lucifer:tag:Magic Lamps",
  40. })
  41. for i, id := range []string{"40e5", "dead", "beef", "cafe", "1337"} {
  42. bus.RunEvent(events.HardwareState{
  43. ID: "nanoleaf:10.80.1.11:" + id,
  44. InternalName: fmt.Sprintf("Hexagon %d", 6+i),
  45. SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity,
  46. ColorFlags: device.CFlagRGB,
  47. State: device.State{},
  48. })
  49. }
  50. bus.RunEvent(events.ExternalEvent{
  51. Kind: "weather",
  52. Values: map[string]string{
  53. "location": "Brekstad",
  54. "temperature_celsius": "21.00",
  55. "precipitation_mm": "3.21",
  56. },
  57. })
  58. c1 := gentools.Ptr(color.MustParse("rgb:#ff0000"))
  59. c2 := gentools.Ptr(color.MustParse("rgb:#00ff00"))
  60. bus.RunCommand(commands.Assign{
  61. Match: "**:Hexagon *",
  62. Effect: effects.Gradient{
  63. States: []device.State{
  64. {
  65. Power: gentools.Ptr(true),
  66. Color: c1,
  67. Intensity: gentools.Ptr(1.0),
  68. },
  69. {
  70. Power: gentools.Ptr(true),
  71. Color: c2,
  72. Intensity: gentools.Ptr(0.7),
  73. },
  74. },
  75. AnimationMS: 1000,
  76. Interpolate: true,
  77. },
  78. })
  79. log.Println("Search \"**:Hexagon {1,5,6}\"")
  80. for _, dev := range resolver.Resolve("lucifer:name:Hexagon {1,5,6}") {
  81. log.Println("- ID:", dev.ID)
  82. log.Println(" Aliases:", dev.Aliases)
  83. }
  84. time.Sleep(time.Second * 15)
  85. }