Browse Source

driver in bridgetest

pull/1/head
Stian Fredrik Aune 4 years ago
parent
commit
e4078de845
  1. 15
      app/config/driver.go
  2. 11
      cmd/bridgetest/main.go
  3. 16
      internal/drivers/provider.go
  4. 2
      models/bridge.go
  5. 1
      models/errors.go
  6. 2
      webui/src/res/colors.sass

15
app/config/driver.go

@ -1,12 +1,23 @@
package config
import "git.aiterp.net/lucifer/new-server/models"
import (
"git.aiterp.net/lucifer/new-server/internal/drivers"
"git.aiterp.net/lucifer/new-server/internal/drivers/nanoleaf"
"git.aiterp.net/lucifer/new-server/models"
"sync"
)
var dp models.DriverProvider
var dpMutex sync.Mutex
func DriverProvider() models.DriverProvider {
dpMutex.Lock()
defer dpMutex.Unlock()
if dp == nil {
panic("not implemented yet")
dp = &drivers.MapBasedDriverProvider{Data: map[models.DriverKind]models.Driver{
models.DTNanoLeaf: &nanoleaf.Driver{},
}}
}
return dp

11
cmd/bridgetest/main.go

@ -5,7 +5,7 @@ import (
"context"
"flag"
"fmt"
"git.aiterp.net/lucifer/new-server/internal/drivers/nanoleaf"
"git.aiterp.net/lucifer/new-server/app/config"
"git.aiterp.net/lucifer/new-server/models"
"log"
"os"
@ -15,7 +15,7 @@ import (
"time"
)
var flagDriver = flag.String("driver", "Nanoleaf", "The bridge driver to use")
var flagDriver = flag.String("driver", string(models.DTNanoLeaf), "The bridge driver to use")
var flagAddress = flag.String("address", "127.0.0.1", "The bridge's address")
var flagToken = flag.String("token", "", "The bridge's access token / api key / login")
var flagPair = flag.Bool("pair", false, "Try to pair with the bridge.")
@ -25,8 +25,11 @@ var flagSearchTimeout = flag.Duration("search-timeout", time.Second*3, "Timeout
func main() {
flag.Parse()
// TODO: Select driver
driver := nanoleaf.Driver{}
// Find drivers
driver, err := config.DriverProvider().Provide(models.DriverKind(*flagDriver))
if err != nil {
log.Fatalln("Failed to find driver:", err)
}
// Find bridge
bridges, err := driver.SearchBridge(context.Background(), *flagAddress, !*flagPair)

16
internal/drivers/provider.go

@ -0,0 +1,16 @@
package drivers
import "git.aiterp.net/lucifer/new-server/models"
type MapBasedDriverProvider struct {
Data map[models.DriverKind]models.Driver
}
func (m *MapBasedDriverProvider) Provide(kind models.DriverKind) (models.Driver, error) {
if m.Data[kind] == nil {
return nil, models.ErrUnknownDriver
}
return m.Data[kind], nil
}

2
models/bridge.go

@ -21,7 +21,7 @@ type DriverKind string
var (
DTHue DriverKind = "Hue"
DTNanoLeaf DriverKind = "NanoLeaf"
DTNanoLeaf DriverKind = "Nanoleaf"
)
var ValidDriverKinds = []DriverKind{

1
models/errors.go

@ -8,6 +8,7 @@ var ErrBadInput = errors.New("bad input")
var ErrBadColor = errors.New("bad color")
var ErrInternal = errors.New("internal")
var ErrUnknownColorFormat = errors.New("unknown color format")
var ErrUnknownDriver = errors.New("unknown driver")
var ErrMissingToken = errors.New("driver is missing authentication information")
var ErrIncorrectToken = errors.New("driver is not accepting authentication information")

2
webui/src/res/colors.sass

@ -1,5 +1,5 @@
$color-background: #111
$color-foreground: rgb(238, 238, 238)
$color-foreground: rgb(204, 204, 204)
$color-foreground-dark: rgba(238, 238, 238, 0.05)
body, html

Loading…
Cancel
Save