add lifx driver. It works with the bulb, but the code is a bit smelly.
This commit is contained in:
+37
-8
@@ -47,6 +47,15 @@ func main() {
|
||||
log.Println("New token:", bridge.Token)
|
||||
}
|
||||
|
||||
ch := config.EventChannel
|
||||
go func() {
|
||||
err := driver.Run(context.Background(), bridge, ch)
|
||||
if err != nil {
|
||||
log.Fatalln("Run bridge stopped:", err)
|
||||
}
|
||||
}()
|
||||
time.Sleep(time.Second)
|
||||
|
||||
// List devices
|
||||
var devices []models.Device
|
||||
if *flagSearch {
|
||||
@@ -60,18 +69,14 @@ func main() {
|
||||
log.Fatalln("Failed to list devices:", err)
|
||||
}
|
||||
}
|
||||
|
||||
idMap := make(map[string]int)
|
||||
nextId := len(devices) + 1
|
||||
for i := range devices {
|
||||
devices[i].ID = i + 1
|
||||
idMap[devices[i].InternalID] = i + 1
|
||||
}
|
||||
|
||||
ch := config.EventChannel
|
||||
go func() {
|
||||
err := driver.Run(context.Background(), bridge, ch)
|
||||
if err != nil {
|
||||
log.Fatalln("Run bridge stopped:", err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
@@ -85,6 +90,30 @@ func main() {
|
||||
text, _ := reader.ReadString('\n')
|
||||
text = strings.Trim(text, "\t \r\n")
|
||||
|
||||
if text == "search" {
|
||||
_, _ = driver.SearchDevices(context.Background(), bridge, time.Second)
|
||||
}
|
||||
if text == "list" || text == "search" || text == "json" {
|
||||
devices, err = driver.ListDevices(context.Background(), bridge)
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to list devices:", err)
|
||||
}
|
||||
|
||||
for i, device := range devices {
|
||||
if extId, ok := idMap[device.InternalID]; ok {
|
||||
devices[i].ID = extId
|
||||
} else {
|
||||
idMap[device.InternalID] = nextId
|
||||
devices[i].ID = nextId
|
||||
|
||||
nextId += 1
|
||||
}
|
||||
|
||||
if text != "json" {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Device: %d - %s %+v\n", device.ID, device.InternalID, device.Capabilities)
|
||||
}
|
||||
}
|
||||
}
|
||||
if text == "json" {
|
||||
j, _ := json.MarshalIndent(devices, "", " ")
|
||||
fmt.Println(string(j))
|
||||
|
||||
Reference in New Issue
Block a user