This commit is contained in:
+3
-22
@@ -8,30 +8,12 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func fetchDevices(ctx context.Context, fetchStr string) ([]models.Device, error) {
|
||||
if strings.HasPrefix(fetchStr, "tag:") {
|
||||
return config.DeviceRepository().FetchByReference(ctx, models.RKTag, fetchStr[4:])
|
||||
} else if strings.HasPrefix(fetchStr, "bridge:") {
|
||||
return config.DeviceRepository().FetchByReference(ctx, models.RKBridgeID, fetchStr[7:])
|
||||
} else if strings.HasPrefix(fetchStr, "id:") {
|
||||
return config.DeviceRepository().FetchByReference(ctx, models.RKDeviceID, fetchStr[7:])
|
||||
} else if strings.HasPrefix(fetchStr, "name:") {
|
||||
return config.DeviceRepository().FetchByReference(ctx, models.RKName, fetchStr[7:])
|
||||
}else if fetchStr == "all" {
|
||||
return config.DeviceRepository().FetchByReference(ctx, models.RKAll, "")
|
||||
} else {
|
||||
_, err := strconv.Atoi(fetchStr)
|
||||
if err != nil {
|
||||
return config.DeviceRepository().FetchByReference(ctx, models.RKName, fetchStr)
|
||||
}
|
||||
|
||||
return config.DeviceRepository().FetchByReference(ctx, models.RKDeviceID, fetchStr)
|
||||
}
|
||||
kind, value := models.ParseFetchString(fetchStr)
|
||||
return config.DeviceRepository().FetchByReference(ctx, kind, value)
|
||||
}
|
||||
|
||||
func Devices(r gin.IRoutes) {
|
||||
@@ -81,7 +63,6 @@ func Devices(r gin.IRoutes) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
config.PublishChannel <- scene.GlobalManager().FilterUnassigned(changed)
|
||||
|
||||
go func() {
|
||||
@@ -268,4 +249,4 @@ func Devices(r gin.IRoutes) {
|
||||
|
||||
return devices, nil
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user