49 lines
981 B
Go
49 lines
981 B
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"git.aiterp.net/lucifer3/server/device"
|
|
"strings"
|
|
)
|
|
|
|
type SetState struct {
|
|
ID string
|
|
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)
|
|
}
|
|
|
|
func (c SetState) VerboseKey() string {
|
|
return "SetState"
|
|
}
|
|
|
|
type SetStateBatch map[string]device.State
|
|
|
|
func (c SetStateBatch) CommandDescription() string {
|
|
b := strings.Builder{}
|
|
b.WriteByte('\n')
|
|
for key, value := range c {
|
|
b.WriteString(" ")
|
|
b.WriteString(key)
|
|
b.WriteString(": ")
|
|
b.WriteString(value.String())
|
|
b.WriteRune('\n')
|
|
}
|
|
|
|
return fmt.Sprintf("SetStateBatch(%s)", b.String())
|
|
}
|
|
|
|
func (c SetStateBatch) VerboseKey() string {
|
|
return "SetStateBatch"
|
|
}
|