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
46 lines
1.4 KiB
package light
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.aiterp.net/lucifer/lucifer/models"
|
|
)
|
|
|
|
var drivers = make(map[string]Driver)
|
|
|
|
// A Driver that communicates with an underlying lighting system.
|
|
type Driver interface {
|
|
// Apply applies all changed lights, which are lights that differ from what Lights returned.
|
|
Apply(ctx context.Context, bridge models.Bridge, lights ...models.Light) error
|
|
|
|
// Lights lists all available lights. The `ID` field will the -1.
|
|
Lights(ctx context.Context, bridge models.Bridge) ([]models.Light, error)
|
|
|
|
// Bridges lists all available bridges.
|
|
Bridges(ctx context.Context) ([]models.Bridge, error)
|
|
|
|
// Connect connects to a bridge, returning the bridge with the API Key.
|
|
Connect(ctx context.Context, bridge models.Bridge) (models.Bridge, error)
|
|
|
|
// DiscoverLights asks the bridge to start a search for new lights.
|
|
DiscoverLights(ctx context.Context, bridge models.Bridge) error
|
|
|
|
// ChangedLights returns a subset of the list describing which lights to update.
|
|
ChangedLights(ctx context.Context, bridge models.Bridge, lights ...models.Light) ([]models.Light, error)
|
|
}
|
|
|
|
// RegisterDriver registers a driver. This must happen in init() functions.
|
|
func RegisterDriver(name string, driver Driver) {
|
|
drivers[name] = driver
|
|
}
|
|
|
|
// Drivers gets the list of drivers.
|
|
func Drivers() []string {
|
|
results := make([]string, len(drivers))
|
|
|
|
for key := range drivers {
|
|
results = append(results, key)
|
|
}
|
|
|
|
return results
|
|
}
|