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.

95 lines
2.3 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. time.Sleep(time.Millisecond)
  53. bus.RunEvent(events.ExternalEvent{
  54. Kind: "weather",
  55. Values: map[string]string{
  56. "location": "Brekstad",
  57. "temperature_celsius": "21.00",
  58. "precipitation_mm": "3.21",
  59. },
  60. })
  61. time.Sleep(time.Millisecond)
  62. bus.RunCommand(commands.Assign{
  63. Match: "**:Hexagon *",
  64. Effect: effects.Manual{
  65. Power: gentools.Ptr(true),
  66. Color: gentools.Ptr(color.MustParse("rgb:#ffcc11")),
  67. Intensity: gentools.Ptr(1.0),
  68. },
  69. })
  70. time.Sleep(time.Millisecond * 100)
  71. log.Println("Search \"**:Hexagon {1,5,6}\"")
  72. for _, dev := range resolver.Resolve("lucifer:name:Hexagon {1,5,6}") {
  73. log.Println("- ID:", dev.ID)
  74. log.Println(" Aliases:", dev.Aliases)
  75. }
  76. }