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.

121 lines
3.1 KiB

2 years ago
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. "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. bus.RunEvent(events.HardwareState{
  46. ID: "nanoleaf:10.80.1.11:40e5",
  47. InternalName: "Hexagon 6",
  48. SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity,
  49. ColorFlags: device.CFlagRGB,
  50. State: device.State{},
  51. })
  52. bus.RunEvent(events.HardwareState{
  53. ID: "nanoleaf:10.80.1.11:dead",
  54. InternalName: "Hexagon 7",
  55. SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity,
  56. ColorFlags: device.CFlagRGB,
  57. State: device.State{},
  58. })
  59. bus.RunEvent(events.HardwareState{
  60. ID: "nanoleaf:10.80.1.11:beef",
  61. InternalName: "Hexagon 8",
  62. SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity,
  63. ColorFlags: device.CFlagRGB,
  64. State: device.State{},
  65. })
  66. time.Sleep(time.Millisecond)
  67. bus.RunEvent(events.ExternalEvent{
  68. Kind: "weather",
  69. Values: map[string]string{
  70. "location": "Brekstad",
  71. "temperature_celsius": "21.00",
  72. "precipitation_mm": "3.21",
  73. },
  74. })
  75. time.Sleep(time.Millisecond)
  76. bus.RunCommand(commands.Assign{
  77. Match: "**:Hexagon *",
  78. Effect: effects.Pattern{
  79. States: []device.State{
  80. {
  81. Power: gentools.Ptr(true),
  82. Color: gentools.Ptr(color.MustParse("rgb:#ff0000")),
  83. Intensity: gentools.Ptr(1.0),
  84. },
  85. {
  86. Power: gentools.Ptr(true),
  87. Color: gentools.Ptr(color.MustParse("rgb:#00ff00")),
  88. Intensity: gentools.Ptr(0.7),
  89. },
  90. },
  91. ShiftMS: 1000,
  92. },
  93. })
  94. time.Sleep(time.Millisecond * 100)
  95. log.Println("Search \"**:Hexagon {1,5,6}\"")
  96. for _, dev := range resolver.Resolve("lucifer:name:Hexagon {1,5,6}") {
  97. log.Println("- ID:", dev.ID)
  98. log.Println(" Aliases:", dev.Aliases)
  99. }
  100. time.Sleep(time.Second * 15)
  101. }