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.

49 lines
1.1 KiB

  1. package main
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "git.aiterp.net/lucifer/new-server/internal/drivers/hue2"
  7. "git.aiterp.net/lucifer/new-server/models"
  8. "log"
  9. )
  10. func main() {
  11. client := hue2.NewClient("10.80.8.8", "o2XKGgmVUGNBghYFdLUCVuinOTMxFH4pHV9PuTbU")
  12. bridge := hue2.NewBridge(client)
  13. err := bridge.RefreshAll(context.Background())
  14. if err != nil {
  15. log.Fatalln(err)
  16. }
  17. j, _ := json.Marshal(bridge.GenerateDevices())
  18. fmt.Println(string(j))
  19. ch := make(chan models.Event)
  20. go func() {
  21. for event := range ch {
  22. log.Println("EVENT", event.Name, event.Payload)
  23. }
  24. }()
  25. for i, dev := range bridge.GenerateDevices() {
  26. device := dev
  27. switch device.InternalID {
  28. case "6d5a45b0-ec69-4417-8588-717358b05086":
  29. c, _ := models.ParseColorValue("xy:0.22,0.18")
  30. device.State.Color = c
  31. device.State.Intensity = 0.3
  32. case "a71128f4-5295-4ae4-9fbc-5541abc8739b":
  33. c, _ := models.ParseColorValue("k:6500")
  34. device.State.Color = c
  35. device.State.Intensity = 0.2
  36. }
  37. device.ID = i + 1
  38. bridge.Update(device)
  39. }
  40. err = bridge.Run(context.Background(), ch)
  41. log.Println(err)
  42. }