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.

112 lines
2.7 KiB

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