|
|
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
// ForgetLight removes the light from the bridge.
ForgetLight(ctx context.Context, bridge models.Bridge, light models.Light) 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)
Buttons(ctx context.Context, bridge models.Bridge) ([]models.Button, error)
PollButton(ctx context.Context, bridge models.Bridge, button models.Button) (<-chan models.ButtonEvent, 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 }
|