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.

46 lines
1.4 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. // ChangedLights returns a subset of the list describing which lights to update.
  20. ChangedLights(ctx context.Context, bridge models.Bridge, lights ...models.Light) ([]models.Light, error)
  21. }
  22. // RegisterDriver registers a driver. This must happen in init() functions.
  23. func RegisterDriver(name string, driver Driver) {
  24. drivers[name] = driver
  25. }
  26. // Drivers gets the list of drivers.
  27. func Drivers() []string {
  28. results := make([]string, len(drivers))
  29. for key := range drivers {
  30. results = append(results, key)
  31. }
  32. return results
  33. }