add nanoleaf service
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.aiterp.net/lucifer3/server/internal/formattools"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PairDevice struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (c PairDevice) CommandDescription() string {
|
||||
return fmt.Sprintf("PairDevice(%s)", c.ID)
|
||||
}
|
||||
|
||||
func (c PairDevice) Matches(driver string) (sub string, ok bool) {
|
||||
split := strings.SplitN(c.ID, ":", 2)
|
||||
if split[0] != driver {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return split[1], true
|
||||
}
|
||||
|
||||
type ConnectDevice struct {
|
||||
ID string `json:"id"`
|
||||
APIKey string `json:"apiKey"`
|
||||
}
|
||||
|
||||
func (c ConnectDevice) Matches(driver string) (sub string, ok bool) {
|
||||
split := strings.SplitN(c.ID, ":", 2)
|
||||
if split[0] != driver {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return split[1], true
|
||||
}
|
||||
|
||||
func (c ConnectDevice) CommandDescription() string {
|
||||
return fmt.Sprintf("ConnectDevice(%s, %s)", c.ID, formattools.Asterisks(c.APIKey))
|
||||
}
|
||||
|
||||
type SearchDevices struct {
|
||||
ID string `json:"id"`
|
||||
Hint string `json:"hint"`
|
||||
}
|
||||
|
||||
func (c SearchDevices) Matches(driver string) (string, bool) {
|
||||
split := strings.SplitN(c.ID, ":", 2)
|
||||
if split[0] != driver {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return split[1], true
|
||||
}
|
||||
|
||||
func (c SearchDevices) CommandDescription() string {
|
||||
return fmt.Sprintf("SearchDevices(%s, %#+v)", c.ID, c.Hint)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package commands
|
||||
import (
|
||||
"fmt"
|
||||
"git.aiterp.net/lucifer3/server/device"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SetState struct {
|
||||
@@ -10,6 +11,14 @@ type SetState struct {
|
||||
State device.State
|
||||
}
|
||||
|
||||
func (c SetState) Matches(driver string) (sub string, ok bool) {
|
||||
if strings.HasPrefix(c.ID, driver) && strings.HasPrefix(c.ID[len(driver):], ":") {
|
||||
return strings.SplitN(c.ID[len(driver)+1:], ":", 2)[0], true
|
||||
} else {
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
func (c SetState) CommandDescription() string {
|
||||
return fmt.Sprintf("SetState(%s, %s)", c.ID, c.State)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user