The main server, and probably only repository in this org.
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.

53 lines
1.7 KiB

  1. package light
  2. import (
  3. "context"
  4. "git.aiterp.net/lucifer/lucifer/models"
  5. )
  6. var drivers = make(map[string]Driver)
  7. // A Driver that communicates with an underlying lighting system.
  8. type Driver interface {
  9. // Apply applies all changed lights, which are lights that differ from what Lights returned.
  10. Apply(ctx context.Context, bridge models.Bridge, lights ...models.Light) error
  11. // Lights lists all available lights. The `ID` field will the -1.
  12. Lights(ctx context.Context, bridge models.Bridge) ([]models.Light, error)
  13. // Bridges lists all available bridges.
  14. Bridges(ctx context.Context) ([]models.Bridge, error)
  15. // Connect connects to a bridge, returning the bridge with the API Key.
  16. Connect(ctx context.Context, bridge models.Bridge) (models.Bridge, error)
  17. // DiscoverLights asks the bridge to start a search for new lights.
  18. DiscoverLights(ctx context.Context, bridge models.Bridge) error
  19. // ForgetLight removes the light from the bridge.
  20. ForgetLight(ctx context.Context, bridge models.Bridge, light models.Light) error
  21. // ChangedLights returns a subset of the list describing which lights to update.
  22. ChangedLights(ctx context.Context, bridge models.Bridge, lights ...models.Light) ([]models.Light, error)
  23. Buttons(ctx context.Context, bridge models.Bridge) ([]models.Button, error)
  24. PollButton(ctx context.Context, bridge models.Bridge, button models.Button) (<-chan models.ButtonEvent, error)
  25. }
  26. // RegisterDriver registers a driver. This must happen in init() functions.
  27. func RegisterDriver(name string, driver Driver) {
  28. drivers[name] = driver
  29. }
  30. // Drivers gets the list of drivers.
  31. func Drivers() []string {
  32. results := make([]string, len(drivers))
  33. for key := range drivers {
  34. results = append(results, key)
  35. }
  36. return results
  37. }